On 2002.01.14 17:29 Michael G Schwern wrote:
> On Mon, Jan 14, 2002 at 11:13:27AM +0100, Rafael Garcia-Suarez wrote:
> > On 2002.01.13 22:25 Michael G Schwern wrote:
> > > Why would this:
> > > 
> > >     BEGIN {
> > >         push @INC, 'foo';
> > >     }
> > > 
> > > put 'foo' into @INC twice if it were compiled?  The compiled program
> > > should not be storing the post-BEGIN value of @INC, it should store
> > > the original value at startup.
> > 
> > The compilation occurs at CHECK-time, that is, after 'foo' has been pushed
> > into @INC.
> 
> I don't know if this is true, but it isn't relevent.  Remember, BEGIN,
> INIT, CHECK, etc... time is only relevent to the current module being
> loaded/run.  As this example shows, Bar.pm's code is run before even
> Foo.pm's BEGIN block.  Replace -MBar with -MO=C and you get the idea.
> 
> # ~/tmp/Foo.pm
> package Foo;
> 
> BEGIN {
>     push @INC, 'foo';
> }
> 
> print "\@INC as Foo has modified it\n";
> print join "\n", @INC;
> 
> # ~/tmp/Bar.pm
> package Bar;
> 
> print "\@INC as Bar sees it\n";
> print join "\n", @INC;

Nah. You should wrap this code in a CHECK block : otherwise, in
your example, it will be run at BEGIN-time (i.e. when the Bar module
is use'd). That's what O.pm does.

> $ bleadperl -I/home/schwern/tmp -MBar -wle 'use Foo'

and this should be -wcle, not -wle ...

> @INC as Bar sees it
> 
> /home/schwern/tmp
> /usr/local/bleadperl/lib/5.7.2/ppc-linux-64int
> /usr/local/bleadperl/lib/5.7.2
> /usr/local/bleadperl/lib/site_perl/5.7.2/ppc-linux-64int
> /usr/local/bleadperl/lib/site_perl/5.7.2
> /usr/local/bleadperl/lib/site_perl
> .
> @INC as Foo has modified it
> 
> /home/schwern/tmp
> /usr/local/bleadperl/lib/5.7.2/ppc-linux-64int
> /usr/local/bleadperl/lib/5.7.2
> /usr/local/bleadperl/lib/site_perl/5.7.2/ppc-linux-64int
> /usr/local/bleadperl/lib/site_perl/5.7.2
> /usr/local/bleadperl/lib/site_perl
> .
> foo

With the modified Bar.pm :

$ bperl -MBar -wcle 'use Foo'
@INC as Foo has modified it

/opt/perl/src/lib
/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
Package `Foo' not found (did you use the incorrect case?) at -e line 1.
@INC as Bar sees it

/opt/perl/src/lib
/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
-e syntax OK

Reply via email to