[Catalyst] RFC: Catalyst::Plugin::SpecialAction::Trail

Tomas Doran bobtfish at bobtfish.net
Wed Jun 1 20:34:25 GMT 2011


On 1 Jun 2011, at 19:35, BUCHMULLER Norbert wrote:
> Comments welcome.

Monkey patching Catalyst::Controller is a horrible horrible horrible  
idea, please don't do that!

If (for example) one were to load two Catalyst apps at once (e.g.  
FCGI::Engine running multiple apps, or one mod_perl instance with two  
apps), then this would result in both applications getting the  
behavior, which I'm quite sure is not what you intended.

If you really need to do this, then apply the roles to the controller  
_instances_ after they have been initialized.

E.g.

around setup_component => sub {
     my ($orig, $self, @args) = @_;
     my $instance = $self->$orig(@args);
     Moose::Util::apply_all_roles($instance, 'My::Role');
     return $instance;
};

This will only affect the application you load it into, rather than  
all Catalyst applications sharing that memory space.

Cheers
t0m



More information about the Catalyst mailing list