redo the currying syntax to get rid of one of the arrayrefs
Jesse Luehrs [Thu, 20 Aug 2009 05:04:49 +0000 (00:04 -0500)]
this will make it more difficult to add things like the subref form of
currying in the future, but it is simpler and cleaner for the vastly
more common case, and the subref form could be added back in via
something like handles => { foo => { grep => sub { ... } } } (rather
than using [] for the middle pair of braces, which would continue to
mean normal currying) if we decide it's really necessary.

lib/Moose.pm
lib/Moose/Meta/Attribute.pm
lib/Moose/Meta/Attribute/Native/Trait.pm
t/020_attributes/010_attribute_delegation.t
t/070_native_traits/202_trait_array.t
t/070_native_traits/203_trait_hash.t
t/070_native_traits/204_trait_number.t
t/070_native_traits/205_trait_list.t
t/070_native_traits/207_trait_string.t

index 3a35baf..2f2ad0c 100644 (file)
@@ -546,13 +546,13 @@ You may also use an array reference to curry arguments to the original method.
 
   has 'thing' => (
       ...
-      handles => { set_foo => [ set => [ 'foo' ] ] },
+      handles => { set_foo => [ set => 'foo' ] },
   );
 
   # $self->set_foo(...) calls $self->thing->set('foo', ...)
 
 The first element of the array reference is the original method name, and the
-second is an array reference of curried arguments.
+rest is a list of curried arguments.
 
 =item C<REGEXP>
 
index 821fe4a..69d3c1e 100644 (file)
@@ -736,9 +736,9 @@ sub _make_delegation_method {
     $method_body = $method_to_call
         if 'CODE' eq ref($method_to_call);
 
-    my $curried_arguments = [];
+    my @curried_arguments;
 
-    ($method_to_call, $curried_arguments) = @$method_to_call
+    ($method_to_call, @curried_arguments) = @$method_to_call
         if 'ARRAY' eq ref($method_to_call);
 
     return $self->delegation_metaclass->new(
@@ -746,7 +746,7 @@ sub _make_delegation_method {
         package_name       => $self->associated_class->name,
         attribute          => $self,
         delegate_to_method => $method_to_call,
-        curried_arguments  => $curried_arguments || [],
+        curried_arguments  => \@curried_arguments,
     );
 }
 
index 5058ba7..0ea1d08 100644 (file)
@@ -109,9 +109,7 @@ around '_make_delegation_method' => sub {
     my $next = shift;
     my ( $self, $handle_name, $method_to_call ) = @_;
 
-    my ( $name, $curried_args ) = @$method_to_call;
-
-    $curried_args ||= [];
+    my ( $name, @curried_args ) = @$method_to_call;
 
     my $method_constructors = $self->method_constructors;
 
@@ -126,7 +124,7 @@ around '_make_delegation_method' => sub {
         $handle_name,
         sub {
             my $instance = shift;
-            return $code->( $instance, @$curried_args, @_ );
+            return $code->( $instance, @curried_args, @_ );
         },
     );
 };
index e3a5f0a..95bd73c 100644 (file)
@@ -32,7 +32,7 @@ use Test::Exception;
         handles => {
             'foo_bar' => 'bar',
             foo_baz => 'baz',
-            'foo_bar_to_20' => [ bar => [ 20 ] ],
+            'foo_bar_to_20' => [ bar => 20 ],
         },
     );
 }
index 4c745ec..25afb92 100644 (file)
@@ -33,11 +33,11 @@ my $sort;
             'sort_options_in_place' => 'sort_in_place',
             'option_accessor'       => 'accessor',
             'add_options_with_speed' =>
-                [ 'push' => [ 'funrolls', 'funbuns' ] ],
+                [ 'push' => 'funrolls', 'funbuns' ],
             'prepend_prerequisites_along_with' =>
-                [ 'unshift' => [ 'first', 'second' ] ],
+                [ 'unshift' => 'first', 'second' ],
             'descending_options' =>
-                [ 'sort_in_place' => [ $sort = sub { $_[1] <=> $_[0] } ] ],
+                [ 'sort_in_place' => ($sort = sub { $_[1] <=> $_[0] }) ],
         }
     );
 }
@@ -260,12 +260,10 @@ is_deeply(
         'splice_options'        => 'splice',
         'sort_options_in_place' => 'sort_in_place',
         'option_accessor'       => 'accessor',
-        'add_options_with_speed' =>
-            [ 'push' => [ 'funrolls', 'funbuns' ] ],
+        'add_options_with_speed' => [ 'push' => 'funrolls', 'funbuns' ],
         'prepend_prerequisites_along_with' =>
-            [ 'unshift' => [ 'first', 'second' ] ],
-        'descending_options' =>
-            [ 'sort_in_place' => [$sort] ],
+            [ 'unshift' => 'first', 'second' ],
+        'descending_options' => [ 'sort_in_place' => $sort ],
     },
     '... got the right handles mapping'
 );
index 2ea8001..fe2e649 100644 (file)
@@ -28,7 +28,7 @@ use Test::Moose 'does_ok';
             'option_accessor'  => 'accessor',
             'key_value'        => 'kv',
             'options_elements' => 'elements',
-            'quantity'         => [ accessor => ['quantity'] ],
+            'quantity'         => [ accessor => 'quantity' ],
         },
     );
 }
@@ -157,7 +157,7 @@ is_deeply(
         'option_accessor'  => 'accessor',
         'key_value'        => 'kv',
         'options_elements' => 'elements',
-        'quantity'         => [ accessor => ['quantity'] ],
+        'quantity'         => [ accessor => 'quantity' ],
     },
     '... got the right handles mapping'
 );
index c3566cc..48736f8 100644 (file)
@@ -23,10 +23,10 @@ use Test::Moose;
             div         => 'div',
             mod         => 'mod',
             abs         => 'abs',
-            inc         => [ add => [1] ],
-            dec         => [ sub => [1] ],
-            odd         => [ mod => [2] ],
-            cut_in_half => [ div => [2] ],
+            inc         => [ add => 1 ],
+            dec         => [ sub => 1 ],
+            odd         => [ mod => 2 ],
+            cut_in_half => [ div => 2 ],
 
         },
     );
@@ -102,10 +102,10 @@ is_deeply(
         div         => 'div',
         mod         => 'mod',
         abs         => 'abs',
-        inc         => [ add => [1] ],
-        dec         => [ sub => [1] ],
-        odd         => [ mod => [2] ],
-        cut_in_half => [ div => [2] ],
+        inc         => [ add => 1 ],
+        dec         => [ sub => 1 ],
+        odd         => [ mod => 2 ],
+        cut_in_half => [ div => 2 ],
     },
     '... got the right handles mapping'
 );
index f6fe862..7ec29a0 100644 (file)
@@ -30,10 +30,10 @@ my $up;
             'join_options'         => 'join',
             'get_option_at'        => 'get',
             'sorted_options'       => 'sort',
-            'less_than_five'       => [ grep => [ $less = sub { $_ < 5 } ] ],
-            'up_by_one'            => [ map => [ $up = sub { $_ + 1 } ] ],
-            'dashify'    => [ join => ['-'] ],
-            'descending' => [ sort => [ $sort = sub { $_[1] <=> $_[0] } ] ],
+            'less_than_five'       => [ grep => ($less = sub { $_ < 5 }) ],
+            'up_by_one'            => [ map => ($up = sub { $_ + 1 }) ],
+            'dashify'    => [ join => '-' ],
+            'descending' => [ sort => ($sort = sub { $_[1] <=> $_[0] }) ],
         },
     );
 
@@ -121,10 +121,10 @@ is_deeply(
         'join_options'         => 'join',
         'get_option_at'        => 'get',
         'sorted_options'       => 'sort',
-        'less_than_five'       => [ grep => [$less] ],
-        'up_by_one'            => [ map => [$up] ],
-        'dashify'              => [ join => ['-'] ],
-        'descending'           => [ sort => [$sort] ],
+        'less_than_five'       => [ grep => $less ],
+        'up_by_one'            => [ map => $up ],
+        'dashify'              => [ join => '-' ],
+        'descending'           => [ sort => $sort ],
     },
     '... got the right handles mapping'
 );
index c14ff01..7c85ae8 100644 (file)
@@ -26,10 +26,9 @@ my $uc;
             chomp_string   => 'chomp',
             clear_string   => 'clear',
             length_string  => 'length',
-            exclaim        => [ append => ['!'] ],
-            capitalize_last =>
-                [ replace => [ qr/(.)$/, $uc = sub { uc $1 } ] ],
-            invalid_number => [ match => [qr/\D/] ],
+            exclaim        => [ append => '!' ],
+            capitalize_last => [ replace => qr/(.)$/, ($uc = sub { uc $1 }) ],
+            invalid_number => [ match => qr/\D/ ],
         },
     );
 }
@@ -108,9 +107,9 @@ is_deeply(
         chomp_string    => 'chomp',
         clear_string    => 'clear',
         length_string   => 'length',
-        exclaim         => [ append => ['!'] ],
-        capitalize_last => [ replace => [ qr/(.)$/, $uc ] ],
-        invalid_number => [ match => [qr/\D/] ],
+        exclaim         => [ append => '!' ],
+        capitalize_last => [ replace => qr/(.)$/, $uc ],
+        invalid_number => [ match => qr/\D/ ],
     },
     '... got the right handles methods'
 );