2009/12/22 Shlomi Fish <shlo...@iglu.org.il>: > Hi Dermot! Hi Shlomi,
>> 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, >> ); ... > This doesn't seem to do what you want. I think you want a meaningful "default" > or "builder" instead: > > <<<<<<<<< > builder => Str > The value of this key is the name of the method that will be > called to obtain the value used to initialize the attribute. > See the builder option docs in Class::MOP::Attribute > and/or Moose::Cookbook::Basics::Recipe8 for more information. >>>>>>>>>> > >> >> 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; >> } >> > Again, this should most probably be a "builder" method. Okay, I'll take that advice. So now I have has 'config' => ( is => 'ro', lazy_build => 1, ); sub _build_config { my $self = shift; my $config = AppConfig->new( { CREATE => 1, GLOBAL => { ARGCOUNT => 1, }, }); my $config_file = "$Bin/../spl.conf"; $self->croak("Can't open config file $config_file\n") if (! -e $config_file); $config->file($config_file); return $config; } And it works a treat, tests all passed, Dumper gave me what I wanted and $self->config->media_root gives me a meaningful response. You get the cigar. > Wow! This is the first time I was able to reply to a question here. Party at > my place at 16:00. Bring a lot of Moose-shaped cakes. (If it turned out, I was > misleading, I won't get to eat any of them - ;-)). Elkles cake....poor I know.