Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

new resource functionality. #11

wants to merge 21 commits into


None yet
1 participant

mattp- commented Apr 5, 2012

I mentioned on irc I was going to introduce Lingua::Inflect as a hard dependency, but I later changed my mind. As is, this is 110% backward compatible. Check out the pod for details.


mattp- added some commits Mar 22, 2012

Changes get to read, providing backcompat alias
Also provides a default 405 method not allowed route for unimplemented
Adds optional Inflection dependency
When :inflect is passed in as import tag, the resource noun if plural is
converted to singular using Lingua::EN::Inflect::Phrase. This overrides
default :id parameter, changing it to ${singular}_id. Useful for nested
Change to Lingua::EN::Inflect::Number
Phrase is overkill for this usage.
New functionality, bare resource => 'foo'; declaration
Allow rails style declaration of resource => 'foo';
When this is done, the callers namespace is checked for existing methods
of the form ${verb}_${resource}. This is an amalgamation of Rails style
resource declaration with Catalyst::Action::REST method dispatch.
Add Member and Collection subroute handling
Similar to rails definitions now, combined
with earlier Catalyst::Action::REST style dispatching:

resource 'users',
    read => sub { ... }, # optional
    member => {
        profile => 'read',
        bar => [qw/read put/],
    collection => {
        posts => [qw/read delete/],

In callers namespace:
read_user_profile()  => GET /users/:id/profile
read_users_posts()   => GET /users/posts
delete_users_posts() => DELETE /users/posts
Changed member/collection API, now created via ref
resource 'users', member => ['foo'];
will now create /users/:id/foo (attaching to get/put/post/delete like
root resource currently behaves. Will install 405 not allowed routes for
missing functions.
Adds new functionality (thanks mst)
New keyword, 'parent', can be passed to resource. When a resource is
declared its prefix and route are saved. If a future resource is
declared that sets parent to an existing resource, that prefix is
recalled and set. This allows for nested resources across package

Added two new keywords, load and load_all. If these are coderefs, they
can be used to populate each defined route handler with the given
resource. For example, index GET is passed 'load_all's arguments.
Could be used to either set vars, or pass args directly to the route.

new keyword, 'params', can be ArrayRef[Str]. If passed in, will override
inflected param based off of resource name. For example,
resource 'users',
    params => [qw/foo bar/];

will create /users/:foo/:bar instead of /users/:user_id. Useful for
composite key definition.

Tests for new functionality forthcoming
Reorganization of inflection code
If :inflect tag is no longer passed to module on import, the module 100%
degrades to previous version functionality. New code should now have
perfect back compatibility.

@mattp- mattp- closed this May 4, 2012

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment