D
David Squire
Hi,
I am reorganizing some of my Perl code to place modules where they can
be found via environment variable PERL5LIB. Some namespace issues are
not working as I would have expected, and I have not been able to find a
nice piece of documentation to explain this.
For example, consider this scenario:
I have directory MyLib (present in $PERL5LIB), which contains two
subdirectories Foo and Bar. Foo contains a module FooTools.pm, and Bar
contains BarTools.pm, i.e. the files MyLib/Foo/FooTools.pm and
MyLib/Bar/BarTools.pm both exist.
In FooTools.pm, I have:
use Bar::BarTools;
Later in FooTools.pm, I want to use a function func() that lives in
BarTools.pm. I expected this to work:
Bar::BarTools::func();
It did not, telling me that it could not find the function, though it is
certainly present in MyLib/Bar/BarTools.pm. This, however, *did* work:
BarTools::func();
Why is it that 'Bar' must be present in the 'use' statement (as I would
in fact expect), but cannot be present when I call the function? I would
have expected a fully qualified name always to work.
What would happen if there were a module BarTools in Foo, and I had done
this in FooTools.pm:
use Bar::BarTools;
use Foo::BarTools;
....
BarTools::func();
?
Would Bar::BarTools::func() work only if there were such a conflict?
Any help or pointers much appreciated.
Regards,
David
I am reorganizing some of my Perl code to place modules where they can
be found via environment variable PERL5LIB. Some namespace issues are
not working as I would have expected, and I have not been able to find a
nice piece of documentation to explain this.
For example, consider this scenario:
I have directory MyLib (present in $PERL5LIB), which contains two
subdirectories Foo and Bar. Foo contains a module FooTools.pm, and Bar
contains BarTools.pm, i.e. the files MyLib/Foo/FooTools.pm and
MyLib/Bar/BarTools.pm both exist.
In FooTools.pm, I have:
use Bar::BarTools;
Later in FooTools.pm, I want to use a function func() that lives in
BarTools.pm. I expected this to work:
Bar::BarTools::func();
It did not, telling me that it could not find the function, though it is
certainly present in MyLib/Bar/BarTools.pm. This, however, *did* work:
BarTools::func();
Why is it that 'Bar' must be present in the 'use' statement (as I would
in fact expect), but cannot be present when I call the function? I would
have expected a fully qualified name always to work.
What would happen if there were a module BarTools in Foo, and I had done
this in FooTools.pm:
use Bar::BarTools;
use Foo::BarTools;
....
BarTools::func();
?
Would Bar::BarTools::func() work only if there were such a conflict?
Any help or pointers much appreciated.
Regards,
David