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:
You would not need the get_log_instance sub sincepackage Log; my $instance = undef; sub new { shift; unless ($instance){ $instance={}; bless $instance,"Log"; } return $instasnce; }
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. :-)| handwaving here my $log=new Log(); |
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Singleton Log Object
by Anonymous Monk on Jan 08, 2013 at 20:17 UTC |