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

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.

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

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://885010]
[jedikaiti]: Hi, Monks
[marto]: heya jedikaiti!
[jedikaiti]: Cute Robot!
[jedikaiti]: How's life, marto?
[marto]: I saw this robot the other day, pretty fancy stuff. Things are pretty good jedikaiti, improving :) How are things with you?
[jedikaiti]: Doing OK, but a little achy this AM - I think the cats were using me as a wrestling mat and mattress while I was asleep last night.

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (18)
As of 2017-07-25 15:04 GMT
Find Nodes?
    Voting Booth?
    I came, I saw, I ...

    Results (374 votes). Check out past polls.