sub begin :Private
{
- $DB::single = 1;
my ($self, $c) = @_;
Catalyst::Controller::DBIC::API::Request->meta->apply($c->req)
sub setup :Chained('specify.in.subclass.config') :CaptureArgs(0) :PathPart('specify.in.subclass.config')
{
- $DB::single = 1;
my ($self, $c) = @_;
$c->req->_set_current_result_set($self->stored_result_source->resultset);
unless(defined($vals))
{
# no data root, assume the request_data itself is the payload
- $vals = [$c->req->request_data || {}];
+ $vals = [$c->req->request_data];
}
elsif(reftype($vals) eq 'HASH')
{
sub deserialize :ActionClass('Deserialize')
{
- $DB::single = 1;
my ($self, $c) = @_;
my $req_params;
sub inflate_request
{
- $DB::single = 1;
my ($self, $c, $params) = @_;
try
List level action chained from L</setup>. List's steps are broken up into three distinct methods: L</list_munge_parameters>, L</list_perform_search>, and L</list_format_output>.
-The goal of this method is to call ->search() on the current_result_set, HashRefInflator the result, and return it in $c->stash->{response}->{$self->data_root}. Pleasee see the individual methods for more details on what actual processing takes place.
+The goal of this method is to call ->search() on the current_result_set, HashRefInflator the result, and return it in $c->stash->{response}->{$self->data_root}. Please see the individual methods for more details on what actual processing takes place.
If the L</select> config param is defined then the hashes will contain only those columns, otherwise all columns in the object will be returned. L</select> of course supports the function/procedure calling semantics that L<DBIx::Class::ResultSet/select>. In order to have proper column names in the result, provide arguments in L</as> (which also follows L<DBIx::Class::ResultSet/as> semantics. Similarly L</count>, L</page>, L</grouped_by> and L</ordered_by> affect the maximum number of rows returned as well as the ordering and grouping. Note that if select, count, ordered_by or grouped_by request parameters are present then these will override the values set on the class with select becoming bound by the select_exposes attribute.
sub list :Private
{
- $DB::single = 1;
my ($self, $c) = @_;
$self->list_munge_parameters($c);
sub list_perform_search
{
- $DB::single = 1;
my ($self, $c) = @_;
try
sub list_format_output
{
- $DB::single = 1;
my ($self, $c) = @_;
my $rs = $c->req->current_result_set->search;
foreach my $row ($rs->all)
{
- push(@$formatted, $self->row_format_output($row));
+ push(@$formatted, $self->row_format_output($c, $row));
}
$output->{$self->data_root} = $formatted;
=method_protected row_format_output
-row_format_output is called each row of the inflated output generated from the search. It receives only one argument, the hashref that represents the row. By default, this method is merely a passthrough.
+row_format_output is called each row of the inflated output generated from the search. It receives two arguments, the catalyst context and the hashref that represents the row. By default, this method is merely a passthrough.
=cut
-sub row_format_output { shift; shift; } # passthrough by default
+sub row_format_output
+{
+ my ($self, $c, $row) = @_;
+ return $row; # passthrough by default
+}
=method_protected update_or_create
sub update_or_create :Private
{
- $DB::single = 1;
my ($self, $c) = @_;
if($c->req->has_objects)
{
$self->validate_objects($c);
- $self->transact_objects($c, sub { $self->save_objects(@_) } );
+ $self->transact_objects($c, sub { $self->save_objects($c, @_) } );
}
else
{
sub transact_objects
{
- $DB::single = 1;
my ($self, $c, $coderef) = @_;
try
sub validate_objects
{
- $DB::single = 1;
my ($self, $c) = @_;
try
sub validate_object
{
- $DB::single = 1;
my ($self, $c, $obj) = @_;
my ($object, $params) = @$obj;
sub delete :Private
{
- $DB::single = 1;
my ($self, $c) = @_;
if($c->req->has_objects)
{
- $self->transact_objects($c, sub { $self->delete_objects(@_) });
+ $self->transact_objects($c, sub { $self->delete_objects($c, @_) });
$c->req->clear_objects;
}
else
sub save_objects
{
- my ($self, $objects) = @_;
+ my ($self, $c, $objects) = @_;
foreach my $obj (@$objects)
{
- $self->save_object($obj);
+ $self->save_object($c, $obj);
}
}
sub save_object
{
- my ($self, $obj) = @_;
+ my ($self, $c, $obj) = @_;
my ($object, $params) = @$obj;
if ($object->in_storage)
{
- $self->update_object_from_params($object, $params);
+ $self->update_object_from_params($c, $object, $params);
}
else
{
- $self->insert_object_from_params($object, $params);
+ $self->insert_object_from_params($c, $object, $params);
}
}
sub update_object_from_params
{
- my ($self, $object, $params) = @_;
+ my ($self, $c, $object, $params) = @_;
foreach my $key (keys %$params)
{
my $value = $params->{$key};
if (ref($value) && !($value == JSON::Any::true || $value == JSON::Any::false))
{
- $self->update_object_relation($object, delete $params->{$key}, $key);
+ $self->update_object_relation($c, $object, delete $params->{$key}, $key);
}
}
sub update_object_relation
{
- my ($self, $object, $related_params, $relation) = @_;
+ my ($self, $c, $object, $related_params, $relation) = @_;
my $row = $object->find_related($relation, {} , {});
$row->update($related_params);
}
sub insert_object_from_params
{
- my ($self, $object, $params) = @_;
+ my ($self, $c, $object, $params) = @_;
$object->set_columns($params);
$object->insert;
}
sub delete_objects
{
- my ($self, $objects) = @_;
+ my ($self, $c, $objects) = @_;
- map { $self->delete_object($_->[0]) } @$objects;
+ map { $self->delete_object($c, $_->[0]) } @$objects;
}
=method_protected delete_object
sub delete_object
{
- my ($self, $object) = @_;
+ my ($self, $c, $object) = @_;
$object->delete;
}
sub end :Private
{
- $DB::single = 1;
my ($self, $c) = @_;
# check for errors
}
elsif($self->return_object && $c->req->has_objects)
{
- $DB::single = 1;
my $returned_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];