my $self = shift;
my ( $controller, $c, $test ) = @_;
- my $nreq = bless($c->request, 'Catalyst::Request::REST');
+ my $nreq = bless( $c->request, 'Catalyst::Request::REST' );
$c->request($nreq);
- unless(defined($self->plugins)) {
+ unless ( defined( $self->plugins ) ) {
my $mpo = Module::Pluggable::Object->new(
- 'require' => 1,
- 'search_path' => [ 'Catalyst::Action::Deserialize' ],
+ 'require' => 1,
+ 'search_path' => ['Catalyst::Action::Deserialize'],
);
my @plugins = $mpo->plugins;
- $self->plugins(\@plugins);
+ $self->plugins( \@plugins );
}
my $content_type = $c->request->content_type;
- my $sclass = 'Catalyst::Action::Deserialize::';
+ my $sclass = 'Catalyst::Action::Deserialize::';
my $sarg;
my $map = $controller->serialize->{'map'};
- if (exists($map->{$content_type})) {
+ if ( exists( $map->{$content_type} ) ) {
my $mc;
- if (ref($map->{$content_type}) eq "ARRAY") {
- $mc = $map->{$content_type}->[0];
+ if ( ref( $map->{$content_type} ) eq "ARRAY" ) {
+ $mc = $map->{$content_type}->[0];
$sarg = $map->{$content_type}->[1];
} else {
$mc = $map->{$content_type};
}
$sclass .= $mc;
- if (! grep(/^$sclass$/, @{$self->plugins})) {
+ if ( !grep( /^$sclass$/, @{ $self->plugins } ) ) {
die "Cannot find plugin $sclass for $content_type!";
}
} else {
- if (exists($controller->serialize->{'default'})) {
+ if ( exists( $controller->serialize->{'default'} ) ) {
$sclass .= $controller->serialize->{'default'};
} else {
die "I cannot find a default serializer!";
}
my @demethods = qw(POST PUT OPTIONS);
- my $method = $c->request->method;
- if (grep /^$method$/, @demethods) {
- if (defined($sarg)) {
- $sclass->execute($controller, $c, $sarg);
+ my $method = $c->request->method;
+ if ( grep /^$method$/, @demethods ) {
+ if ( defined($sarg) ) {
+ $sclass->execute( $controller, $c, $sarg );
} else {
- $sclass->execute($controller, $c);
+ $sclass->execute( $controller, $c );
}
$self->NEXT::execute( @_, );
} else {
- $self->NEXT::execute( @_ );
+ $self->NEXT::execute(@_);
}
-};
+}
1;
sub execute {
my $self = shift;
my ( $controller, $c, $serializer ) = @_;
-
+
my $body = $c->request->body;
if ($body) {
my $rbody;
- if (-f $c->request->body) {
- open(BODY, "<", $c->request->body);
- while (my $line = <BODY>) {
+ if ( -f $c->request->body ) {
+ open( BODY, "<", $c->request->body );
+ while ( my $line = <BODY> ) {
$rbody .= $line;
}
close(BODY);
}
- my $dso = Data::Serializer->new(serializer => $serializer);
- my $rdata = $dso->raw_deserialize($rbody);
+ my $dso = Data::Serializer->new( serializer => $serializer );
+ my $rdata = $dso->raw_deserialize($rbody);
$c->request->data($rdata);
} else {
- $c->log->debug('I would have deserialized, but there was nothing in the body!');
+ $c->log->debug(
+ 'I would have deserialized, but there was nothing in the body!');
}
-};
+}
1;
sub execute {
my $self = shift;
my ( $controller, $c, $test ) = @_;
-
+
my $body = $c->request->body;
if ($body) {
- my $rdata = LoadFile($c->request->body);
+ my $rdata = LoadFile( $c->request->body );
$c->request->data($rdata);
} else {
- $c->log->debug('I would have deserialized, but there was nothing in the body!');
+ $c->log->debug(
+ 'I would have deserialized, but there was nothing in the body!');
}
-};
+}
1;
my ( $self, $c ) = @_;
my $controller = $self->class;
- my $method = $self->name . "_" . uc($c->request->method);
- if ($controller->can($method)) {
+ my $method = $self->name . "_" . uc( $c->request->method );
+ if ( $controller->can($method) ) {
return $controller->$method($c);
} else {
$self->_return_405($c);
my ( $self, $c ) = @_;
my $controller = $self->class;
- my $methods = Class::Inspector->methods($controller);
+ my $methods = Class::Inspector->methods($controller);
my @allowed;
- foreach my $method (@{$methods}) {
+ foreach my $method ( @{$methods} ) {
my $name = $self->name;
- if ($method =~ /^$name\_(.+)$/) {
- push(@allowed, $1);
+ if ( $method =~ /^$name\_(.+)$/ ) {
+ push( @allowed, $1 );
}
}
$c->response->content_type('text/plain');
$c->response->status(405);
- $c->response->header('Allow' => \@allowed);
- $c->response->body("Method " . $c->request->method . " not implemented for " . $c->uri_for($self->reverse));
+ $c->response->header( 'Allow' => \@allowed );
+ $c->response->body( "Method "
+ . $c->request->method
+ . " not implemented for "
+ . $c->uri_for( $self->reverse ) );
}
1;
return 1 if $c->response->status =~ /^(?:204|3\d\d)$/;
# Load the Serialize Classes
- unless(defined($self->plugins)) {
+ unless ( defined( $self->plugins ) ) {
my $mpo = Module::Pluggable::Object->new(
- 'require' => 1,
- 'search_path' => [ 'Catalyst::Action::Serialize' ],
+ 'require' => 1,
+ 'search_path' => ['Catalyst::Action::Serialize'],
);
my @plugins = $mpo->plugins;
- $self->plugins(\@plugins);
+ $self->plugins( \@plugins );
}
# Look up what serializer to use from content_type map
- #
+ #
# If we don't find one, we use the default
my $content_type = $c->request->content_type;
- my $sclass = 'Catalyst::Action::Serialize::';
+ my $sclass = 'Catalyst::Action::Serialize::';
my $sarg;
my $map = $controller->serialize->{'map'};
- if (exists($map->{$content_type})) {
+ if ( exists( $map->{$content_type} ) ) {
my $mc;
- if (ref($map->{$content_type}) eq "ARRAY") {
- $mc = $map->{$content_type}->[0];
+ if ( ref( $map->{$content_type} ) eq "ARRAY" ) {
+ $mc = $map->{$content_type}->[0];
$sarg = $map->{$content_type}->[1];
} else {
$mc = $map->{$content_type};
}
$sclass .= $mc;
- if (! grep(/^$sclass$/, @{$self->plugins})) {
+ if ( !grep( /^$sclass$/, @{ $self->plugins } ) ) {
die "Cannot find plugin $sclass for $content_type!";
}
} else {
- if (exists($controller->serialize->{'default'})) {
+ if ( exists( $controller->serialize->{'default'} ) ) {
$sclass .= $controller->serialize->{'default'};
} else {
die "I cannot find a default serializer!";
}
# Go ahead and serialize ourselves
- if (defined($sarg)) {
- $sclass->execute($controller, $c, $sarg);
+ if ( defined($sarg) ) {
+ $sclass->execute( $controller, $c, $sarg );
} else {
- $sclass->execute($controller, $c);
+ $sclass->execute( $controller, $c );
}
- if (! $c->response->content_type ) {
- $c->response->content_type($c->request->content_type);
+ if ( !$c->response->content_type ) {
+ $c->response->content_type( $c->request->content_type );
}
return 1;
-};
+}
1;
my ( $controller, $c, $serializer ) = @_;
my $stash_key = $controller->serialize->{'stash_key'} || 'rest';
- my $dso = Data::Serializer->new(serializer => $serializer);
+ my $dso = Data::Serializer->new( serializer => $serializer );
$c->response->output( $dso->raw_serialize( $c->stash->{$stash_key} ) );
return 1;
-};
+}
1;
my $stash_key = $controller->serialize->{'stash_key'} || 'rest';
$c->response->output( Dump( $c->stash->{$stash_key} ) );
return 1;
-};
+}
1;
__PACKAGE__->config(
serialize => {
- 'default' => 'YAML',
+ 'default' => 'YAML',
'stash_key' => 'rest',
- 'map' => {
- 'text/x-yaml' => 'YAML',
+ 'map' => {
+ 'text/x-yaml' => 'YAML',
'text/x-data-dumper' => [ 'Data::Serializer', 'Data::Dumper' ],
},
}
);
-sub begin :ActionClass('Deserialize') {}
+sub begin : ActionClass('Deserialize') {
+}
-sub end :ActionClass('Serialize') {}
+sub end : ActionClass('Serialize') {
+}
1;