Merge pull request #3 from ironcamel/fix-types-example
[p5sagit/Function-Parameters.git] / lib / Function / Parameters.pm
index 8720269..4bd2e1c 100644 (file)
@@ -7,7 +7,7 @@ use Carp qw(confess);
 
 use XSLoader;
 BEGIN {
-       our $VERSION = '1.0104';
+       our $VERSION = '1.0202';
        XSLoader::load;
 }
 
@@ -57,6 +57,11 @@ sub _reify_type_default {
        Moose::Util::TypeConstraints::find_or_create_isa_type_constraint($_[0])
 }
 
+sub _delete_default {
+       my ($href, $key, $default) = @_;
+       exists $href->{$key} ? delete $href->{$key} : $default
+}
+
 my @bare_arms = qw(function method);
 my %type_map = (
        function    => {
@@ -148,16 +153,12 @@ sub import {
                $clean{attrs} = join ' ', map delete $type{$_} || (), qw(attributes attrs);
                _assert_valid_attributes $clean{attrs} if $clean{attrs};
                
-               $clean{default_arguments} =
-                       exists $type{default_arguments}
-                       ? !!delete $type{default_arguments}
-                       : 1
-               ;
+               $clean{default_arguments} = _delete_default \%type, 'default_arguments', 1;
+               $clean{named_parameters}  = _delete_default \%type, 'named_parameters',  1;
+               $clean{types}             = _delete_default \%type, 'types',             1;
 
-               $clean{check_argument_count} = !!delete $type{check_argument_count};
-               $clean{invocant} = !!delete $type{invocant};
-               $clean{named_parameters} = !!delete $type{named_parameters};
-               $clean{types} = !!delete $type{types};
+               $clean{check_argument_count} = _delete_default \%type, 'check_argument_count', 0;
+               $clean{invocant}             = _delete_default \%type, 'invocant',             0;
 
                if (my $rt = delete $type{reify_type}) {
                        ref $rt eq 'CODE' or confess qq{"$rt" doesn't look like a type reifier};
@@ -514,7 +515,7 @@ exchange the order of the arguments doesn't matter anymore. As with hash
 initialization, you can specify the same key multiple times and the last
 occurrence wins:
 
-  rectangle(height => 1, width => 2, height => 2, height => 5;
+  rectangle(height => 1, width => 2, height => 2, height => 5);
   # same as: rectangle(width => 2, height => 5);
 
 You can combine positional and named parameters as long as the positional
@@ -652,7 +653,8 @@ L</Experimental feature: Types> below).
 
 Valid values: code references. The function specified here will be called to
 turn type annotations into constraint objects (see
-L</Experimental feature: Types> below).
+L</Experimental feature: Types> below). It will receive two arguments: a string
+containing the type description, and the name of the current package.
 
 The default type reifier is equivalent to:
 
@@ -744,7 +746,7 @@ types. That is, before each parameter you can put a type specification
 consisting of identifiers (C<Foo>), unions (C<... | ...>), and parametric types
 (C<...[...]>). Example:
 
-  fun foo(Int $n, ArrayRef[String | CodeRef] $cb) { ... }
+  fun foo(Int $n, ArrayRef[Str | CodeRef] $cb) { ... }
 
 If you do this, the type reification function corresponding to the keyword will
 be called to turn the type (a string) into a constraint object. The default