blib/lib/Poet/Mason/Plugin/Request.pm

filter: Statementstmt 72.0% 67 / 93 Branchbran 100% 12 / 12 Conditioncond 83.3% 5 / 6 MC/DCmcdc 75.0% 3 / 4 Subroutinesub 72.7% 16 / 22 Podpod n/a totaltotal 75.1% 103 / 137 CC 10 SCAR 9.1
CC
10
Cov
76%
__ANON__
6.0
__ANON__
3.0
__ANON__
2.0
CRAP 2.5
« blib/lib/Poet/t/Environment.pm ↑ Summary blib/lib/Poet/Test/Class.pm »
1 package Poet::Mason::Plugin::Request;
2 1 $Poet::Mason::Plugin::Request::VERSION = '0.16';
3 2 ▶use Mason::PluginRole;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use Poet qw($conf $poet);
Subroutine BEGIN: called CC=1 SCAR=0.0
5 2 ▶use Poet::Plack::Response;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 2 ▶use JSON::XS;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 2 ▶use Try::Tiny;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 1 has 'req' => ( is => 'ro', required => 1, isa => 'Object' );
10 1 has 'res' => ( is => 'ro', required => 1, isa => 'Object' );
11  
12 17 ▶around 'run' => sub {
Subroutine __ANON__: called CC=3 SCAR=11.0
13 17 my $orig = shift;
14 17 my $self = shift;
15  
16 17 my $result = $self->$orig(@_);
17 15 ▶ $self->res->status(200) if !$self->res->status;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->res->status 7 8 15
18 15 ▶ $self->res->content_type( $conf->get( 'server.default_content_type' => 'text/html' ) )
Branch: 1 branch
BranchTrueFalseTotal
unless $self->res->content_type 12 3 15
19 if !$self->res->content_type();
20 15 $self->res->content( $result->output );
21 15 return $result;
22 1 };
23  
24 16 ▶around 'construct_page_component' => sub {
Subroutine __ANON__: called CC=6 SCAR=17.9
25 16 my $orig = shift;
26 16 my $self = shift;
27 16 my ( $compc, $args ) = @_;
28  
29 16 ▶ if ( blessed($args) && $args->can('get_all') ) {
Branch: 1 branch
BranchTrueFalseTotal
if (builtin::blessed($args) and $args->can("get_all")) 13 3 16
Condition66%2/3
builtin::blessed($args) and $args->can("get_all")
!ll&&!rl&&r
3013
MC/DC50%1/2
builtin::blessed($args) and $args->can("get_all")
builtin::blessed($args) $args->can("get_all")
Truth table66%2/3
A and B
A= builtin::blessed($args)B= $args->can("get_all")
ABresult
0X0
100
111
30 13 my $orig_args = $args;
31 13 $args = $orig_args->as_hashref;
32  
33 # TODO: cache this
34 my @array_attrs =
35 3 map { $_->name }
36 13 ▶ grep { $_->has_type_constraint && $_->type_constraint->is_a_type_of('ArrayRef') }
Condition100%3/3
$_->has_type_constraint && $_->type_constraint->is_a_type_of('ArrayRef')
!ll&&!rl&&r
4013
MC/DC100%2/2
$_->has_type_constraint && $_->type_constraint->is_a_type_of('ArrayRef')
$_->has_type_constraint $_->type_constraint->is_a_type_of('ArrayRef')
Truth table100%3/3
A && B
A= $_->has_type_constraintB= $_->type_constraint->is_a_type_of('ArrayRef')
ABresult
0X0
100
111
37 $compc->meta->get_all_attributes;
38 13 foreach my $attr (@array_attrs) {
39 3 ▶ if ( my @values = $orig_args->get_all($attr) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my(@values) = $orig_args->get_all($attr)) 2 1 3
40 2 $args->{$attr} = \@values;
41 }
42 }
43 }
44  
45 16 $self->$orig( $compc, $args );
46 1 };
47  
48 16 ▶override 'catch_abort' => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
49 16 my ( $self, $code ) = @_;
50 16 my $retval;
51 16 ▶ try {
Subroutine __ANON__: called CC=1 SCAR=0.0
52 16 $retval = $code->();
53 }
54 7 ▶ catch {
Subroutine __ANON__: called CC=2 SCAR=6.9
55 7 my $err = $_;
56 7 ▶ if ( $self->aborted($err) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->aborted($err)) { } 6 1 7
57 6 $retval = $err->aborted_value;
58 }
59 else {
60 1 local $SIG{__DIE__} = undef;
61 1 die $err;
62 }
63 16 };
64 15 return $retval;
65 1 };
66  
67 6 ▶before 'abort' => sub {
Subroutine __ANON__: called CC=2 SCAR=6.9
68 6 my ( $self, $retval ) = @_;
69 6 ▶ $self->res->status($retval) if defined($retval);
Branch: 1 branch
BranchTrueFalseTotal
if defined $retval 1 5 6
70 1 };
71  
72 2 ▶method redirect () {
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine redirect: called CC=1 SCAR=0.0
73 4 $self->res->redirect(@_);
74 4 $self->clear_and_abort();
75 1 }
76  
77 0 ▶method not_found () {
Subroutine BEGIN: called CC=1 SCAR=4.1
Subroutine not_found: not called CC=1 SCAR=4.9
Subroutine __ANON__: not called CC=1 SCAR=4.9
78 0 $self->clear_and_abort(404);
79 1 }
80  
81 0 ▶method session () {
Subroutine BEGIN: called CC=1 SCAR=4.1
Subroutine session: not called CC=1 SCAR=4.9
Subroutine __ANON__: not called CC=1 SCAR=4.9
82 0 $self->req->session;
83 1 }
84  
85 0 ▶method send_json ($data) {
Subroutine BEGIN: called CC=1 SCAR=4.9
Subroutine __ANON__: not called CC=1 SCAR=6.0
Subroutine send_json: not called CC=1 SCAR=6.0
86 0 $self->clear_buffer;
87 0 $self->print( JSON::XS::encode_json($data) );
88 0 $self->res->content_type("application/json");
89 0 $self->abort();
90 1 }
91  
92 1 1;
« blib/lib/Poet/t/Environment.pm ↑ Summary blib/lib/Poet/Test/Class.pm »