SPUG: Modules - more than one object in file?
Brian Ingerson
briani at activestate.com
Wed Oct 11 12:16:52 CDT 2000
Todd Wells wrote:
>
> I'm creating a module which uses some other objects internally, so I have
> multiple package statements in the same .pm file to define these other
> objects. Is there a good reason why I shouldn't do this? I'd prefer to
> keep it all in one file. However, I'm having a problem which I think is
> related.
>
> I have my module all in one file that contains 3 package statements, for
> objects A, B and C. e.g.:
>
> package A;
> sub new { blah }
> sub log { fooblah }
> 1;
>
> package B;
> @ISA = sq ( A );
> sub new { blahblah }
> 1;
>
> package C;
> sub new { moblah }
> 1;
>
> However, when I call
>
> $pack_b = B->new();
> $pack_b->log("foobar"), I get:
>
> Can't locate package "A" for @B::ISA at A.pm line 274.
> Can't locate package "A" for @B::ISA at A.pm line 274.
> Can't locate object method "log" via package "B" at A.pm line 274.
> Can't locate package "A" for @B::ISA.
Try this:
package A;
sub foo { print "It worked\n" }
package B;
@ISA = qw ( A );
sub new { bless [], shift }
$b = B->new;
$b->foo;
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
POST TO: spug-list at pm.org PROBLEMS: owner-spug-list at pm.org
Subscriptions; Email to majordomo at pm.org: ACTION LIST EMAIL
Replace ACTION by subscribe or unsubscribe, EMAIL by your Email-address
For daily traffic, use spug-list for LIST ; for weekly, spug-list-digest
Seattle Perl Users Group (SPUG) Home Page: http://www.halcyon.com/spug/
More information about the spug-list
mailing list