CC: | schwern [...] pobox.com |
Subject: | method as coderef |
Date: | Mon, 12 Sep 2011 11:41:38 +0800 |
To: | bug-Method-Signatures [...] rt.cpan.org |
From: | Sherwin Daganato <sherwind [...] gmail.com> |
Method does not work as expected when called as coderef.
I've included a test below to demonstrate the problem.
Method::Signatures 20100730
Perl 5.8.8
Mac OS X 10.5.8
=-=-=-=-=-=-=-=-=-
#!/usr/bin/perl
use strict;
use warnings;
use Test::More 'no_plan';
package Foo;
use Method::Signatures;
method bar($name) { }
method baz(@names) { }
package main;
my $module = 'Foo';
my $method_bar = 'bar';
my $method_baz = 'baz';
my ($coderef_bar, $coderef_baz);
{
no strict 'refs';
$coderef_bar = *{"$module\::$method_bar"}{CODE};
$coderef_baz = *{"$module\::$method_baz"}{CODE};
}
ok eval { $coderef_bar->('arg'); 1 }; # fails with /missing required
argument/ error
ok eval { $coderef_baz->('arg1', 'arg2'); 1 }; # succeeds
$coderef_bar = $module->can($method_bar);
$coderef_baz = $module->can($method_baz);
ok eval { $coderef_bar->('arg'); 1 }; # fails with /missing required
argument/ error
ok eval { $coderef_baz->('arg1', 'arg2'); 1 }; # succeds
ok eval { $module->$method_bar('arg'); 1 }; # succeeds
ok eval { $module->$method_baz('arg1', 'arg2'); 1 }; # succeeds