aHi,

I just starting out with Moose so forgive me if I'm slow on the up-take.

I have a parent class and I want it to contain some configuration
information. I'm using AppConfig and that returns configuration as
instance. But when I try and access data from the configuration, such
as `print $self->config->media_root`, I am getting "unblessed
reference" errors.

I am not sure if my attribute option choices are best suited for what
I want. Can anyone give me some pointers? I could use Config::General
but, as an exercise, I'd like to know how to install an instance
within my classes.
Thanks in advance,
Dp.


package Media;

use metaclass (
    metaclass   => 'Moose::Meta::Class',
    error_class => 'Moose::Error::Croak',
);
use Moose;
use AppConfig;
use FindBin qw($Bin);
use lib "$Bin/../";


has 'config'    => (
        is          => 'ro',
        lazy        => 1,
        default     => sub{ {} },
        trigger     => \&_get_config,
);

sub _get_config {
    my $self = shift;
    my $config = AppConfig->new( {
            CREATE  => 0,
        });
    $config->define('media_root',{ ARGCOUNT=> 'ARGCOUNT_ONE' });
    my $config_file = "$Bin/../media.conf";
    $self->croak("Can't open config file $config_file\n") if (! -e
$config_file);
    $config->file($config_file);
    return $config;
}

Reply via email to