[Catalyst] Converting a GET request to a POST request

Ronald J Kimball rkimball at pangeamedia.com
Tue Nov 23 16:22:14 GMT 2010


On Mon, Nov 22, 2010 at 7:33 PM, Tomas Doran <bobtfish at bobtfish.net> wrote:
>
> On 22 Nov 2010, at 18:28, Ronald J Kimball wrote:
>>
>> It doesn't care what the request method is, as long as it's POST, PUT,
>> OPTIONS, or DELETE.  ;)
>
> No, it just doesn't care.
>
>> If I create Catalyst::Action::Deserialize::JSONP, I'll still need to
>> convert the GET request to a POST.  That seems to be the really tricky
>> part.
>
> Why? Where is the code which forces it to be a POST?

In Catalyst::Action::Deserialize:

sub execute {
    my $self = shift;
    my ( $controller, $c ) = @_;

    my @demethods = qw(POST PUT OPTIONS DELETE);
    my $method    = $c->request->method;
    if ( grep /^$method$/, @demethods ) {
        my ( $sclass, $sarg, $content_type ) =
          $self->_load_content_plugins( 'Catalyst::Action::Deserialize',
            $controller, $c );
        return 1 unless defined($sclass);
        my $rc;
        if ( defined($sarg) ) {
            $rc = $sclass->execute( $controller, $c, $sarg );
        } else {
            $rc = $sclass->execute( $controller, $c );
        }
        if ( $rc eq "0" ) {
            return $self->_unsupported_media_type( $c, $content_type );
        } elsif ( $rc ne "1" ) {
            return $self->_serialize_bad_request( $c, $content_type, $rc );
        }
    }

    $self->maybe::next::method(@_);

    return 1;
}


Ronald



More information about the Catalyst mailing list