Skip to content

Instantly share code, notes, and snippets.

Created August 20, 2012 23:56
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 anonymous/3409425 to your computer and use it in GitHub Desktop.
Save anonymous/3409425 to your computer and use it in GitHub Desktop.
package API;
use Mojo::Base 'Mojolicious';
sub startup {
my $self = shift;
$self->helper( has_permission => \&authorize );
$self->routes
->bridge->to( cb => sub { $self->has_permission('admin') } )
->get('/resource')->to( cb => \&search );
}
sub search {
my $self = shift;
$self->render( json => 'search' );
}
sub authorize {
my $self = shift;
return 1 if int( rand() * 10 ) < 6;
warn "access denied\n";
$self->render(text => 'You don\'t have access');
return;
}
1;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment