line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Plack::Middleware::Acme::Werewolf; |
2
|
|
|
|
|
|
|
|
3
|
4
|
|
|
4
|
|
305271
|
use strict; |
|
4
|
|
|
|
|
7
|
|
|
4
|
|
|
|
|
134
|
|
4
|
4
|
|
|
4
|
|
21
|
use warnings; |
|
4
|
|
|
|
|
7
|
|
|
4
|
|
|
|
|
117
|
|
5
|
4
|
|
|
4
|
|
3688
|
use Astro::MoonPhase (); |
|
4
|
|
|
|
|
12183
|
|
|
4
|
|
|
|
|
95
|
|
6
|
4
|
|
|
4
|
|
871
|
use parent qw( Plack::Middleware ); |
|
4
|
|
|
|
|
302
|
|
|
4
|
|
|
|
|
32
|
|
7
|
4
|
|
|
4
|
|
17689
|
use Plack::Util::Accessor qw( moonlength message handler ); |
|
4
|
|
|
|
|
7
|
|
|
4
|
|
|
|
|
44
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
our $VERSION = '0.02'; |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
sub prepare_app { |
12
|
3
|
|
|
3
|
1
|
622
|
my ( $self ) = @_; |
13
|
3
|
50
|
|
|
|
20
|
die "Set moonlength" unless $self->moonlength; |
14
|
3
|
50
|
66
|
|
|
325
|
die "handler must be a code reference." if $self->handler && ref( $self->handler ) ne 'CODE'; |
15
|
|
|
|
|
|
|
} |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
sub call { |
18
|
5
|
|
|
5
|
1
|
57284
|
my ( $self, $env ) = @_; |
19
|
5
|
|
|
|
|
25
|
my $moonage = ( Astro::MoonPhase::phase( time ) )[2]; |
20
|
|
|
|
|
|
|
#print "moonage:$moonage\n"; |
21
|
5
|
100
|
|
|
|
1347
|
if ( abs( 14 - $moonage ) > $self->moonlength / 2 ) { |
22
|
2
|
|
|
|
|
42
|
return $self->app->( $env ); |
23
|
|
|
|
|
|
|
} |
24
|
|
|
|
|
|
|
else { |
25
|
3
|
|
100
|
|
|
36
|
my $body = $self->message || 'Forbidden'; |
26
|
|
|
|
|
|
|
|
27
|
3
|
100
|
|
|
|
44
|
if ( $self->handler ) { |
28
|
1
|
|
|
|
|
9
|
return $self->handler->( $self, $env, $moonage ); |
29
|
|
|
|
|
|
|
} |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
return [ |
32
|
2
|
|
|
|
|
46
|
403, |
33
|
|
|
|
|
|
|
[ |
34
|
|
|
|
|
|
|
'Content-Type' => 'text/plain', |
35
|
|
|
|
|
|
|
'Content-Length' => length $body, |
36
|
|
|
|
|
|
|
], |
37
|
|
|
|
|
|
|
[ $body ] |
38
|
|
|
|
|
|
|
]; |
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
1; |
43
|
|
|
|
|
|
|
__END__ |