Created
June 25, 2012 21:27
-
-
Save diegok/2991364 to your computer and use it in GitHub Desktop.
render_exeption() and render_not_found() example.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env perl | |
use Mojolicious::Lite; | |
get '/divide/:dividend/by/:divisor' => sub { | |
my $self = shift; | |
my $dividend = $self->param('dividend'); | |
my $divisor = $self->param('divisor'); | |
return $self->render_not_found | |
unless $dividend =~ /^\d+$/ && $divisor =~ /^\d+$/; | |
return $self->render_exception('Divide by zero') if $divisor == 0; | |
$self->render_text( $dividend / $divisor ); | |
}; | |
app->start; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment