[Catalyst] Plugin methods and context namespace
Christopher H. Laco
claco at chrislaco.com
Fri Nov 25 01:40:25 CET 2005
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Sebastian Riedel wrote:
>
> Am 25.11.2005 um 01:22 schrieb Christopher H. Laco:
>
>> -----BEGIN PGP SIGNED MESSAGE-----
>> Hash: SHA1
>>
>> Sebastian Riedel 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.
>>>>
>>>> I have this working by creating a package MyPlugin and a plugin
>>>> wrapper Catalyst::Plugin::MyPlugin. The wrapper just does a few
>>>> things:
>>>>
>>>> inherits from Class::Data::Inheritable
>>>> uses MyPlugin
>>>> adds 'myplugin' to classdata
>>>> sets $c->myplugin( MyPlugin->new( $c ) ) in prepare
>>>>
>>>> This works, but having an external MyPlugin.pm doesn't seem very
>>>> clean. Is there a better way to get plugin methods in the $c-
>>>>
>>>>> myplugin->foo format?
>>>
>>>
>>>
>>> MyApp->plugin( 'prototype', 'HTML::Prototype' );
>>>
>>> $c->prototype->define_javascript_functions;
>>>
>>
>> IS that only supported in MyApp.pm when the app loads, of can this be
>> called at anytime/module when the app is running?
>
>
> Anytime.
>
I'm assuming that without specifying a name space above, it would've
been $c->define_javascript_functions?
Awesome. I was thinking about loading an aliased copy of the form
validator plugin if it wasn't already within my controllers.
That goes a long was towards Just Works in terms of scaffolds without
having to mess with editing MyApp.pm to load a plugin. And since it's
aliased, it won't collide with other things.
- -=Chris
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.1 (GNU/Linux)
iD8DBQFDhl15+66dLHM50ssRAoADAKCeG3Ays4DZuRvkF73ULIr4qL0SzACdGfkh
GJXJn6qF98kPgVSs+zrVoCU=
=jLBl
-----END PGP SIGNATURE-----
More information about the Catalyst
mailing list