Hello friends,

Please take a look at this and let me know if you know how to resolve it.

Lets say I have moduleA.pm with the following constructor in which I also 
call a moduleB:

--------------------
moduleA.pm
--------------------
package moduleA.pm
use strict;
use warnings;
use moduleB;

sub new {
    my $class = shift;
    my $this = {};
    bless $this, $class;

    $this->{moduleB} = new moduleB ( holder => $this ); # Ref to itself
    return $this,
}
1;
--------------------


Now, lets say I have moduleB with the following constructor:


--------------------
moduleB.pm
--------------------
package moduleB;
use strict;
use warnings;

sub new {
    my $class = shift;
    my $this = {
        @_
    };
    bless $this, $class;
}
1;
--------------------


Finally, I call moduleA from a main.pl script:


--------------------
main.pl
--------------------
use strict;
use warnings;
use moduleA;

my $m = new moduleA;

--------------------


Ok. Now, as you can see, when I call moduleB from moduleA, I'm passing the 
moduleA blessed object to the constructor of moduleB, so moduleB can handle 
some things that need to be handled in the main constructed object, like 
properties that can be set in moduleA from moduleB and that I can query 
directly in the object constructed at main.pl.

Example: Some other sub in moduleB, could easily read or modify a property 
of moduleA blessed in main.pl (e.g. main.pl assigns $m->{username} = 'john', 
and some sub in moduleB can have access to that using 
$class->{holder}->{username}).

This works fine. However, I want to know if there is some way to let moduleB 
know how to assign that "holder" property by itself (automatically). I mean, 
is there any method to detect when your constructor is being assigned as 
property of another blessed object and then take a reference to that blessed 
object calling this new constructor, without having to receive a reference 
to it as argument?

If I'm not making myself clear, please let me know so I can try to explain 
it better.


Thanks in advance to all for your time, thoughts and knowledge.


Cheers,

Paco Zarabozo



_______________________________________________
ActivePerl mailing list
[email protected]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Reply via email to