X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=catagits%2FCatalyst-Controller-DBIC-API.git;a=blobdiff_plain;f=lib%2FCatalyst%2FController%2FDBIC%2FAPI.pm;h=7db1d8cb8e73fd7f56f9063c2629f484493a84c8;hp=568b7fbb8993dbeb580cfaad20d32348bd866959;hb=26e9dcd6d31111877fd0b97f5c6743fab226e015;hpb=e2f6c772e3ab169b87b44d7834c35e4449bb534c diff --git a/lib/Catalyst/Controller/DBIC/API.pm b/lib/Catalyst/Controller/DBIC/API.pm index 568b7fb..7db1d8c 100644 --- a/lib/Catalyst/Controller/DBIC/API.pm +++ b/lib/Catalyst/Controller/DBIC/API.pm @@ -2,7 +2,7 @@ package Catalyst::Controller::DBIC::API; #ABSTRACT: Provides a DBIx::Class web service automagically use Moose; -BEGIN { extends 'Catalyst::Controller::ActionRole'; } +BEGIN { extends 'Catalyst::Controller'; } use CGI::Expand (); use DBIx::Class::ResultClass::HashRefInflator; @@ -27,8 +27,9 @@ sub _build__json { } with 'Catalyst::Controller::DBIC::API::StoredResultSource', - 'Catalyst::Controller::DBIC::API::StaticArguments', - 'Catalyst::Controller::DBIC::API::RequestArguments' => { static => 1 }; + 'Catalyst::Controller::DBIC::API::StaticArguments'; + +with 'Catalyst::Controller::DBIC::API::RequestArguments' => { static => 1 }; __PACKAGE__->config(); @@ -41,7 +42,7 @@ __PACKAGE__->config(); __PACKAGE__->config ( action => { setup => { PathPart => 'artist', Chained => '/api/rpc/rpc_base' } }, # define parent chain action and partpath class => 'MyAppDB::Artist', - result_class => 'MyAppDB::ResultSet::Artist', + resultset_class => 'MyAppDB::ResultSet::Artist', create_requires => ['name', 'age'], create_allows => ['nickname'], update_allows => ['name', 'age', 'nickname'], @@ -80,8 +81,7 @@ sub begin :Private { my ($self, $c) = @_; - Catalyst::Controller::DBIC::API::Request->meta->apply($c->req) - unless Moose::Util::does_role($c->req, 'Catalyst::Controller::DBIC::API::Request'); + Moose::Util::ensure_all_roles($c->req, 'Catalyst::Controller::DBIC::API::Request'); } =method_protected setup @@ -190,16 +190,19 @@ sub deserialize :Chained('setup') :CaptureArgs(0) :PathPart('') :ActionClass('De =method_protected generate_rs -generate_rs is used by inflate_request to generate the resultset stored in the current request. It receives $c as its only argument. And by default it merely returns the resultset from the stored_result_source on the controller. Override this method if you need to manipulate the default implementation of getting the resultset from the controller. +generate_rs is used by inflate_request to get a resultset for the current +request. It receives $c as its only argument. +By default it returns a resultset of the controller's class. +Override this method if you need to manipulate the default implementation of +getting a resultset. =cut sub generate_rs { - #my ($self, $c) = @_; - my ($self) = @_; + my ($self, $c) = @_; - return $self->stored_result_source->resultset; + return $c->model($self->class); } =method_protected inflate_request @@ -814,12 +817,18 @@ sub insert_object_from_params my ($self, undef, $object, $params) = @_; my %rels; - while (my ($k, $v) = each %{ $params }) { - if (ref($v) && !(reftype($v) eq reftype(JSON::true))) { - $rels{$k} = $v; + while (my ($key, $value) = each %{ $params }) { + if (ref($value) && !(reftype($value) eq reftype(JSON::true))) { + $rels{$key} = $value; } + # accessor = colname + elsif ($object->can($key)) { + $object->$key($value); + } + # accessor != colname else { - $object->set_column($k => $v); + my $accessor = $object->result_source->column_info($key)->{accessor}; + $object->$accessor($value); } }