From: nperez Date: Mon, 8 Feb 2010 19:47:30 +0000 (-0600) Subject: Implement per object inflation hook in end X-Git-Tag: 2.001002~4 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=catagits%2FCatalyst-Controller-DBIC-API.git;a=commitdiff_plain;h=c9b8a7980c40fed5f81423f48a2c369f81348ce7 Implement per object inflation hook in end --- diff --git a/Changes b/Changes index 2fb2074..e4eef49 100644 --- a/Changes +++ b/Changes @@ -4,6 +4,7 @@ Revision history for Catalyst-Controller-DBIC-API: {{ $dist->version }} - Fixed missing requirement for MooseX::Types::Structured - Fixed MooseX::Aliases usage (we don't any more) +- Object inflation during end was broken out into its own method: each_object_inflate 2.001001 ************************************************************** diff --git a/lib/Catalyst/Controller/DBIC/API.pm b/lib/Catalyst/Controller/DBIC/API.pm index 7ae2bc3..561508a 100644 --- a/lib/Catalyst/Controller/DBIC/API.pm +++ b/lib/Catalyst/Controller/DBIC/API.pm @@ -715,7 +715,7 @@ sub end :Private { $DB::single = 1; my $returned_objects = []; - map {my %inflated = $_->[0]->get_inflated_columns; push(@$returned_objects, \%inflated) } $c->req->all_objects; + push(@$returned_objects, $self->each_object_inflate($c, $_)) for map { $_->[0] } $c->req->all_objects; $c->stash->{response}->{$self->data_root} = scalar(@$returned_objects) > 1 ? $returned_objects : $returned_objects->[0]; } @@ -723,12 +723,24 @@ sub end :Private $c->forward('serialize'); } -# from Catalyst::Action::Serialize -sub serialize :ActionClass('Serialize') { - my ($self, $c) = @_; +=method_protected each_object_inflate + +each_object_inflate executes during L and allows hooking into the process of inflating the objects to return in the response. Receives, the context, and the object as arguments. + +This only executes if L if set and if there are any objects to actually return. + +=cut + +sub each_object_inflate +{ + my ($self, $c, $object) = @_; + return { $object->get_inflated_columns }; } +# from Catalyst::Action::Serialize +sub serialize :ActionClass('Serialize') { } + =method_protected push_error push_error stores an error message into the stash to be later retrieved by L. Accepts a Dict[message => Str] parameter that defines the error message.