Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re: Singleton Log Object

by blue_cowdawg (Monsignor)
on Jan 08, 2013 at 20:08 UTC ( #1012330=note: print w/ replies, xml ) Need Help??


in reply to Singleton Log Object

      sub new{ my ($class,$logpath) = @_; unless ( ref $singleton eq 'Log' ) { $singleton = {}; bless( $singleton, $class ); $singleton->create_path($logpath); } return $singleton; }

There's a couple of things I'd change:

package Log; my $instance = undef; sub new { shift; unless ($instance){ $instance={}; bless $instance,"Log"; } return $instasnce; }
You would not need the get_log_instance sub since
| handwaving here my $log=new Log(); |
would either return the instance in play already or create a new one it there wasn't one in play. Creating a singleton is something I do all the time. Especially for my logging module. :-)


Peter L. Berghold -- Unix Professional
Peter -at- Berghold -dot- Net; AOL IM redcowdawg Yahoo IM: blue_cowdawg


Comment on Re: Singleton Log Object
Select or Download Code
Re^2: Singleton Log Object
by Anonymous Monk on Jan 08, 2013 at 20:17 UTC
    Great to get some feed back so promptly! You're the best, thanks so much.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (13)
As of 2015-07-02 09:14 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (33 votes), past polls