line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Web::Machine; |
2
|
|
|
|
|
|
|
BEGIN { |
3
|
10
|
|
|
10
|
|
645219
|
$Web::Machine::AUTHORITY = 'cpan:STEVAN'; |
4
|
|
|
|
|
|
|
} |
5
|
|
|
|
|
|
|
# ABSTRACT: A Perl port of Webmachine |
6
|
|
|
|
|
|
|
$Web::Machine::VERSION = '0.15'; |
7
|
10
|
|
|
10
|
|
91
|
use strict; |
|
10
|
|
|
|
|
24
|
|
|
10
|
|
|
|
|
331
|
|
8
|
10
|
|
|
10
|
|
53
|
use warnings; |
|
10
|
|
|
|
|
17
|
|
|
10
|
|
|
|
|
287
|
|
9
|
|
|
|
|
|
|
|
10
|
10
|
|
|
10
|
|
1896
|
use Try::Tiny; |
|
10
|
|
|
|
|
3824
|
|
|
10
|
|
|
|
|
649
|
|
11
|
10
|
|
|
10
|
|
78
|
use Carp qw[ confess ]; |
|
10
|
|
|
|
|
29
|
|
|
10
|
|
|
|
|
556
|
|
12
|
10
|
|
|
10
|
|
59
|
use Scalar::Util qw[ blessed ]; |
|
10
|
|
|
|
|
18
|
|
|
10
|
|
|
|
|
1605
|
|
13
|
10
|
|
|
10
|
|
9146
|
use Module::Runtime qw[ use_package_optimistically ]; |
|
10
|
|
|
|
|
17300
|
|
|
10
|
|
|
|
|
66
|
|
14
|
|
|
|
|
|
|
|
15
|
10
|
|
|
10
|
|
7894
|
use Plack::Request; |
|
10
|
|
|
|
|
534346
|
|
|
10
|
|
|
|
|
339
|
|
16
|
10
|
|
|
10
|
|
7534
|
use Plack::Response; |
|
10
|
|
|
|
|
23054
|
|
|
10
|
|
|
|
|
344
|
|
17
|
|
|
|
|
|
|
|
18
|
10
|
|
|
10
|
|
6036
|
use Web::Machine::Util qw[ inflate_headers ]; |
|
10
|
|
|
|
|
36
|
|
|
10
|
|
|
|
|
66
|
|
19
|
10
|
|
|
10
|
|
15588
|
use Web::Machine::FSM; |
|
10
|
|
|
|
|
31
|
|
|
10
|
|
|
|
|
342
|
|
20
|
|
|
|
|
|
|
|
21
|
10
|
|
|
10
|
|
113
|
use parent 'Plack::Component'; |
|
10
|
|
|
|
|
20
|
|
|
10
|
|
|
|
|
151
|
|
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
sub new { |
24
|
18
|
|
|
18
|
1
|
16828
|
my ($class, %args) = @_; |
25
|
|
|
|
|
|
|
|
26
|
18
|
50
|
33
|
|
|
297
|
(exists $args{'resource'} |
|
|
|
33
|
|
|
|
|
27
|
|
|
|
|
|
|
&& (not blessed $args{'resource'}) |
28
|
|
|
|
|
|
|
&& use_package_optimistically($args{'resource'})->isa('Web::Machine::Resource')) |
29
|
|
|
|
|
|
|
|| confess 'You must pass in a resource for this Web::Machine'; |
30
|
|
|
|
|
|
|
|
31
|
18
|
100
|
|
|
|
8225
|
if (exists $args{'request_class'}) { |
32
|
4
|
100
|
|
|
|
14
|
use_package_optimistically($args{'request_class'})->isa('Plack::Request') |
33
|
|
|
|
|
|
|
|| confess 'The request_class class must inherit from Plack::Request'; |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
else { |
36
|
14
|
|
|
|
|
54
|
$args{'request_class'} = 'Plack::Request'; |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
|
39
|
15
|
|
|
|
|
635
|
$class->SUPER::new( \%args ); |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
sub inflate_request { |
43
|
33
|
|
|
33
|
1
|
96
|
my ($self, $env) = @_; |
44
|
33
|
|
|
|
|
1008
|
inflate_headers( $self->{request_class}->new( $env ) ); |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
sub create_fsm { |
48
|
31
|
|
|
31
|
1
|
52
|
my $self = shift; |
49
|
31
|
|
|
|
|
400
|
Web::Machine::FSM->new( tracing => $self->{'tracing'} ) |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
sub create_resource { |
53
|
31
|
|
|
31
|
1
|
79
|
my ($self, $request) = @_; |
54
|
31
|
50
|
|
|
|
1321
|
$self->{'resource'}->new( |
55
|
|
|
|
|
|
|
request => $request, |
56
|
|
|
|
|
|
|
response => $request->new_response, |
57
|
31
|
|
|
|
|
217
|
@{ $self->{'resource_args'} || [] }, |
58
|
|
|
|
|
|
|
); |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
sub finalize_response { |
62
|
32
|
|
|
32
|
1
|
90
|
my ($self, $response) = @_; |
63
|
32
|
|
|
|
|
150
|
$response->finalize; |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
sub call { |
67
|
32
|
|
|
32
|
1
|
158233
|
my ($self, $env) = @_; |
68
|
|
|
|
|
|
|
|
69
|
32
|
|
|
32
|
|
279
|
my $request = try { $self->inflate_request( $env ) }; |
|
32
|
|
|
|
|
784
|
|
70
|
|
|
|
|
|
|
|
71
|
32
|
100
|
|
|
|
100708
|
return $self->finalize_response( Plack::Response->new( 400 ) ) |
72
|
|
|
|
|
|
|
unless defined $request; |
73
|
|
|
|
|
|
|
|
74
|
31
|
|
|
|
|
151
|
my $resource = $self->create_resource( $request ); |
75
|
31
|
|
|
|
|
179
|
my $fsm = $self->create_fsm; |
76
|
|
|
|
|
|
|
|
77
|
31
|
100
|
|
|
|
146
|
if ($self->{'streaming'}) { |
78
|
|
|
|
|
|
|
return sub { |
79
|
10
|
|
|
10
|
|
3976
|
my $responder = shift; |
80
|
|
|
|
|
|
|
|
81
|
10
|
|
|
|
|
54
|
my $response = $self->finalize_response( $fsm->run( $resource ) ); |
82
|
|
|
|
|
|
|
|
83
|
10
|
100
|
|
|
|
2879
|
if (my $cb = $env->{'web.machine.streaming_push'}) { |
84
|
4
|
|
|
|
|
6
|
pop @$response; |
85
|
4
|
|
|
|
|
14
|
my $writer = $responder->($response); |
86
|
4
|
|
|
|
|
117
|
$cb->($writer); |
87
|
|
|
|
|
|
|
} |
88
|
|
|
|
|
|
|
else { |
89
|
6
|
|
|
|
|
28
|
$responder->($response); |
90
|
|
|
|
|
|
|
} |
91
|
|
|
|
|
|
|
} |
92
|
10
|
|
|
|
|
95
|
} |
93
|
|
|
|
|
|
|
else { |
94
|
21
|
|
|
|
|
120
|
my $response = $self->finalize_response( $fsm->run( $resource ) ); |
95
|
|
|
|
|
|
|
|
96
|
21
|
100
|
|
|
|
6880
|
if ($env->{'web.machine.streaming_push'}) { |
97
|
1
|
|
|
|
|
13
|
die "Can't do a streaming push response " |
98
|
|
|
|
|
|
|
. "unless the 'streaming' option was set"; |
99
|
|
|
|
|
|
|
} |
100
|
|
|
|
|
|
|
else { |
101
|
20
|
|
|
|
|
407
|
return $response; |
102
|
|
|
|
|
|
|
} |
103
|
|
|
|
|
|
|
} |
104
|
|
|
|
|
|
|
} |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
1; |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
__END__ |