[Catalyst] Advice needed on porting 5.7 plugin (monkeypatches Cat::Request)

Pedro Melo melo at simplicidade.org
Fri Aug 21 10:37:00 GMT 2009


Hi,

I need some advice about an old 5.7 plugin that I came across at a  
client site. The plugin wraps CGI::Expand to deal with hierarchical  
parameters (see expand_cgi export in CGI::Expand docs).

They want to migrate the app to 5.8 and this plugin was doing some  
nasty stuff - monkeypatching Catalyst::Request like this:

     package Catalyst::Request;
     __PACKAGE__->mk_accessors('hparams');

This is of course a no-no with CatMoose.

Reading through the docs, I see that I can subclass the  
Catalyst::Request class and use the $c->request_class to setup the new  
one. I've done that like this:

package My::Request;

use Moose;

BEGIN { extends 'Catalyst::Request' }

has hparams => (
	isa => 'HashRef',
	is  => 'rw',	
	default =>  sub { {} },
);

no Moose;
__PACKAGE__->meta->make_immutable;

1;

I have two questions:

  * is it possible for a plugin, at setup time, to set the  
request_class()?
  * is there a better way?

Best regards,



More information about the Catalyst mailing list