File: simple_calculator.psgi

package info (click to toggle)
libdancer2-perl 0.207000%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 2,460 kB
  • sloc: perl: 8,069; makefile: 7
file content (36 lines) | stat: -rw-r--r-- 772 bytes parent folder | download | duplicates (4)
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;