X-Git-Url: http://git.vpit.fr/?p=perl%2Fmodules%2FSub-Prototype-Util.git;a=blobdiff_plain;f=lib%2FSub%2FPrototype%2FUtil.pm;h=d52b905f8c8370fad0e2b7f218952da99b52e30f;hp=6544afce389d3fc79a90063aaf317b360f6d61c4;hb=26e43a265dbd585d36cc6b3fc48c423e17421a62;hpb=73786f1f0683e45f68b8d0d486c38e447b085fc4 diff --git a/lib/Sub/Prototype/Util.pm b/lib/Sub/Prototype/Util.pm index 6544afc..d52b905 100644 --- a/lib/Sub/Prototype/Util.pm +++ b/lib/Sub/Prototype/Util.pm @@ -1,5 +1,7 @@ package Sub::Prototype::Util; +use 5.006; + use strict; use warnings; @@ -12,13 +14,13 @@ Sub::Prototype::Util - Prototype-related utility routines. =head1 VERSION -Version 0.08 +Version 0.09 =cut use vars qw/$VERSION/; -$VERSION = '0.08'; +$VERSION = '0.09'; =head1 SYNOPSIS @@ -68,13 +70,14 @@ sub _clean_msg { Flattens the array C<@args> according to the prototype C<$proto>. When C<@args> is what C<@_> is after calling a subroutine with prototype C<$proto>, C returns the list of what C<@_> would have been if there were no prototype. +It croaks if the arguments can't possibly match the required prototype, e.g. when a reference type is wrong or when not enough elements were provided. =cut sub flatten { my $proto = shift; return @_ unless defined $proto; - my @args; + my @args; while ($proto =~ /(\\?)(\[[^\]]+\]|[^\];])/g) { my $p = $2; if ($1) { @@ -126,7 +129,7 @@ Valid keys are : 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 C. +You may also want to use L. =item C<< wrong_ref => $code >> @@ -162,7 +165,7 @@ sub _wrap { my $cur = '$_[' . $i . ']'; if ($ref) { if (length $p > 1) { - return 'my $r = ' . $opts->{ref} . '(' . $cur . '); ' + return 'my $r = ' . $opts->{ref} . '(' . $cur . '); ' . join ' els', map( { "if (\$r eq '" . $reftypes{$_} ."') { " @@ -307,7 +310,7 @@ Tests code coverage report is available at L