|
Posted by shenkin on May 2, 2005, 3:53 pm
Please log in for more thread options
Here's an example: main imports Foo and Foo imports Bar (or rather,
tries to but cannot). If I put package Bar in a separate Bar.pm file
and "use" it from Foo, things work.
Per postings on similar topics that have appeared on this list in the
past, I've put the exporting apparatus into BEGIN{} blocks. This
enables main to import Foo, but I've not been able to find a way to get
Foo to import Bar. The program output is:
foo
Undefined subroutine &Foo::bar called at try.pl line 15.
Any suggestions? That is, other than (a) use a .pm file, as described
above, and (b) use fully qualified names.
--------- snip ---------
use strict;
import Foo;
foo();
package Foo;
use Exporter;
BEGIN {
our @ISA = qw(Exporter);
our @EXPORT = qw(foo);
}
import Bar;
sub foo{
print "foon";
bar();
}
package Bar;
use Exporter;
BEGIN {
our @ISA = qw(Exporter);
our @EXPORT = qw(bar);
}
sub bar{
print "barn";
}
--------- snip ---------
Thanks,
-P.
P.S. From a practical point of view. I can continue with my workaround
of keeping Bar in a .pm file, so I can't argue that this issue is
impeding my work. But I'm finding it quite puzzling, because here is a
situation where I thought I understood how things work, and my example
shows me that I don't, after all.
|
|
Posted by shenkin on May 2, 2005, 4:08 pm
Please log in for more thread options
I just discovered that if I take the main package and put it at the end
of the file, preceded by "package main;", things work.
-P.
|
|
Posted by Brian McCauley on May 4, 2005, 9:21 pm
Please log in for more thread options
shenkin@gmail.com wrote:
> I just discovered that if I take the main package and put it at the end
> of the file, preceded by "package main;", things work.
Yes, that's a perfectly good way, and indeed what most people do.
The other way is to enclose the packages in {}.
|
| Similar Threads | Posted | | Modules with several packages | October 16, 2005, 10:50 am |
| how to install multiple modules with one Makefile.PL | July 2, 2008, 11:56 am |
| Creating Makefiles for multiple nested modules | June 8, 2006, 3:33 pm |
| DBI and DBI::Oracle packages configuration | July 22, 2004, 8:55 am |
| Problems with forked packages and CPAN | March 30, 2006, 1:53 pm |
| Perl module that simplifies creation of packages? | August 22, 2006, 10:55 am |
| Storing multiple cookies | June 9, 2007, 11:58 am |
| WWW::Mechanize module: multiple Select. | July 13, 2004, 7:36 pm |
| HTML::Form, Multiple select Elements with Same name | July 30, 2004, 3:48 pm |
| Win32::Daemon - multiple processor problem | August 10, 2004, 6:03 am |
|