Created
July 12, 2010 07:34
-
-
Save zakame/472218 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 Modern::Perl; | |
use Mojolicious::Lite; | |
get '/fizzbuzz/:number' => sub { | |
my $self = shift; | |
my $num = $self->param('number'); | |
my $out = []; | |
$self->render( text => "Not a Number!\n" ) | |
if $num !~ /^\d+$/; | |
for ( 1 .. $num ) { | |
when ( $_ % 3 == 0 && $_ % 5 == 0 ) { push @$out, "FizzBuzz" } | |
when ( $_ % 3 == 0 ) { push @$out, "Fizz" } | |
when ( $_ % 5 == 0 ) { push @$out, "Buzz" } | |
default { push @$out, $_ }; | |
} | |
$self->render_json($out); | |
}; | |
app->start; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment