Skip Menu |

This queue is for tickets about the Method-Signatures CPAN distribution.

Report information
The Basics
Id: 70881
Status: rejected
Priority: 0/
Queue: Method-Signatures

People
Owner: Nobody in particular
Requestors: sherwind [...] gmail.com
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: (no value)
Fixed in: (no value)



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
CC: schwern [...] pobox.com
Subject: Re: [rt.cpan.org #70881] AutoReply: method as coderef
Date: Mon, 12 Sep 2011 11:57:01 +0800
To: bug-Method-Signatures [...] rt.cpan.org
From: Sherwin Daganato <sherwind [...] gmail.com>
Apparently coderef will not work if *self* is not passed as argument. e.g. $coderef->($module, $arg) Sorry for wasting time. Please disregard this bug. On Mon, Sep 12, 2011 at 11:41 AM, Bugs in Method-Signatures via RT <bug-Method-Signatures@rt.cpan.org> wrote: Show quoted text
> > Greetings, > > This message has been automatically generated in response to the > creation of a trouble ticket regarding: >        "method as coderef", > a summary of which appears below. > > There is no need to reply to this message right now.  Your ticket has been > assigned an ID of [rt.cpan.org #70881].  Your ticket is accessible > on the web at: > >    https://rt.cpan.org/Ticket/Display.html?id=70881 > > Please include the string: > >         [rt.cpan.org #70881] > > in the subject line of all future correspondence about this issue. To do so, > you may reply to this message. > >                        Thank you, >                        bug-Method-Signatures@rt.cpan.org > > ------------------------------------------------------------------------- > 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 > >
Yes, this behavior is correct. If you call a method as a code ref manually you have to include the invocant as the first argument yourself. That's a normal Perl thing.