| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Dancer2::Handler::AutoPage; |
|
2
|
|
|
|
|
|
|
# ABSTRACT: Class for handling the AutoPage feature |
|
3
|
|
|
|
|
|
|
$Dancer2::Handler::AutoPage::VERSION = '2.0.1'; |
|
4
|
142
|
|
|
142
|
|
306595
|
use Moo; |
|
|
142
|
|
|
|
|
8215
|
|
|
|
142
|
|
|
|
|
11716
|
|
|
5
|
142
|
|
|
142
|
|
72522
|
use Carp 'croak'; |
|
|
142
|
|
|
|
|
369
|
|
|
|
142
|
|
|
|
|
10812
|
|
|
6
|
142
|
|
|
142
|
|
1377
|
use Dancer2::Core::Types; |
|
|
142
|
|
|
|
|
394
|
|
|
|
142
|
|
|
|
|
2010
|
|
|
7
|
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
with qw< |
|
9
|
|
|
|
|
|
|
Dancer2::Core::Role::Handler |
|
10
|
|
|
|
|
|
|
Dancer2::Core::Role::StandardResponses |
|
11
|
|
|
|
|
|
|
>; |
|
12
|
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
sub register { |
|
14
|
216
|
|
|
216
|
1
|
702
|
my ( $self, $app ) = @_; |
|
15
|
|
|
|
|
|
|
|
|
16
|
216
|
100
|
|
|
|
4478
|
return unless $app->config->{auto_page}; |
|
17
|
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
$app->add_route( |
|
19
|
|
|
|
|
|
|
method => $_, |
|
20
|
|
|
|
|
|
|
regexp => $self->regexp, |
|
21
|
|
|
|
|
|
|
code => $self->code, |
|
22
|
4
|
|
|
|
|
48
|
) for $self->methods; |
|
23
|
|
|
|
|
|
|
} |
|
24
|
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
sub code { |
|
26
|
|
|
|
|
|
|
sub { |
|
27
|
10
|
|
|
10
|
|
20
|
my $app = shift; |
|
28
|
10
|
|
|
|
|
14
|
my $prefix = shift; |
|
29
|
|
|
|
|
|
|
|
|
30
|
10
|
|
|
|
|
185
|
my $template = $app->template_engine; |
|
31
|
10
|
50
|
|
|
|
105
|
if ( !defined $template ) { |
|
32
|
0
|
|
|
|
|
0
|
$app->response->has_passed(1); |
|
33
|
0
|
|
|
|
|
0
|
return; |
|
34
|
|
|
|
|
|
|
} |
|
35
|
|
|
|
|
|
|
|
|
36
|
10
|
|
|
|
|
49
|
my $page = $app->request->path; |
|
37
|
10
|
|
|
|
|
250
|
my $layout_dir = $template->layout_dir; |
|
38
|
10
|
100
|
|
|
|
135
|
if ( $page =~ m{^/\Q$layout_dir\E/} ) { |
|
39
|
3
|
|
|
|
|
47
|
$app->response->has_passed(1); |
|
40
|
3
|
|
|
|
|
148
|
return; |
|
41
|
|
|
|
|
|
|
} |
|
42
|
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
# remove leading '/', ensuring paths relative to the view |
|
44
|
7
|
|
|
|
|
30
|
$page =~ s{^/}{}; |
|
45
|
7
|
|
|
|
|
36
|
my $view_path = $template->view_pathname($page); |
|
46
|
|
|
|
|
|
|
|
|
47
|
7
|
100
|
|
|
|
30
|
if ( ! $template->pathname_exists( $view_path ) ) { |
|
48
|
3
|
|
|
|
|
76
|
$app->response->has_passed(1); |
|
49
|
3
|
|
|
|
|
204
|
return; |
|
50
|
|
|
|
|
|
|
} |
|
51
|
|
|
|
|
|
|
|
|
52
|
4
|
|
|
|
|
48
|
my $ct = $template->process( $page ); |
|
53
|
4
|
50
|
|
|
|
60
|
return ( $app->request->method eq 'GET' ) ? $ct : ''; |
|
54
|
8
|
|
|
8
|
1
|
83
|
}; |
|
55
|
|
|
|
|
|
|
} |
|
56
|
|
|
|
|
|
|
|
|
57
|
8
|
|
|
8
|
1
|
36
|
sub regexp {'/**'} |
|
58
|
|
|
|
|
|
|
|
|
59
|
4
|
|
|
4
|
1
|
25
|
sub methods {qw(head get)} |
|
60
|
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
1; |
|
62
|
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
__END__ |