[Catalyst] Mapping parameters for web services

Bill Moseley moseley at hank.org
Wed Oct 24 20:52:21 GMT 2007

On Wed, Oct 24, 2007 at 07:10:09PM +0100, Matt S Trout wrote:
> > The C::P::Server::XMLRPC plugin allows adding attributes to existing
> > controllers, so you can do:
> > 
> >     sub user_detail : Local : XMLRPC {
> >         my ( $self, $c, $user_id ) = @_;
> > 
> >         # validate user_id and place user object in stash.
> > 
> >     }
> Yes, and I'm saying that that's cute and all, but don't do that.

Why don't you like that?

> If you want to share controller code, use a common base class.

Ok, but In which way?

So, there's a bunch of existing actions spread around a handful of
controllers.  Now you want to add in XMLRCP where each request must
alter in the input parameters to use the existing controller code.

Do you create new controller classes just for the XMLRPC requests
where they rearrange the parameters and then call the web controller

Or do you factor out the common code into a base class for each
controller and then have web and XMLRPC (and what ever else comes
along) to handle those requests?

    package App::Controller::User;
    use Base 'App::Contoller::User::Base';

    sub user_detail : Local {
        my ( $self, $c, $user_id ) = @_;
        return $self->fetch_user_detail( $c, $user_id );

    package App::Controller::XMLRPC::User;
    use Base 'App::Contoller::User::Base';

    sub user_detail : XMLRPC {
        my ( $self, $c ) = @_;
        my $user_id = $c->req->params->{user_id};
        return $self->fetch_user_detail( $c, $user_id );

Or are you thinking of something else?

Bill Moseley
moseley at hank.org

More information about the Catalyst mailing list