blib/lib/Web/Machine.pm

filter: Statementstmt 100% 69 / 69 Branchbran 92.8% 13 / 14 Conditioncond 37.5% 3 / 8 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 100% 19 / 19 Podpod 100% 6 / 6 totaltotal 91.6% 110 / 120 CC 11 SCAR 10.1
CC
11
Cov
93%
new
6.8
call
4.0
create_resource
2.0
CRAP 2.7
« blib/lib/Web/Machine/Util/BodyEncoding.pm ↑ Summary blib/lib/Web/Machine/Resource.pm »
1 package Web::Machine;
2 # ABSTRACT: A Perl port of Webmachine
3  
4 16 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 16 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 16 our $VERSION = '0.17';
8  
9 16 ▶use Try::Tiny;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 16 ▶use Carp qw[ confess ];
Subroutine BEGIN: called CC=1 SCAR=0.0
11 16 ▶use Scalar::Util qw[ blessed ];
Subroutine BEGIN: called CC=1 SCAR=0.0
12 16 ▶use Module::Runtime qw[ use_package_optimistically ];
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 16 ▶use Plack::Request;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 16 ▶use Plack::Response;
Subroutine BEGIN: called CC=1 SCAR=0.0
16  
17 16 ▶use Web::Machine::Util qw[ inflate_headers ];
Subroutine BEGIN: called CC=1 SCAR=0.0
18 16 ▶use Web::Machine::FSM;
Subroutine BEGIN: called CC=1 SCAR=0.0
19  
20 16 ▶use parent 'Plack::Component';
Subroutine BEGIN: called CC=1 SCAR=0.0
21  
22 25 ▶sub new {
Subroutine new: called CC=6 SCAR=19.1
Pod documented
23 25 my ($class, %args) = @_;
24  
25 (exists $args{'resource'}
26 && (not blessed $args{'resource'})
27 25 ▶ && use_package_optimistically($args{'resource'})->isa('Web::Machine::Resource'))
Branch: 1 branch
BranchTrueFalseTotal
exists $args{"resource"} and not builtin::blessed($args{"resource"}) and &use_package_optimistically($args{"resource"})->isa("Web::Machine::Resource") or confess("You must pass in a resource for this Web::Machine") 25 0 25
Condition33%2/6
exists $args{"resource"} and not builtin::blessed($args{"resource"}) and &use_package_optimistically($args{"resource"})->isa("Web::Machine::Resource")
!ll&&!rl&&r
0025
exists $args{"resource"} and not builtin::blessed($args{"resource"})
!ll&&!rl&&r
0025
MC/DC0%0/3
exists $args{"resource"} and not builtin::blessed($args{"resource"}) and &use_package_optimistically($args{"resource"})->isa("Web::Machine::Resource")
exists $args{"resource"} not builtin::blessed($args{"resource"}) &use_package_optimistically($args{"resource"})->isa("Web::Machine::Resource")
Truth table25%1/4
A and not(B) and C
A= exists $args{"resource"}B= not builtin::blessed($args{"resource"})C= &use_package_optimistically($args{"resource"})->isa("Web::Machine::Resource")
ABCresult
0XX0
10X0
1100
1111
28 || confess 'You must pass in a resource for this Web::Machine';
29  
30 25 ▶ if (exists $args{'request_class'}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $args{'request_class'}) { } 4 21 25
31 4 ▶ use_package_optimistically($args{'request_class'})->isa('Plack::Request')
Branch: 1 branch
BranchTrueFalseTotal
&use_package_optimistically($args{"request_class"})->isa("Plack::Request") or confess("The request_class class must inherit from Plack::Request") 1 2 3
32 || confess 'The request_class class must inherit from Plack::Request';
33 }
34 else {
35 21 $args{'request_class'} = 'Plack::Request';
36 }
37  
38 22 $class->SUPER::new( \%args );
39 }
40  
41 48 ▶sub inflate_request {
Subroutine inflate_request: called CC=1 SCAR=0.0
Pod documented
42 48 my ($self, $env) = @_;
43 48 inflate_headers( $self->{request_class}->new( $env ) );
44 }
45  
46 46 ▶sub create_fsm {
Subroutine create_fsm: called CC=1 SCAR=0.0
Pod documented
47 46 my $self = shift;
48 46 Web::Machine::FSM->new( tracing => $self->{'tracing'} )
49 }
50  
51 46 ▶sub create_resource {
Subroutine create_resource: called CC=2 SCAR=7.1
Pod documented
52 46 my ($self, $request) = @_;
53 $self->{'resource'}->new(
54 request => $request,
55 response => $request->new_response,
56 46 ▶ @{ $self->{'resource_args'} || [] },
Condition50%1/2
$self->{'resource_args'} || []
l!l
046
MC/DC0%0/1
$self->{'resource_args'} || []
$self->{'resource_args'}
Truth table50%1/2
A
A= $self->{'resource_args'}
Aresult
11
00
57 );
58 }
59  
60 47 ▶sub finalize_response {
Subroutine finalize_response: called CC=1 SCAR=0.0
Pod documented
61 47 my ($self, $response) = @_;
62 47 $response->finalize;
63 }
64  
65 47 ▶sub call {
Subroutine call: called CC=4 SCAR=13.9
Pod documented
66 47 my ($self, $env) = @_;
67  
68 47 ▶ my $request = try { $self->inflate_request($env) };
Subroutine __ANON__: called CC=1 SCAR=0.0
69  
70 47 ▶ return $self->finalize_response( Plack::Response->new( 400 ) )
Branch: 1 branch
BranchTrueFalseTotal
unless defined $request 1 46 47
71 unless defined $request;
72  
73 46 my $resource = $self->create_resource( $request );
74 46 my $fsm = $self->create_fsm;
75  
76 46 ▶ if ($self->{'streaming'}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'streaming'}) { } 10 36 46
77 10 ▶ return sub {
Subroutine __ANON__: called CC=2 SCAR=6.9
78 10 my $responder = shift;
79  
80 10 my $response = $self->finalize_response( $fsm->run( $resource ) );
81  
82 10 ▶ if (my $cb = $env->{'web.machine.streaming_push'}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $cb = $env->{'web.machine.streaming_push'}) { } 4 6 10
83 4 pop @$response;
84 4 my $writer = $responder->($response);
85 4 $cb->($writer);
86 }
87 else {
88 6 $responder->($response);
89 }
90 }
91 10 }
92 else {
93 36 my $response = $self->finalize_response( $fsm->run( $resource ) );
94  
95 36 ▶ if ($env->{'web.machine.streaming_push'}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($env->{'web.machine.streaming_push'}) { } 1 35 36
96 1 die "Can't do a streaming push response "
97 . "unless the 'streaming' option was set";
98 }
99 else {
100 35 return $response;
101 }
102 }
103 }
104  
105 16 1;
106  
107 __END__
« blib/lib/Web/Machine/Util/BodyEncoding.pm ↑ Summary blib/lib/Web/Machine/Resource.pm »