blib/lib/Amon2/Web/Request.pm

filter: Statementstmt 89.6% 78 / 87 Branchbran 53.3% 16 / 30 Conditioncond 47.6% 10 / 21 MC/DCmcdc 0.0% 0 / 13 Subroutinesub 88.8% 16 / 18 Podpod 100% 9 / 9 totaltotal 72.4% 129 / 178 CC 26 SCAR 26.5
CC
26
Cov
75%
uri_with
32.8
param_raw
3.6
body_parameters
2.3
CRAP 14.1
« blib/lib/auto/share/dist/Amon2/flavor/Minimum/lib/__PATH__/Web/View.pm ↑ Summary blib/lib/Amon2/Setup/Flavor/Large.pm »
1 package Amon2::Web::Request;
2 14 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 14 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 14 ▶use parent qw/Plack::Request/;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 14 ▶use Encode ();
Subroutine BEGIN: called CC=1 SCAR=0.0
6 14 ▶use Carp ();
Subroutine BEGIN: called CC=1 SCAR=0.0
7 14 ▶use URI::QueryParam;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 14 ▶use Hash::MultiValue;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 32 ▶sub new {
Subroutine new: called CC=2 SCAR=6.9
Pod documented
11 32 my ($class, $env, $context_class) = @_;
12 32 my $self = $class->SUPER::new($env);
13 32 ▶ if (@_==3) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_ == 3) 4 28 32
14 4 $self->{_web_pkg} = $context_class;
15 }
16 32 return $self;
17 }
18  
19 3 ▶sub _encoding {
Subroutine _encoding: called CC=2 SCAR=7.2
20 3 my $self = shift;
21 3 ▶ return $self->{_web_pkg} ? $self->{_web_pkg}->context->encoding : Amon2->context->encoding;
Branch: 1 branch
BranchTrueFalseTotal
$self->{'_web_pkg'} ? : 0 3 3
22 }
23  
24 # -------------------------------------------------------------------------
25 # This object returns decoded parameter values by default
26  
27 1 ▶sub body_parameters {
Subroutine body_parameters: called CC=2 SCAR=8.1
Pod documented
28 1 my ($self) = @_;
29 1 ▶ $self->{'amon2.body_parameters'} ||= $self->_decode_parameters($self->SUPER::body_parameters());
Condition33%1/3
$self->{"amon2.body_parameters"} ||= $self->_decode_parameters($self->SUPER::body_parameters)
l!l&&r!l&&!r
010
MC/DC0%0/2
$self->{"amon2.body_parameters"} ||= $self->_decode_parameters($self->SUPER::body_parameters)
$self->{"amon2.body_parameters"} $self->_decode_parameters($self->SUPER::body_parameters)
Truth table33%1/3
A ||= B
A= $self->{"amon2.body_parameters"}B= $self->_decode_parameters($self->SUPER::body_parameters)
ABresult
1X1
011
000
30 }
31  
32 2 ▶sub query_parameters {
Subroutine query_parameters: called CC=2 SCAR=7.1
Pod documented
33 2 my ($self) = @_;
34 2 ▶ $self->{'amon2.query_parameters'} ||= $self->_decode_parameters($self->SUPER::query_parameters());
Condition66%2/3
$self->{"amon2.query_parameters"} ||= $self->_decode_parameters($self->SUPER::query_parameters)
l!l&&r!l&&!r
110
MC/DC0%0/2
$self->{"amon2.query_parameters"} ||= $self->_decode_parameters($self->SUPER::query_parameters)
$self->{"amon2.query_parameters"} $self->_decode_parameters($self->SUPER::query_parameters)
Truth table66%2/3
A ||= B
A= $self->{"amon2.query_parameters"}B= $self->_decode_parameters($self->SUPER::query_parameters)
ABresult
1X1
011
000
35 }
36  
37 2 ▶sub _decode_parameters {
Subroutine _decode_parameters: called CC=2 SCAR=6.9
38 2 my ($self, $stuff) = @_;
39  
40 2 my $encoding = $self->_encoding();
41 2 my @flatten = $stuff->flatten();
42 2 my @decoded;
43 2 ▶ while ( my ($k, $v) = splice @flatten, 0, 2 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = splice(@flatten, 0, 2)) 3 2 5
44 3 push @decoded, Encode::decode($encoding, $k), Encode::decode($encoding, $v);
45 }
46 2 return Hash::MultiValue->new(@decoded);
47 }
48 3 ▶sub parameters {
Subroutine parameters: called CC=2 SCAR=7.0
Pod documented
49 3 my $self = shift;
50  
51 3 ▶ $self->env->{'amon2.request.merged'} ||= do {
Condition66%2/3
$self->env->{"amon2.request.merged"} ||= do { my $query = $self->query_parameters; my $body = $self->body_parameters; "Hash::MultiValue"->new($query->flatten, $body->flatten) }
l!l&&r!l&&!r
210
MC/DC0%0/2
$self->env->{"amon2.request.merged"} ||= do { my $query = $self->query_parameters; my $body = $self->body_parameters; "Hash::MultiValue"->new($query->flatten, $body->flatten) }
$self->env->{"amon2.request.merged"} do { my $query = $self->query_parameters; my $body = $self->body_parameters; "Hash::MultiValue"->new($query->flatten, $body->flatten) }
Truth table66%2/3
A ||= B
A= $self->env->{"amon2.request.merged"}B= do { my $query = $self->query_parameters; my $body = $self->body_parameters; "Hash::MultiValue"->new($query->flatten, $body->flatten) }
ABresult
1X1
011
000
52 1 my $query = $self->query_parameters;
53 1 my $body = $self->body_parameters;
54 1 Hash::MultiValue->new( $query->flatten, $body->flatten );
55 };
56 }
57  
58 # -------------------------------------------------------------------------
59 # raw parameter values are also available.
60  
61 0 ▶sub body_parameters_raw {
Subroutine body_parameters_raw: not called CC=1 SCAR=6.9
Pod documented
62 0 shift->SUPER::body_parameters();
63 }
64 0 ▶sub query_parameters_raw {
Subroutine query_parameters_raw: not called CC=1 SCAR=6.9
Pod documented
65 0 shift->SUPER::query_parameters();
66 }
67 2 ▶sub parameters_raw {
Subroutine parameters_raw: called CC=2 SCAR=7.0
Pod documented
68 2 my $self = shift;
69  
70 2 ▶ $self->env->{'plack.request.merged'} ||= do {
Condition66%2/3
$self->env->{"plack.request.merged"} ||= do { my $query = $self->SUPER::query_parameters; my $body = $self->SUPER::body_parameters; "Hash::MultiValue"->new($query->flatten, $body->flatten) }
l!l&&r!l&&!r
110
MC/DC0%0/2
$self->env->{"plack.request.merged"} ||= do { my $query = $self->SUPER::query_parameters; my $body = $self->SUPER::body_parameters; "Hash::MultiValue"->new($query->flatten, $body->flatten) }
$self->env->{"plack.request.merged"} do { my $query = $self->SUPER::query_parameters; my $body = $self->SUPER::body_parameters; "Hash::MultiValue"->new($query->flatten, $body->flatten) }
Truth table66%2/3
A ||= B
A= $self->env->{"plack.request.merged"}B= do { my $query = $self->SUPER::query_parameters; my $body = $self->SUPER::body_parameters; "Hash::MultiValue"->new($query->flatten, $body->flatten) }
ABresult
1X1
011
000
71 1 my $query = $self->SUPER::query_parameters();
72 1 my $body = $self->SUPER::body_parameters();
73 1 Hash::MultiValue->new( $query->flatten, $body->flatten );
74 };
75 }
76 1 ▶sub param_raw {
Subroutine param_raw: called CC=3 SCAR=12.7
Pod documented
77 1 my $self = shift;
78  
79 0 ▶ return keys %{ $self->parameters_raw } if @_ == 0;
Branch: 1 branch
BranchTrueFalseTotal
if @_ == 0 0 1 1
80  
81 1 my $key = shift;
82 1 ▶ return $self->parameters_raw->{$key} unless wantarray;
Branch: 1 branch
BranchTrueFalseTotal
unless wantarray 1 0 1
83 0 return $self->parameters_raw->get_all($key);
84 }
85  
86  
87 # -------------------------------------------------------------------------
88 # uri_with funcition. The code was taken from Catalyst::Request
89 2 ▶sub uri_with {
Subroutine uri_with: called CC=17 SCAR=34.9
Pod documented
90 2 my( $self, $args, $behavior) = @_;
91  
92 2 ▶ Carp::carp( 'No arguments passed to uri_with()' ) unless $args;
Branch: 1 branch
BranchTrueFalseTotal
unless $args 0 2 2
93  
94 2 my $append = 0;
95 2 ▶ if((ref($behavior) eq 'HASH') && defined($behavior->{mode}) && ($behavior->{mode} eq 'append')) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $behavior eq "HASH" and defined $behavior->{"mode"} and $behavior->{"mode"} eq "append") 0 2 2
Condition33%2/6
ref $behavior eq "HASH" and defined $behavior->{"mode"} and $behavior->{"mode"} eq "append"
!ll&&!rl&&r
200
ref $behavior eq "HASH" and defined $behavior->{"mode"}
!ll&&!rl&&r
200
MC/DC0%0/3
ref $behavior eq "HASH" and defined $behavior->{"mode"} and $behavior->{"mode"} eq "append"
ref $behavior eq "HASH" defined $behavior->{"mode"} $behavior->{"mode"} eq "append"
Truth table25%1/4
A and B and C
A= ref $behavior eq "HASH"B= defined $behavior->{"mode"}C= $behavior->{"mode"} eq "append"
ABCresult
0XX0
10X0
1100
1111
96 0 $append = 1;
97 }
98  
99 2 my $params = do {
100 2 foreach my $value ( values %$args ) {
101 2 ▶ next unless defined $value;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $value 0 2 2
102 2 ▶ for ( ref $value eq 'ARRAY' ? @$value : $value ) {
Branch: 1 branch
BranchTrueFalseTotal
ref $value eq 'ARRAY' ? : 0 2 2
103 2 $_ = "$_";
104 2 ▶ utf8::encode($_) if utf8::is_utf8($_);
Branch: 1 branch
BranchTrueFalseTotal
if utf8::is_utf8($_) 0 2 2
105 }
106 }
107  
108 2 my %params = %{ $self->uri->query_form_hash };
109 2 foreach my $key ( keys %{$args} ) {
110 2 my $val = $args->{$key};
111 2 ▶ if (utf8::is_utf8($key)) {
Branch: 1 branch
BranchTrueFalseTotal
if (utf8::is_utf8($key)) 1 1 2
112 1 $key = Encode::encode($self->_encoding(), $key);
113 }
114 2 ▶ if ( defined($val) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $val) { } 2 0 2
115  
116 2 ▶ if ( $append && exists( $params{$key} ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($append and exists $params{$key}) { } 0 2 2
Condition33%1/3
$append and exists $params{$key}
!ll&&!rl&&r
200
MC/DC0%0/2
$append and exists $params{$key}
$append exists $params{$key}
Truth table33%1/3
A and B
A= $appendB= exists $params{$key}
ABresult
0X0
100
111
117  
118 # This little bit of heaven handles appending a new value onto
119 # an existing one regardless if the existing value is an array
120 # or not, and regardless if the new value is an array or not
121 $params{$key} = [
122 ref( $params{$key} ) eq 'ARRAY'
123 0 ▶ ? @{ $params{$key} }
Branch: 1 branch
BranchTrueFalseTotal
ref $val eq 'ARRAY' ? : 0 0 0
124 : $params{$key},
125 0 ▶ ref($val) eq 'ARRAY' ? @{$val} : $val
Branch: 1 branch
BranchTrueFalseTotal
ref $params{$key} eq 'ARRAY' ? : 0 0 0
126 ];
127  
128 }
129 else {
130 2 $params{$key} = $val;
131 }
132 }
133 else {
134  
135 # If the param wasn't defined then we delete it.
136 0 delete( $params{$key} );
137 }
138 }
139 2 \%params;
140 };
141  
142 2 my $uri = $self->uri->clone;
143 2 $uri->query_form($params);
144  
145 2 return $uri;
146 }
147  
148 14 1;
149 __END__
« blib/lib/auto/share/dist/Amon2/flavor/Minimum/lib/__PATH__/Web/View.pm ↑ Summary blib/lib/Amon2/Setup/Flavor/Large.pm »