[Catalyst] Initialization

John M. Dlugosz wxju46gefd at snkmail.com
Sat Mar 5 09:58:40 GMT 2011


  On 3/5/2011 3:01 AM, Tomas Doran bobtfish-at-bobtfish.net |Catalyst/Allow to home| wrote:
>
> Ergo you can just do your work in the BUILD method for your model.

Thanks for that, and the example.
>
> Just pass in the root you want the model to see as config, add an attribute, and the 
> value will be there for you..
The root is already being set up somehow.  That's what path_to('root') in the example is 
finding?  Why does this need to be set again on Model's config?  Is the model not seeing 
that information at BUILD time?

>
> Something like:
>
> package MyApp::Model::Foo;
> use Moose;
> use namespace::autoclean;
>
> has root => (
>     is => 'ro',
>     required => 1,
> );
>
> sub BUILD {
>     my $self = shift;
>     ... your code here, and you can call $self->root  ...
> }
>
> and then in MyApp.pm:
>
> __PACKAGE__->config(
>     'Model::Foo' => {
>         root => __PACKAGE__->path_to('root'),
>   },
> );
>
> Cheers
> t0m
>
>
> _______________________________________________
> List: Catalyst at lists.scsys.co.uk
> Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
> Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
> Dev site: http://dev.catalyst.perl.org/




More information about the Catalyst mailing list