Login | Register For Free | Help
Search for: (Advanced)

Mailing List Archive: Catalyst: Users

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

 

 

Catalyst users RSS feed   Index | Next | Previous | View Threaded


melo at simplicidade

Aug 21, 2009, 3:37 AM

Post #1 of 3 (397 views)
Permalink
Advice needed on porting 5.7 plugin (monkeypatches Cat::Request)

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,

_______________________________________________
List: Catalyst[at]lists.scsys.co.uk
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst[at]lists.scsys.co.uk/
Dev site: http://dev.catalyst.perl.org/


rafl at debian

Aug 21, 2009, 4:10 AM

Post #2 of 3 (365 views)
Permalink
Re: Advice needed on porting 5.7 plugin (monkeypatches Cat::Request) [In reply to]

On Fri, Aug 21, 2009 at 11:37:00AM +0100, Pedro Melo wrote:
> 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:

It's probably better to create a role to apply to the request class and,
optionally, use CatalystX::RoleApplicator to apply it.

See Catalyst::TraitFor::Request::BrowserDetect for an example.

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

Yes. See Catalyst::Plugin::Browser for that.

> * is there a better way?

Other than not doing it and using CX::RoleApplicator instead? None that
i've found so far.


--
BOFH excuse #383:
Your processor has taken a ride to Heaven's Gate on the UFO behind
Hale-Bopp's comet.
Attachments: signature.asc (0.18 KB)


bobtfish at bobtfish

Aug 21, 2009, 9:26 AM

Post #3 of 3 (362 views)
Permalink
Re: Advice needed on porting 5.7 plugin (monkeypatches Cat::Request) [In reply to]

Pedro Melo wrote:
> * is it possible for a plugin, at setup time, to set the request_class()?

Yes.

before setup_finalize => sub { my $self = shift;
$self->request_class("New::Request::Class"); };

> * is there a better way?

Yes. Make a request class role, then use CatalystX::RoleApplicator
to apply it to the request class.

See Catalyst::Plugin::Browser for an example of it being used in a plugin.

Cheers
t0m

_______________________________________________
List: Catalyst[at]lists.scsys.co.uk
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst[at]lists.scsys.co.uk/
Dev site: http://dev.catalyst.perl.org/

Catalyst users RSS feed   Index | Next | Previous | View Threaded
 
 


Interested in having your list archived? Contact lists@gossamer-threads.com
 
  Web Applications & Managed Hosting Powered by Gossamer Threads Inc.