Skip to content

Instantly share code, notes, and snippets.

@yko

yko/keywords.pl Secret

Created January 28, 2011 12:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yko/8160dba7492bd018fbcb to your computer and use it in GitHub Desktop.
Save yko/8160dba7492bd018fbcb to your computer and use it in GitHub Desktop.
# Simple "resource" keyword
$r->add_keyword(resource => sub {
my ($r, $name) = @_;
# Generate "/$name" route
my $resource = $r->route("/$name")->to("$name#");
# Handle POST requests
$resource->bridge->to(cb => sub { shift->can_i_haz })
->post->to('#create')->name("create_$name");
# Handle GET requests
$resource->get->to('#show')->name("show_$name");
return $resource;
});
# POST /user -> {controller => 'user', action => 'create'}
# GET /user -> {controller => 'user', action => 'show'}
$r->resource('user');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment