blib/lib/Catalyst/Plugin/OrderedParams.pm

filter: Statementstmt 79.2% 42 / 53 Branchbran 30.0% 6 / 20 Conditioncond 60.0% 3 / 5 MC/DCmcdc 33.3% 1 / 3 Subroutinesub 100% 5 / 5 Podpod 0.0% 0 / 2 totaltotal 64.7% 57 / 88 CC 13 SCAR 29.1
CC
13
Cov
65%
prepare_body
27.2
prepare_request
3.0
BEGIN
1.0
CRAP 18.3
↑ Summary
1 package Catalyst::Plugin::OrderedParams;
2  
3 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use NEXT;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 2 ▶use Tie::Hash::Indexed;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 2 ▶if ( Catalyst->VERSION ge '5.49' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ("Catalyst"->VERSION ge "5.49") 2 0 2
8 2 require HTTP::Body;
9 }
10  
11 2 our $VERSION = '0.06';
12  
13 2 ▶sub prepare_request {
Subroutine prepare_request: called CC=3 SCAR=11.1
Pod undocumented
14 2 my $c = shift;
15
16 # make sure the params hash hasn't already been touched by another plugin
17 2 ▶ if ( scalar keys %{ $c->req->{parameters} } ) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar keys %{$c->req->{'parameters'};}) { } 0 2 2
18 0 $c->log->error( "OrderedParams: Request parameters have already been "
19 . "set/modified. Please load the OrderedParams plugin "
20 . "before all other plugins." );
21 }
22 else {
23 2 my $params = {};
24 2 tie %{$params}, 'Tie::Hash::Indexed';
25 2 $c->req->{parameters} = $params;
26  
27 2 ▶ if ( Catalyst->VERSION ge '5.49' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ("Catalyst"->VERSION ge "5.49") 2 0 2
28 2 my $query_params = {};
29 2 tie %{$query_params}, 'Tie::Hash::Indexed';
30 2 $c->req->{query_parameters} = $query_params;
31 }
32 }
33  
34 2 return $c->NEXT::prepare_request(@_);
35 }
36  
37 2 ▶sub prepare_body {
Subroutine prepare_body: called CC=11 SCAR=33.0
Pod undocumented
38 2 my $c = shift;
39
40 2 ▶ return $c->NEXT::prepare_body(@_) if Catalyst->VERSION lt '5.49';
Branch: 1 branch
BranchTrueFalseTotal
if "Catalyst"->VERSION lt "5.49" 0 2 2
41
42 # due to complex interactions in 5.5 this method has to be overridden
43 # instead of extended.
44
45 2 ▶ if ( defined $c->request->{_body} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $c->request->{"_body"}) 0 2 2
46 # We may not have a body to process if it was a GET request
47 0 ▶ return if !ref $c->request->{_body};
Branch: 1 branch
BranchTrueFalseTotal
unless ref $c->request->{"_body"} 0 0 0
48  
49 # have we already built the object?
50 0 ▶ return if defined $c->request->{_body}->{ordered};
Branch: 1 branch
BranchTrueFalseTotal
if defined $c->request->{"_body"}{"ordered"} 0 0 0
51 }
52  
53 # for 5.5+, we create a new HTTP::Body instance with indexed hashes.
54 2 ▶ my $length = $c->req->header('Content-Length') || 0;
Condition100%2/2
$c->req->header('Content-Length') || 0
l!l
11
MC/DC100%1/1
$c->req->header('Content-Length') || 0
$c->req->header('Content-Length')
Truth table100%2/2
A
A= $c->req->header('Content-Length')
Aresult
11
00
55 2 my $type = $c->req->header('Content-Type');
56 2 my $body = HTTP::Body->new( $type, $length );
57
58 2 tie %{ $body->{param} }, 'Tie::Hash::Indexed';
59 2 tie %{ $body->{upload} }, 'Tie::Hash::Indexed';
60 2 $body->{ordered} = 1;
61
62 2 $c->req->{_body} = $body;
63  
64 # Initialize on-demand data
65 2 $c->engine->prepare_body( $c, @_ );
66 2 $c->prepare_parameters;
67 2 $c->prepare_uploads;
68  
69 0 ▶ if ( $c->debug && keys %{ $c->req->body_parameters } ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($c->debug and keys %{$c->req->body_parameters;}) 0 2 2
Condition33%1/3
$c->debug and keys %{$c->req->body_parameters;}
!ll&&!rl&&r
200
MC/DC0%0/2
$c->debug and keys %{$c->req->body_parameters;}
$c->debug keys %{$c->req->body_parameters;}
Truth table33%1/3
A and B
A= $c->debugB= keys %{$c->req->body_parameters;}
ABresult
0X0
100
111
70 0 my $t = Text::SimpleTable->new( [ 37, 'Key' ], [ 36, 'Value' ] );
71 0 for my $key ( sort keys %{ $c->req->body_parameters } ) {
72 0 my $param = $c->req->body_parameters->{$key};
73 0 ▶ my $value = defined($param) ? $param : '';
Branch: 1 branch
BranchTrueFalseTotal
defined $param ? : 0 0 0
74 0 ▶ $t->row( $key,
Branch: 1 branch
BranchTrueFalseTotal
ref $value eq 'ARRAY' ? : 0 0 0
75 ref $value eq 'ARRAY' ? ( join ', ', @$value ) : $value );
76 }
77 0 $c->log->debug( "Body Parameters are:\n" . $t->draw );
78 }
79 }
80  
81 2 1;
82 __END__
↑ Summary