line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Plack::Middleware::RevisionPlate; |
2
|
3
|
|
|
3
|
|
115656
|
use 5.010; |
|
3
|
|
|
|
|
11
|
|
|
3
|
|
|
|
|
127
|
|
3
|
3
|
|
|
3
|
|
12
|
use strict; |
|
3
|
|
|
|
|
5
|
|
|
3
|
|
|
|
|
100
|
|
4
|
3
|
|
|
3
|
|
21
|
use warnings; |
|
3
|
|
|
|
|
3
|
|
|
3
|
|
|
|
|
105
|
|
5
|
|
|
|
|
|
|
|
6
|
3
|
|
|
3
|
|
902
|
use Plack::Util::Accessor qw/path revision_filename/; |
|
3
|
|
|
|
|
400
|
|
|
3
|
|
|
|
|
21
|
|
7
|
3
|
|
|
3
|
|
1619
|
use Plack::Response; |
|
3
|
|
|
|
|
37804
|
|
|
3
|
|
|
|
|
132
|
|
8
|
3
|
|
|
3
|
|
2311
|
use File::Slurp qw/read_file/; |
|
3
|
|
|
|
|
49823
|
|
|
3
|
|
|
|
|
262
|
|
9
|
3
|
|
|
3
|
|
1264
|
use parent qw/Plack::Middleware/; |
|
3
|
|
|
|
|
643
|
|
|
3
|
|
|
|
|
21
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
our $VERSION = "0.01"; |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
sub call { |
14
|
12
|
|
|
12
|
1
|
51337
|
my $self = shift; |
15
|
12
|
|
|
|
|
12
|
my $env = shift; |
16
|
12
|
|
66
|
|
|
26
|
return $self->_may_handle_request($env) // $self->app->($env); |
17
|
|
|
|
|
|
|
} |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
sub prepare_app { |
20
|
2
|
|
|
2
|
1
|
49968
|
my $self = shift; |
21
|
2
|
|
|
|
|
6
|
$self->_read_revision_file_at_first; |
22
|
|
|
|
|
|
|
} |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
sub _read_revision_file_at_first { |
25
|
4
|
|
|
4
|
|
9
|
my $self = shift; |
26
|
4
|
|
66
|
|
|
10
|
$self->{revision} = -e $self->_revision_filename && read_file($self->_revision_filename); |
27
|
|
|
|
|
|
|
} |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
sub _may_handle_request { |
30
|
12
|
|
|
12
|
|
12
|
my ($self, $env) = @_; |
31
|
12
|
50
|
|
|
|
34
|
my $path_match = $self->path or return; |
32
|
12
|
|
|
|
|
69
|
my $path = $env->{PATH_INFO}; |
33
|
|
|
|
|
|
|
|
34
|
12
|
|
|
|
|
17
|
for ($path) { |
35
|
12
|
50
|
|
|
|
131
|
my $matched = 'CODE' eq ref $path_match ? $path_match->($_, $env) : $_ =~ $path_match; |
36
|
12
|
100
|
|
|
|
51
|
return unless $matched; |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
|
39
|
8
|
|
|
|
|
9
|
my $method = $env->{REQUEST_METHOD}; |
40
|
8
|
100
|
100
|
|
|
38
|
return Plack::Response->new(405)->finalize if $method ne 'GET' && $method ne 'HEAD'; # 405: method not allowed |
41
|
|
|
|
|
|
|
|
42
|
6
|
|
|
|
|
29
|
my $res = Plack::Response->new; |
43
|
6
|
|
|
|
|
52
|
$res->content_type('text/plain'); |
44
|
6
|
100
|
|
|
|
122
|
if (defined $self->{revision}) { |
45
|
3
|
100
|
|
|
|
7
|
if (-e $self->_revision_filename) { |
46
|
2
|
|
|
|
|
8
|
$res->status(200); |
47
|
2
|
|
|
|
|
15
|
$res->body($self->{revision}); |
48
|
|
|
|
|
|
|
} else { |
49
|
1
|
|
|
|
|
4
|
$res->status(404); |
50
|
1
|
|
|
|
|
6
|
$res->body("REVISION_FILE_REMOVED\n"); |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
} else { |
53
|
3
|
|
|
|
|
10
|
$res->status(404); |
54
|
3
|
|
|
|
|
17
|
$res->body("REVISION_FILE_NOT_FOUND\n"); |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
|
57
|
6
|
100
|
|
|
|
32
|
$res->body('') if $method eq 'HEAD'; |
58
|
6
|
|
|
|
|
19
|
return $res->finalize; |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
sub _revision_filename { |
62
|
11
|
|
|
11
|
|
1742
|
my $self = shift; |
63
|
11
|
|
100
|
|
|
289
|
$self->{_revision_filename} //= $self->revision_filename // './REVISION'; |
|
|
|
66
|
|
|
|
|
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
1; |
67
|
|
|
|
|
|
|
__END__ |