Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re: instantiate objects from non-Catalyst model classes with parameters

by ruoso (Curate)
on Jan 29, 2011 at 10:29 UTC ( #885010=note: print w/ replies, xml ) Need Help??


in reply to instantiate objects from non-Catalyst model classes with parameters

interesting you mention this. I have just wrote a model factory based on Catalyst::Component::InstancePerContext...

package Leilao::Model::Negocio; use Moose; extends 'Catalyst::Model'; use namespace::autoclean; use Module::Find; use Module::Load; use Sub::Name; use Catalyst::Component::InstancePerContext; use Moose::Meta::Class; sub BUILD { my ($self) = @_; my @modules = findallmod 'Leilao::Negocio'; foreach my $neg (@modules) { load $neg; (my $mod = $neg) =~ s/^Leilao::Negocio/Leilao::Model::Negocio/ +; my $sub = sub { my ($self, $c) = @_; return $neg->new ( #user => $c->user, schema => $c->model('DB')->schema ); }; my $class = Moose::Meta::Class->create( $mod, superclasses => +['Catalyst::Model']); $class->add_method(build_per_context_instance => $sub); Catalyst::Component::InstancePerContext->meta->apply($class); } } __PACKAGE__->meta->make_immutable; 1;

This model will use create adapted models for every class in the Leilao::Negocio namespace using Catalyst::Component::InstancePerContext and initializing the classes with arbitrary parameters.

daniel


Comment on Re: instantiate objects from non-Catalyst model classes with parameters
Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://885010]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (9)
As of 2014-08-29 15:22 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (281 votes), past polls