ViceRaid has asked for the wisdom of the Perl Monks concerning the following question:
Good morning, and my apologies in advance for a rather long and meandering supplication.
I came across something puzzling yesterday evening; it may likely prove to be just an unremarkable example of the Fool Pattern, but anyway. I'm creating a module that fakes a particular environment, mainly by declaring big sets of global variables. It started a bit like this
package Totally::Fake; our @ISA = qw/Exporter/; our ($fake, @faker); @EXPORT = qw/$fake @faker/;
The dream was that I could easily check the perl scripts I wrote for this environment using 'perl -c -MTotally::Fake -Mstrict my_script.pl', and all the variables will be there and strict won't complain.
First thing I don't understand
This didn't work. my_script.pl would refer to $fake and strict would complain. So I tried making a little test script:
use Totally::Fake; use lib '/path/to/dev/version'; print $fake;
Second thing I don't understand:
This did work - but only because of the presence of the use lib declaration. I could add a non-existent path to @INC, so loading exactly the same version of Totally::Fake from /usr/lib/perl, and it would work, where it wouldn't without use lib. This seems really weird to me. Why should 'use lib' affect my exports?
Third thing I don't understand
So some poking and tinkering later, I happened to try 'use base qw/Exporter/' instead of 'our @ISA = qw/Exporter/' in my module ... and it finally worked how I'd like it to. Which is good, but bad. I had a look at the documentation for base. How does inheriting using base differ from declaring @ISA, so that one works here, and the other doesn't?
With thanks in advance
ViceRaid
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Side effects of use-ing base (vs our @ISA)
by herveus (Prior) on Sep 10, 2003 at 11:17 UTC | |
by ViceRaid (Chaplain) on Sep 10, 2003 at 11:36 UTC | |
by bobn (Chaplain) on Sep 10, 2003 at 13:19 UTC | |
Re: Side effects of use-ing base (vs our @ISA)
by Abigail-II (Bishop) on Sep 10, 2003 at 11:13 UTC | |
by ViceRaid (Chaplain) on Sep 10, 2003 at 11:29 UTC | |
by Abigail-II (Bishop) on Sep 10, 2003 at 11:40 UTC | |
by Abigail-II (Bishop) on Sep 10, 2003 at 11:47 UTC |