Many thanks. I've had a slight snag with the syntax. If I uncomment the line in the following code I get:
Can't locate object method "set" via package "config" (perhaps you forgot to load "config"?) at myapp.pl line 9.
#!/usr/bin/perl use strict; use warnings; use Auto::Config; my $root_local = Auto::Config::config->get(root => 'local'); # This line produces the error message # config->set('root', remote => 'docroot_new'); Auto::Config::config->set('root', remote => 'docroot_new'); print "$root_local\n";
Do the methods have to be fully qualified like that? Or, more likely, have I goofed?
package Auto::Config_class; sub new { my $class = shift; my $fn = shift; my $this = { root => { local => 'c:/local', remote => 'docroot', }, }; bless $this, $class } sub get { my $this=shift; my $pri_key = shift; my $sec_key = shift; my $default = shift; exists $this->{$pri_key}{$sec_key} ? $this->{$pri_key}{$sec_key} : $default; } sub set { my $this=shift; my $pri_key = shift; my $sec_key = shift; my $value = shift; $this->{$prim_key}{$sec_key} = $value; } 1;
package Auto::Config; use strict; use warnings; require Exporter; our @EXPORT=qw(config); use lib '..'; use Auto::Config_class; my $config; sub config { $config = Auto::Config_class->new('../cwi.ini') unless defined $config; $config; } 1;
Again, many thanks.
In reply to Re^2: Using "Class Data as Package Variables" to hold a global
by wfsp
in thread Using "Class Data as Package Variables" to hold a global
by wfsp
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |