X-Git-Url: http://git.vpit.fr/?a=blobdiff_plain;f=lib%2FSub%2FPrototype%2FUtil.pm;h=b2f67a7f81aa703868e3d5217232265446aeaa87;hb=909c371df9ff98e4f100b9451219275970a93dbd;hp=a981d27498ac393d4d383c8c39d2af27e8190c49;hpb=e0d0c3b61349870e1009e833116c10a794e3b6b8;p=perl%2Fmodules%2FSub-Prototype-Util.git diff --git a/lib/Sub/Prototype/Util.pm b/lib/Sub/Prototype/Util.pm index a981d27..b2f67a7 100644 --- a/lib/Sub/Prototype/Util.pm +++ b/lib/Sub/Prototype/Util.pm @@ -29,10 +29,17 @@ $VERSION = '0.10'; my @a = qw; my @args = ( \@a, 1, { d => 2 }, undef, 3 ); - my @flat = flatten '\@$;$', @args; # ('a', 'b', 'c', 1, { d => 2 }) - recall 'CORE::push', @args; # @a contains 'a', 'b', 'c', 1, { d => 2 }, undef, 3 + my @flat = flatten '\@$;$', @args; + # @flat contains now ('a', 'b', 'c', 1, { d => 2 }) + + my $res = recall 'CORE::push', @args; + # @a contains now 'a', 'b', 'c', 1, { d => 2 }, undef, 3 + # and $res is 7 + my $splice = wrap 'CORE::splice'; - my @b = $splice->(\@a, 4, 2); # @a is now ('a', 'b', 'c', 1, 3) and @b is ({ d => 2 }, undef) + my @b = $splice->(\@a, 4, 2); + # @a contains now ('a', 'b', 'c', 1, 3) + # and @b is ({ d => 2 }, undef) =head1 DESCRIPTION @@ -142,24 +149,32 @@ Valid keys are : =over 4 -=item C<< ref => $func >> +=item * + +C<< ref => $func >> Specifies the function used in the generated code to test the reference type of scalars. Defaults to C<'ref'>. You may also want to use L. -=item C<< wrong_ref => $code >> +=item * + +C<< wrong_ref => $code >> The code executed when a reference of incorrect type is encountered. The result of this snippet is also the result of the generated code, hence it defaults to C<'undef'>. It's a good place to C or C too. -=item C<< sub => $bool >> +=item * + +C<< sub => $bool >> Encloses the code into a C block. Default is true. -=item C<< compile => $bool >> +=item * + +C<< compile => $bool >> Makes L compile the code generated and return the resulting code reference. Be careful that in this case C must be a fully qualified function name. @@ -170,7 +185,8 @@ Defaults to true, but turned off when C is false. For example, this allows you to recall into C and C by using the C<\&@> prototype : my $grep = wrap { 'CORE::grep' => '\&@' }; - sub mygrep (&@) { $grep->(@_) } # the prototypes are intentionally different + # the prototypes are intentionally different + sub mygrep (&@) { $grep->(@_) } =cut