Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re: Accessing Methods of Another Package

by tedrek (Pilgrim)
on Nov 29, 2002 at 20:46 UTC ( [id://216590]=note: print w/replies, xml ) Need Help??


in reply to Accessing Methods of Another Package

one way you could accomplish this is by keeping a reference to the parent in each of the section objects so your code becomes something like this
package Module::Main ... sub init { my $self = shift; $self->{SEC1} = Module::Section1->new($self); $self->{SEC2} = Module::Section2->new($self); return 1; } package Module::Section1; sub new { my $class = shift; my $parent = shift || die; #require a parent.. my $self = {}; $self->{PARENT} = $parent; bless($self,$class); return $self; } sub do_something { my $self = shift; $self->{PARENT}->{SEC2}->method(); return; }
update: Or you could keep a reference to the Section2 object which might be a better method OO wise.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://216590]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others contemplating the Monastery: (3)
As of 2024-03-29 07:20 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found