[Catalyst] Dynamic model and controller creation

Bill Moseley moseley at hank.org
Mon Jan 2 16:30:19 GMT 2012

On Mon, Jan 2, 2012 at 6:42 PM, Tomas Doran <bobtfish at bobtfish.net> wrote:

> Why are you messing around with ACCEPT_CONTEXT to do this?
> Why not just use COMPONENT to return the service class once?

Oh, I'm glad you brought that up.

Couple of reasons.  Not shown in my sample code, but I'm setting an
attribute at construction time from another model instance.

That is,

    my ( $self, $c, @args ) =3D @_;

    my $service =3D $self->service;

    unless ( $service ) {
        my $service_class =3D $self->service_class;
        Class::MOP::load_class( $service_class );

        $service =3D $service_class->new({
            *connection =3D> $c->model( 'Some::Client' ),*

Where Model::Foo does use Model::Adaptor.   Maybe I could  work with
setup_components to make sure the model instances are created in the
correct order (or user Bread::Board as discussed earlier).

I'm also using a few models that create a socket at instance time and are
not smart about forking.  (In some cases I wrap those in a separate class,

> master/lib/CatalystX/**JobServer/Web/Plugin/**ModelsFromConfig.pm#L7<http=
> Which is code to do exactly what you want - i.e. setup any models there is
> config for, but which don't have an explicit class on-disk, and then go on
> to setup controllers for each model setup.

Sure does!  Thanks,

-- =

Bill Moseley
moseley at hank.org
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.scsys.co.uk/pipermail/catalyst/attachments/20120102/d2898=

More information about the Catalyst mailing list