[Catalyst] Plugin methods and context namespace
Sebastian Riedel
sri at oook.de
Fri Nov 25 03:19:21 CET 2005
Am 25.11.2005 um 02:22 schrieb John Wang:
> On 11/24/05, Sebastian Riedel <sri at oook.de> wrote:
> Am 24.11.2005 um 23:36 schrieb John Wang:
>
> > To keep the $c context namespace cleaner, I'd like to add plugin
> > methods like $c->myplugin->foo instead of $c->foo.
> > [...]
> > sets $c->myplugin( MyPlugin->new( $c ) ) in prepare
> > [...]
>
> MyApp->plugin( 'prototype', 'HTML::Prototype' );
>
> $c->prototype->define_javascript_functions;
>
> What if the plugin methods need the $c context object like a
> Catalyst::Plugin?
Then it should be a Catalyst::Plugin imo.
>
> MyApp->plugin( 'myplugin', 'MyPlugin', [$c] );
Not possible, the context is instantiated for each request.
>
> I can retrieve the context object using C::P::Singleton but I'd
> rather not hardcode MyApp into a plugin. Another option may be to
> subsequently set the context like:
>
> $c->myplugin->context( $c );
>
> Is there a preferred way?
No.
--
sebastian
More information about the Catalyst
mailing list