forked from PerlDancer/Dancer
/
webapp.pm
74 lines (58 loc) · 1.31 KB
/
webapp.pm
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
package webapp;
use Dancer;
use Template;
set apphandler => 'PSGI';
before sub {
var note => "I ARE IN TEH BEFOR FILTERZ";
debug "in the before filter";
};
get '/foo/*' => sub {
my ($match) = splat; # ('bar/baz')
debug "je suis dans /foo";
use Data::Dumper;
"note: '".vars->{note}."'\n".
"match: $match\n".
"request: ".Dumper(request);
};
# for testing Perl errors
get '/error' => sub {
template();
};
get '/' => sub {
debug "welcome to the home";
template 'index', {note => vars->{note}};
};
get '/hello/:name' => sub {
template 'hello';
};
get '/page/:slug' => sub {
template 'index' => {
message => 'This is the page '.params->{slug},
};
};
post '/new' => sub {
"creating new entry: ".params->{name};
};
get '/say/:word' => sub {
content_type "text/plain";
if (params->{word} =~ /^\d+$/) {
pass and return false;
}
"I say a word: '".params->{word}."'";
};
get '/download/*.*' => sub {
my ($file, $ext) = splat;
"Downloading $file.$ext";
};
get '/say/:number' => sub {
pass if (params->{number} == 42); # this is buggy :)
"I say a number: '".params->{number}."'";
};
# this is the trash route
get r('/(.*)') => sub {
my ($trash) = splat;
status 'not_found';
"got to trash: $trash";
};
dance;
1;