|There's more than one way to do things|
Storing object references during creation of ->new objectby perldarren (Novice)
|on Aug 05, 2012 at 15:14 UTC||Need Help??|
perldarren has asked for the
wisdom of the Perl Monks concerning the following question:
I could really do with a hand on some OO perl that I'm battling with please perlmonks.
Here is what I'm trying to do: I have 2 packages
The LogSimple logging object is created like so, the important piece to focus on here in this object is the function reference stored in 'exit'
Next I initialise the following object, there can be multiples of these with different serial numbers.
The LogSimple object handles any exit from the project like this:
Where the script would exit 1. I use the LogSimple package in other projects and have recently added the optional ability to make a callback so that 'stuff' can take place before the exit..
Now, when something goes wrong talking to $server object I would like to call the subroutine\&DEC::Project::exit_routine
I can get exit_routine to execute except I want to be able to issue commands to all of the $server objects from \&DEC::Project::exit_routine just before the exit.
I am trying to store references to all of the $server objects as they are created in ->new inside a global hash like this:
My thinking is that I should be able to loop through the hash executing whatever methods I need against all of the objects like this:
However I keep running into the following: Can't call method "logout" on unblessed reference
This is my first real venture into OO programming so this is a real challenge for me. Anyone able to offer advice ?
Many thanks, Darren