Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

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

by ruoso (Curate)
on Jan 29, 2011 at 10:29 UTC ( [id://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
Domain Nodelet?
Node Status?
node history
Node Type: note [id://885010]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others exploiting the Monastery: (1)
As of 2024-04-25 00:16 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found