On Tuesday 22 Dec 2009 15:10:06 Dermot wrote: > 2009/12/22 Shlomi Fish <shlo...@iglu.org.il>: > > Hi Dermot! > > Hi Shlomi, >
Hi. > >> 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; > } I don't see where you've associated << _build_config >> with the 'config' attribute. Or is this some kind of undocumented default or a property of your meta-class. > > 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. A chocolate cigar I hope. I don't smoke. ;-) But I'm glad I could be of help. > > > 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. > What is Elkles? http://www.google.com/search?q=elkles does not seem to know. I know what an "Elk" is. Regards, Shlomi Fish -- ----------------------------------------------------------------- Shlomi Fish http://www.shlomifish.org/ Stop Using MSIE - http://www.shlomifish.org/no-ie/ Bzr is slower than Subversion in combination with Sourceforge. ( By: http://dazjorz.com/ )