Skip Menu |

This queue is for tickets about the indirect CPAN distribution.

Report information
The Basics
Id: 73848
Status: rejected
Priority: 0/
Queue: indirect

People
Owner: Nobody in particular
Requestors: MITHALDU [...] cpan.org
Cc:
AdminCc:

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



Subject: indirect should not complain about `ok Module->new;`
`ok Module->new;` is a perfectly sane function call on the result of a method call, but indirect thinks it's an indirect method call.
On Mon Jan 09 08:18:27 2012, MITHALDU wrote: Show quoted text
> `ok Module->new;` is a perfectly sane function call on the result of a > method call, but indirect thinks it's an indirect method call.
Actually it’s Perl that thinks it’s an indirect method calls and compiles it as such. indirect.xs detects that and complains.
Le Lun 09 Jan 2012 08:18:27, MITHALDU a écrit : Show quoted text
> `ok Module->new;` is a perfectly sane function call on the result of a > method call, but indirect thinks it's an indirect method call.
This is a "perfectly sane function call" if Perl knows that you mean it to be a function call, i.e. when 'ok' has been previously declared or imported. As sprout said, this bare snippet compiles to a method call : $ perl -MO=Deparse -e 'ok X->new' 'X'->ok->new; -e syntax OK This is not even equivalent to a function call, because it may succeed at run-time even if X::new doesn't exist (e.g. when X isa Y and Y::new exists). When 'ok' is declared before the code is compiled, Perl does what you expect : $ perl -MO=Deparse -e 'sub ok; ok X->new' ok('X'->new); sub ok ; -e syntax OK $ perl -MO=Deparse -e 'sub ok { }; ok X->new' sub ok { } ok 'X'->new; -e syntax OK $ perl -MTest::More= -MO=Deparse -e 'ok X->new' ok 'X'->new; -e syntax OK indirect.pm reports the indirect construct in the first case and stays silent in the second case, which is the correct behaviour. Vincent.
I thought it would be obvious from the use of ok that i was importing it from Test::More, so i didn't mention it. Please consider this then to be the required mention: My code looked like this: no indirect; use Test::More; ok TestModule->marp; As you said, importing should declare the ok, so it would be known as a sub. But for whatever reason it actually is still interpreted as an indirect call. Would this be a bug in Perl itself?
Le Mar 10 Jan 2012 11:55:34, MITHALDU a écrit : Show quoted text
> I thought it would be obvious from the use of ok that i was importing it > from Test::More, so i didn't mention it. Please consider this then to be > the required mention: > > My code looked like this: > > no indirect; > use Test::More; > ok TestModule->marp; > > As you said, importing should declare the ok, so it would be known as a > sub. But for whatever reason it actually is still interpreted as an > indirect call. Would this be a bug in Perl itself?
Do you mean 'compiled' instead of 'interpreted'? Then this isn't true. perl (5.8.9, 5.10.1, 5.12.4 and 5.14.1) correctly compiles your code as a sub call, and indirect correctly doesn't complain : $ perl -MO=Deparse -e 'no indirect; use Test::More; ok TestModule->marp' no indirect; use Test::More; BEGIN { $^H{'indirect'} = q(35359128); } ok 'TestModule'->marp;
Damn. Sorry again, i was still thinking this was a very general thing. How about this? $ perl -MO=Deparse -e 'no indirect; use Net::FTP; use Test::More; ok Net::FTP->new' Indirect call of method "ok" on object "Net::FTP" at -e line 1. no indirect; use Net::FTP; use Test::More; BEGIN { $^H{'indirect'} = q(56545644); } 'Net::FTP'->ok->new; -e syntax OK
Le Mar 10 Jan 2012 13:42:10, MITHALDU a écrit : Show quoted text
> Damn. Sorry again, i was still thinking this was a very general thing. > How about this? > > $ perl -MO=Deparse -e 'no indirect; use Net::FTP; use Test::More; ok > Net::FTP->new' > Indirect call of method "ok" on object "Net::FTP" at -e line 1. > no indirect; > use Net::FTP; > use Test::More; > BEGIN { > $^H{'indirect'} = q(56545644); > } > 'Net::FTP'->ok->new; > -e syntax OK
When the candidate for the object (here, 'Net::FTP') denotes a package that is non-empty, then perl decides that 'ok Net::FTP->new' is an indirect method call. Note the difference : $ perl -MO=Deparse -e 'sub ok; ok X->new' ok('X'->new); sub ok ; -e syntax OK $ perl -MO=Deparse -e 'sub X::foo; sub ok; ok X->new' sub X::foo; 'X'->ok->new; sub ok ; -e syntax OK indirect.pm properly reports this gotcha. Vincent.
Yeah, mst just explained to me that it's so `sub new` in a package doesn't break `new OtherThing`. Kind of ugly, but oh well. Thanks for your patience as well. :)
Le Mar 10 Jan 2012 14:21:02, MITHALDU a écrit : Show quoted text
> Yeah, mst just explained to me that it's so `sub new` in a package > doesn't break `new OtherThing`. Kind of ugly, but oh well. Thanks for > your patience as well. :)
I didn't know what was the reason for this behaviour, so I have learnt something new as well. Thanks. Vincent.