1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
|
use Dancer2;
get '/' => sub {
return q{Welcome to simple calculator, powered by Dancer2.
<a href="/add/2/3">add 2 + 3</a>
<a href="/multiply?x=2&y=3">multiply</a>
<form method="POST" action="/division">
<input name="x"><input name="y">
<input type="submit" value="Division">
</form>
};
};
get '/add/:x/:y' => sub {
my $x = route_parameters->{'x'};
my $y = route_parameters->{'y'};
return ($x+$y);
};
get '/multiply' => sub {
my $x = query_parameters->{'x'};
my $y = query_parameters->{'y'};
return ($x*$y);
};
post '/division' => sub {
my $x = body_parameters->{'x'};
my $y = body_parameters->{'y'};
return int($x/$y);
};
__PACKAGE__->to_app;
|