perl - How can I get hold of all the arguments passed to a method with MooseX::Method::Signatures? -


if use moosex::method::signatures, , want pass arguments onto second method, have explicitly list them again:

method foo (str :$bar!, int: :$baz!) {     ...     return $self->_foo2(bar => $bar, baz => $baz); } 

it nice if like:

method foo (str :$bar!, int: :$baz!) {     ...     return $self->_foo2(%args); } 

this documentation method::signatures suggests can use @_ drops named parameter keys.

having done little testing, seems moosex::method::signatures "odd 1 out" of major implementations of method signatures. others allow use @_ expected; mxms not.

use strict; use warnings; use test::more 0.96;  {   package mybase;   sub new { bless {}, shift }   sub _foo { \@_ } }  {   package usekavorka;   use kavorka;   use parent -norequire => qw(mybase);    method foo (str :$bar!, int :$baz!) {     $self->_foo(@_);   } }  {   package usems;   use method::signatures;   use parent -norequire => qw(mybase);    method foo (str :$bar!, int :$baz!) {     $self->_foo(@_);   } }  {   package usemxms;   use moose;   use moosex::method::signatures;   extends qw(mybase);    method foo (str :$bar!, int :$baz!) {     $self->_foo(@_);   } }  {   package usefp;   use function::parameters;   use parent -norequire => qw(mybase);    method foo (str :$bar, int :$baz) {     $self->_foo(@_);   } }  $class (qw/ usekavorka usems usemxms usefp /) {   $obj = $class->new;   is_deeply(     $obj->foo(bar => "hello world", baz => 42),     [ $obj, bar => "hello world", baz => 42 ],     "\@_ worked fine in $class",   ); }  done_testing;  __end__ ok 1 - @_ worked fine in usekavorka ok 2 - @_ worked fine in usems not ok 3 - @_ worked fine in usemxms #   failed test '@_ worked fine in usemxms' #   @ foo.pl line 55. #     structures begin differing at: #          $got->[1] = usemxms=hash(0x92c0cc8) #     $expected->[1] = 'bar' ok 4 - @_ worked fine in usefp 1..4 # looks failed 1 test of 4. 

i'm biased because wrote it, advice switch kavoka gives pretty features of moosex::method::signatures, without massive slow down.


Comments

Popular posts from this blog

php - render data via PDO::FETCH_FUNC vs loop -

c++ - OpenCV Error: Assertion failed <scn == 3 ::scn == 4> in unknown function, -

The canvas has been tainted by cross-origin data in chrome only -