develooper Front page | perl.perl5.porters | Postings from August 2001

Re: The coderef in @INC strikes back

Thread Previous
From:
Rafael Garcia-Suarez
Date:
August 22, 2001 01:29
Subject:
Re: The coderef in @INC strikes back
Message ID:
20010822103520.A13629@rafael

On 2001.08.22 09:27:10 +0200 Jonathan Stowe wrote:
> So I sat down with my computer with a view to seeing what I could do about
> this and whilst writing a test to determine what use could be made of the
> coderef that is passed to the subroutine I  came up with :
> 
> #!/usr/bin/perl -w
> 
> use strict;
> 
> BEGIN
> {
>    push @INC , bless( sub { print "*@_*" }, 'Foo');
> }
> 
> use Foggle;
> 
> 
> Which to my surprise gives :
> 
> Can't locate object method "INC" via package "Foo" (perhaps you forgot to
> load "Foo"?) at inctest.pl line 10.
> BEGIN failed--compilation aborted at inctest.pl line 10.
 
This is not surprising -- you didn't define the method INC.
Here's a test case that works :

#!/opt/perl/bin/perl5.7.2 -w
sub Foo::INC { print "*@_*\n"; undef } # return undef filehandle: file not found
BEGIN
{
    push @INC , bless( { }, 'Foo');
}
use Foggle;

And this correctly reports :

*Foo=HASH(0x81096f4) Foggle.pm*
Can't locate Foggle.pm in @INC (@INC contains: /home/rafael/perllib /opt/perl/lib/5.7.2/i686-linux /opt/perl/lib/5.7.2 /opt/perl/lib/site_perl/5.7.2/i686-linux /opt/perl/lib/site_perl/5.7.2 /opt/perl/lib/site_perl . Foo=HASH(0x81096f4)) at /home/rafael/bin/quux line 9.
BEGIN failed--compilation aborted at /home/rafael/bin/quux line 9.

> Now maybe I shouldnt be surprised and maybe I have missed something here
> but to me this looks like it wants me to define Foo::INC() - but even
> doing that doesnt help.

You probably have missed that sub INC {...} always defines a subroutine in the
main:: package.

-- 
Rafael Garcia-Suarez

Thread Previous


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About