line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
#!/usr/bin/perl |
2
|
1
|
|
|
1
|
|
16515
|
use 5.006; |
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
104
|
|
3
|
1
|
|
|
1
|
|
4
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
34
|
|
4
|
1
|
|
|
1
|
|
3
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
53
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
package Plack::App::Hash; |
7
|
|
|
|
|
|
|
$Plack::App::Hash::VERSION = '1.000'; |
8
|
|
|
|
|
|
|
# ABSTRACT: Serve up the contents of a hash as a website |
9
|
|
|
|
|
|
|
|
10
|
1
|
|
|
1
|
|
418
|
use parent 'Plack::Component'; |
|
1
|
|
|
|
|
248
|
|
|
1
|
|
|
|
|
4
|
|
11
|
|
|
|
|
|
|
|
12
|
1
|
|
|
1
|
|
11335
|
use Plack::Util (); |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
11
|
|
13
|
1
|
|
|
1
|
|
458
|
use Array::RefElem (); |
|
1
|
|
|
|
|
509
|
|
|
1
|
|
|
|
|
20
|
|
14
|
1
|
|
|
1
|
|
475
|
use HTTP::Status (); |
|
1
|
|
|
|
|
2669
|
|
|
1
|
|
|
|
|
29
|
|
15
|
|
|
|
|
|
|
#use Digest::SHA; |
16
|
|
|
|
|
|
|
|
17
|
1
|
|
|
1
|
|
458
|
use Plack::Util::Accessor qw( content headers auto_type default_type ); |
|
1
|
|
|
|
|
211
|
|
|
1
|
|
|
|
|
6
|
|
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
sub call { |
20
|
16
|
|
|
16
|
1
|
32183
|
my $self = shift; |
21
|
16
|
|
|
|
|
17
|
my $env = shift; |
22
|
|
|
|
|
|
|
|
23
|
16
|
|
50
|
|
|
42
|
my $path = $env->{'PATH_INFO'} || ''; |
24
|
16
|
|
|
|
|
57
|
$path =~ s!\A/!!; |
25
|
|
|
|
|
|
|
|
26
|
16
|
|
|
|
|
45
|
my $content = $self->content; |
27
|
16
|
100
|
66
|
|
|
147
|
return $self->error( 404 ) unless $content and exists $content->{ $path }; |
28
|
15
|
100
|
|
|
|
70
|
return $self->error( 500 ) if ref $content->{ $path }; |
29
|
|
|
|
|
|
|
|
30
|
14
|
|
66
|
|
|
29
|
my $headers = ( $self->headers || $self->headers( {} ) )->{ $path }; |
31
|
|
|
|
|
|
|
|
32
|
14
|
100
|
|
|
|
86
|
if ( not defined $headers ) { |
|
|
100
|
|
|
|
|
|
33
|
8
|
|
|
|
|
12
|
$headers = []; |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
elsif ( not ref $headers ) { |
36
|
2
|
|
|
|
|
1000
|
require JSON::MaybeXS; |
37
|
2
|
|
|
|
|
4364
|
$headers = JSON::MaybeXS::decode_json $headers; |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
|
40
|
13
|
100
|
|
|
|
34
|
return $self->error( 500 ) if 'ARRAY' ne ref $headers; |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
{ |
43
|
12
|
|
|
|
|
12
|
my $auto = $self->auto_type; |
|
12
|
|
|
|
|
28
|
|
44
|
12
|
|
|
|
|
51
|
my $default = $self->default_type; |
45
|
12
|
100
|
100
|
|
|
71
|
last unless $auto or $default; |
46
|
5
|
100
|
|
|
|
13
|
last if Plack::Util::header_exists $headers, 'Content-Type'; |
47
|
3
|
|
66
|
|
|
37
|
$auto &&= do { require Plack::MIME; Plack::MIME->mime_type( $path ) }; |
|
2
|
|
|
|
|
484
|
|
|
2
|
|
|
|
|
626
|
|
48
|
3
|
|
66
|
|
|
40
|
Plack::Util::header_push $headers, 'Content-Type' => $_ for $auto || $default || (); |
|
|
|
33
|
|
|
|
|
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
|
51
|
12
|
100
|
|
|
|
77
|
if ( not Plack::Util::header_exists $headers, 'Content-Length' ) { |
52
|
10
|
|
|
|
|
254
|
Plack::Util::header_push $headers, 'Content-Length' => length $content->{ $path }; |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
|
55
|
12
|
|
|
|
|
64
|
my @body; |
56
|
12
|
|
|
|
|
34
|
Array::RefElem::av_push @body, $content->{ $path }; |
57
|
12
|
|
|
|
|
70
|
return [ 200, $headers, \@body ]; |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
sub error { |
61
|
3
|
|
|
3
|
0
|
4
|
my $status = pop; |
62
|
3
|
|
|
|
|
5
|
my $pkg = __PACKAGE__; |
63
|
3
|
|
|
|
|
14
|
my $body = [ qq(\n$pkg $status) . HTTP::Status::status_message $status ]; |
64
|
3
|
|
|
|
|
30
|
return [ $status, [ |
65
|
|
|
|
|
|
|
'Content-Type' => 'text/html', |
66
|
|
|
|
|
|
|
'Content-Length' => length $body->[0], |
67
|
|
|
|
|
|
|
], $body ]; |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
1; |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
__END__ |