CatalystX::CRUD::Controller::REST - Catalyst::Controller::REST with CRUD
package MyApp::Controller::Foo; use Moose; use namespace::autoclean; BEGIN { extends 'CatalystX::CRUD::Controller::REST' } __PACKAGE__->config( model_name => 'Foo', primary_key => 'id', page_size => 50, ); 1; # now you can manage Foo objects with URIs like: # POST /foo -> create new Foo record # GET /foo -> list all Foo records # PUT /foo/<pk> -> create or update Foo record (idempotent) # DELETE /foo/<pk> -> delete Foo record # GET /foo/<pk> -> view Foo record # GET /foo/<pk>/bar -> view Bar object(s) related to Foo # POST /foo/<pk>/bar -> create Bar object related to Foo # GET /foo/<pk>/bar/<pk2> -> view Bar with id <pk2> related to Foo with <pk> # POST /foo/<pk>/bar/<pk2> -> create relationship between Foo <pk> and Bar <pk2> # DELETE /foo/<pk>/bar/<pk2> -> sever Bar object relationship to Foo # PUT /foo/<pk>/bar/<pk2> -> create/update Bar object related to Foo (idempotent) # GET /foo/search -> search for Foo objects # GET /foo/count -> search for Foo objects, returning count only
Subclass of Catalyst::Controller::REST for use with CatalystX::CRUD.
This module is not to be confused with CatalystX::CRUD::REST. This is not a drop-in replacement for existing CatalystX::CRUD::Controllers.
This module extends Catalyst::Controller::REST to work with the CatalystX::CRUD::Controller API. It is designed for web services, not managing CRUD actions via HTML forms.
This is not a subclass of CatalystX::CRUD::Controller.
Registers URL space for search.
Query the model and return results. See do_search().
Registers URL space for count.
Like search_objects_GET() but does not set result values, only a total count. Useful for AJAX-y types of situations where you want to query for a total number of matches and create a pager but not actually retrieve any data.
Registers URL space for 0 path arguments.
GET /foo -> list objects of type foo.
Calls do_search().
POST /foo -> create object of type foo.
Registers URL space for 1 path argument.
GET /foo/<pk> -> retrieve object for pk.
PUT /foo/<pk> -> create or update the object for pk.
This method must be idempotent. POST is not.
DELETE /foo/<pk> -> delete the object for pk.
Registers URL space for 2 path arguments.
GET /foo/<pk>/bar -> a list of objects of type bar related to foo.
POST /foo/<pk>/bar -> create relationship between foo and bar.
TODO This method calls a not-yet-implemented create_related() action in the CXC::Model.
Registers the URL space for 3 path arguments.
GET /foo/<pk>/<re>/<pk2>
DELETE /foo/<pk>/bar/<pk2> -> sever 'bar' object relationship to 'foo'
POST /foo/<pk>/bar/<pk2> -> create relationship between 'foo' and 'bar'
PUT /foo/<pk>/bar/<pk2> -> create/update 'bar' object related to 'foo'
Calls can_write(), inflate_object(), precommit(), create_or_update_object() and postcommit().
Calls the update() or create() method on the object (or model_adapter()), picking the method based on whether object_id in stash() evaluates true (update) or false (create).
object_id
Checks can_write(), precommit(), and if both true, calls the delete() method on the object in the stash().
Returns the object from stash() initialized with the request data.
Returns true if the current request is authorized to read() the object in stash().
object
Default is true.
Returns true if the current request is authorized to create() or update() the object in stash().
Called by save_object(). If precommit() returns a false value, save_object() is aborted. If precommit() returns a true value, create_or_update_object() gets called.
The default return is true.
Called internally inside save_object(). Our default just returns true. Override this method to post-process a successful save_object() action.
Determines the correct value and field name for pk and calls the do_model() method for fetch.
fetch
On success, the object key will be set in stash().
On failure, calls status_not_found() and sets the fetch_failed stash() key.
Prepare and execute a search. Called internally by list() and search().
Results are saved in stash() under the results key.
results
If naked_results is true, then results are set just as they are returned from search() or list() (directly from the Model).
If naked_results is false (default), then results is a CatalystX::CRUD::Results object.
Wrapper around the ControllerRole method of the same name. The wrapper does an eval and sets the ctx error param with $@.
Peter Karman, <karman at cpan.org>
<karman at cpan.org>
Please report any bugs or feature requests to bug-catalystx-crud-controller-rest at rt.cpan.org, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=CatalystX-CRUD-Controller-REST. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.
bug-catalystx-crud-controller-rest at rt.cpan.org
You can find documentation for this module with the perldoc command.
perldoc CatalystX::CRUD::Controller::REST
You can also look for information at:
Mailing List
https://groups.google.com/forum/#!forum/catalystxcrud
RT: CPAN's request tracker
http://rt.cpan.org/NoAuth/Bugs.html?Dist=CatalystX-CRUD-Controller-REST
AnnoCPAN: Annotated CPAN documentation
http://annocpan.org/dist/CatalystX-CRUD-Controller-REST
CPAN Ratings
http://cpanratings.perl.org/d/CatalystX-CRUD-Controller-REST
Search CPAN
http://search.cpan.org/dist/CatalystX-CRUD-Controller-REST/
Copyright 2012 Peter Karman.
This program is free software; you can redistribute it and/or modify it under the terms of either: the GNU General Public License as published by the Free Software Foundation; or the Artistic License.
See http://dev.perl.org/licenses/ for more information.
To install CatalystX::CRUD::Controller::REST, copy and paste the appropriate command in to your terminal.
cpanm
cpanm CatalystX::CRUD::Controller::REST
CPAN shell
perl -MCPAN -e shell install CatalystX::CRUD::Controller::REST
For more information on module installation, please visit the detailed CPAN module installation guide.