[Catalyst] Running MyAppB under MyAppA (only for developers)

Oleg Pronin syber.rus at gmail.com
Wed Jul 25 20:23:09 GMT 2007


I need to plug in application B in A, so it could extend A's actions under
some namespace.

I understand this is not so simple, but i have no other way.
I write a dynamic admin interface (Uniadm) that will be plugged in to
various projects.
It will extend functionallity of a project it was plugged in to.
Admin interface will be available under www.myappA_site/uniadm/.
Both Uniadm and MyApp are catalyst projects itselves.

I see 2 ways to do that:


1) intercept request at handle_request stage in MyApp and redirect it to
handle_request of Uniadm.
   This is not a solution for me because Uniadm will need to forward to
MyApp's actions sometimes and vice versa.
   It will not be possible in this way.


2) Get all Uniadm's actions after initialization and register it in MyApp.
    I made a plugin and this is a piece of its code:


    my @ctrls =3D Module::Find::findallmod('Uniadm::Controller');
    foreach my $ctrl (@ctrls) {
        require Class::Inspector->filename($ctrl);
        $ctrl->config->{namespace} =3D Catalyst::Utils::class2prefix($ctrl,=
 0)
            unless defined $ctrl->config->{namespace};

        $ctrl->config->{namespace} =3D 'uniadm/'.$ctrl->config->{namespace};
    }

    require Uniadm;

    #Please god forgive me
    my @from_actions =3D values %{Uniadm->dispatcher->{action_hash}};
    my $to_dispatcher =3D MyApp->dispatcher;

    foreach my $from_action (@from_actions) {
        $to_dispatcher->register('MyApp', $from_action);
    }

After that i register Uniadm's views in MyApp.

I assume that Uniadm will always be loaded in SomeApp and will not be
started standalone so i understand

that in Uniadm's actions $c is not the Uniadm's object, it is MyApp's
object. So all calls to Uniadm's logic inside its actions go through
Uniadm->...

and a view is rendered by explicitly calling $c->forward to view.

Everything seems to be working except for 2 things:

 - Imported chained action remains in old namespace (without '/uniadm/'
prefix).

 - Uniadm has 'auto' action in root controller. It is not called when
processing requests under /uniadm/ namespace somwhy:


 .----------------------------------------------------------------+--------=
---.
        | Action                                                      |
Time      |

+----------------------------------------------------------------+---------=
--+
        | /auto                                                        |
0.011560s |

? where is /uniadm/auto ?
        | /uniadm/info/general                                  | 0.000193s|

Is there a better (easier) way to solve my problem?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.scsys.co.uk/pipermail/catalyst/attachments/20070725/498de=
087/attachment.htm


More information about the Catalyst mailing list