[Catalyst-commits] r14391 -
CatalystX-CRUD/CatalystX-CRUD-Controller-REST/trunk/lib/CatalystX/CRUD/Controller
karpet at dev.catalyst.perl.org
karpet at dev.catalyst.perl.org
Mon Nov 5 16:43:17 GMT 2012
Author: karpet
Date: 2012-11-05 16:43:17 +0000 (Mon, 05 Nov 2012)
New Revision: 14391
Modified:
CatalystX-CRUD/CatalystX-CRUD-Controller-REST/trunk/lib/CatalystX/CRUD/Controller/REST.pm
Log:
lots of perltidy noise, but significantly, fetch() no longer conflaits has_errors() with !stash->{object}
Modified: CatalystX-CRUD/CatalystX-CRUD-Controller-REST/trunk/lib/CatalystX/CRUD/Controller/REST.pm
===================================================================
--- CatalystX-CRUD/CatalystX-CRUD-Controller-REST/trunk/lib/CatalystX/CRUD/Controller/REST.pm 2012-11-05 14:45:40 UTC (rev 14390)
+++ CatalystX-CRUD/CatalystX-CRUD-Controller-REST/trunk/lib/CatalystX/CRUD/Controller/REST.pm 2012-11-05 16:43:17 UTC (rev 14391)
@@ -88,7 +88,8 @@
=cut
-sub search_objects : Path('search') : Args(0) : ActionClass('REST') { }
+sub search_objects : Path('search') : Args(0) : ActionClass('REST') {
+}
=head2 search_objects_GET
@@ -114,7 +115,8 @@
=cut
-sub count_objects : Path('count') : Args(0) : ActionClass('REST') { }
+sub count_objects : Path('count') : Args(0) : ActionClass('REST') {
+}
=head2 count_objects_GET
@@ -146,7 +148,8 @@
=cut
-sub zero_args : Path('') : Args(0) : ActionClass('REST') { }
+sub zero_args : Path('') : Args(0) : ActionClass('REST') {
+}
=head2 zero_args_GET( I<ctx> )
@@ -186,6 +189,7 @@
);
}
else {
+
# TODO msg
$self->status_bad_request( $c, message => 'Failed to create' );
}
@@ -250,6 +254,7 @@
}
}
else {
+
# TODO msg
$self->status_bad_request( $c, message => 'Failed to update' );
}
@@ -274,6 +279,7 @@
$self->status_no_content($c);
}
else {
+
# TODO msg
$self->status_bad_request( $c, message => 'Failed to delete' );
}
@@ -301,8 +307,8 @@
my ( $self, $c, $id, $rel ) = @_;
return if $c->stash->{fetch_failed};
my $results
- = $self->do_model( $c, 'iterator_related', $c->stash->{object},
- $rel, );
+ = $self->do_model( $c, 'iterator_related', $c->stash->{object}, $rel,
+ );
if ( $self->has_errors($c) ) {
my $err = $c->error->[0];
if ( $err =~ m/^(unsupported relationship name: (\S+))/i ) {
@@ -349,6 +355,7 @@
);
}
else {
+
# TODO msg
$self->status_bad_request( $c, message => 'Failed to delete' );
}
@@ -377,13 +384,15 @@
sub three_args_GET {
my ( $self, $c, $id, $rel, $rel_id ) = @_;
return if $c->stash->{fetch_failed};
- my $result = $self->do_model( $c, 'find_related', $c->stash->{object},
- $rel, $rel_id, );
+ my $result
+ = $self->do_model( $c, 'find_related', $c->stash->{object}, $rel,
+ $rel_id, );
if ( !$result or ( ref $result eq 'ARRAY' and !@$result ) ) {
my $err_msg = sprintf( "No such %s with id '%s'", $rel, $rel_id );
$self->status_not_found( $c, message => $err_msg );
}
else {
+
# coerce $result into an array ref for consistency
if ( ref $result ne 'ARRAY' ) {
$result = [$result];
@@ -411,12 +420,13 @@
return;
}
- my $rt = $self->do_model( $c, 'rm_related', $c->stash->{object},
- $rel, $rel_id, );
+ my $rt = $self->do_model( $c, 'rm_related', $c->stash->{object}, $rel,
+ $rel_id, );
if ($rt) {
$self->status_no_content($c);
}
else {
+
# TODO msg
$self->status_bad_request( $c,
message => 'Failed to remove relationship' );
@@ -432,12 +442,13 @@
sub three_args_POST {
my ( $self, $c, $id, $rel, $rel_id ) = @_;
return if $c->stash->{fetch_failed};
- my $rt = $self->do_model( $c, 'add_related', $c->stash->{object},
- $rel, $rel_id, );
+ my $rt = $self->do_model( $c, 'add_related', $c->stash->{object}, $rel,
+ $rel_id, );
if ($rt) {
$self->status_no_content($c);
}
else {
+
# TODO msg
$self->status_bad_request( $c,
message => 'Failed to create relationship' );
@@ -453,13 +464,14 @@
sub three_args_PUT {
my ( $self, $c, $id, $rel, $rel_id ) = @_;
return if $c->stash->{fetch_failed};
- my $rt = $self->do_model( $c, 'put_related', $c->stash->{object},
- $rel, $rel_id, );
+ my $rt = $self->do_model( $c, 'put_related', $c->stash->{object}, $rel,
+ $rel_id, );
if ($rt) {
$self->status_no_content($c);
}
else {
+
# TODO msg
$self->status_bad_request( $c,
message => 'Failed to PUT relationship' );
@@ -659,14 +671,18 @@
my @arg = ( defined $pk_is_null || !$id ) ? () : (@pk);
$c->log->debug( "fetch: " . dump \@arg ) if $c->debug;
$c->stash->{object} = $self->do_model( $c, 'fetch', @arg );
- if ( $self->has_errors($c) or !$c->stash->{object} ) {
+ if ( !$c->stash->{object} ) {
my $err_msg
= sprintf( "No such %s with id '%s'", $self->model_name, $id );
$self->status_not_found( $c, message => $err_msg );
$c->log->error($err_msg);
$c->stash( fetch_failed => 1 );
+ $c->clear_errors;
return 0;
}
+ if ( $self->has_errors($c) ) {
+ $c->log->debug("errors in fetch") if $c->debug;
+ }
return $c->stash->{object};
}
More information about the Catalyst-commits
mailing list