kalium has asked for the wisdom of the Perl Monks concerning the following question:
The code (incomplete) it is calling is below.Encoder::Config::set_config_file($config_file); my $config_obj = Encoder::Config::get_instance;
What's odd is that defined $instance in the get_instance sub always returns true. I went through the debugger, and sure enough, as soon as I enter get_instance my global $instance variable seems to be a hash. Any feedback is greatly appreciatedpackage Encoder::Config; my $global_config_file; my $called; my $instance = undef; sub get_instance { my $default_config_file = '../etc/system.ini'; return $instance if defined $instance; $instance = {}; bless $instance; if ($global_config_file) { $instance->load_config($global_config_file); } else { $instance->load_config($default_config_file); } return $instance; } sub set_config_file { $global_config_file = shift; return if $called; $called = 1; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Global and autovivification?
by moritz (Cardinal) on Nov 04, 2008 at 16:05 UTC | |
by kalium (Sexton) on Nov 04, 2008 at 16:09 UTC | |
by kalium (Sexton) on Nov 04, 2008 at 16:22 UTC |