ActionPack/MediaType.pm

filter: Statementstmt 100% 48 / 48 Branchbran 86.6% 26 / 30 Conditioncond 80.9% 17 / 21 MC/DCmcdc 69.2% 9 / 13 Subroutinesub 100% 14 / 14 Podpod 100% 9 / 9 totaltotal 91.1% 123 / 135 CC 25 SCAR 13.9
CC
25
Cov
92%
type_matches
6.0
_compare_params
5.0
params_match
5.0
CRAP 4.0
« ActionPack.pm ↑ Summary ActionPack/MediaTypeList.pm »
1 package HTTP::Headers::ActionPack::MediaType;
2 # ABSTRACT: A Media Type
3  
4 9 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 9 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 9 our $VERSION = '0.10';
8  
9 9 ▶use Scalar::Util qw[ blessed ];
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 9 ▶use parent 'HTTP::Headers::ActionPack::Core::BaseHeaderType';
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 577 ▶sub type { (shift)->subject }
Subroutine type: called CC=1 SCAR=0.0
Pod documented
14 90 ▶sub major { (split '/' => (shift)->type)[0] }
Subroutine major: called CC=1 SCAR=0.0
Pod documented
15 80 ▶sub minor { (split '/' => (shift)->type)[1] }
Subroutine minor: called CC=1 SCAR=0.0
Pod documented
16  
17 90 ▶sub matches_all {
Subroutine matches_all: called CC=3 SCAR=11.1
Pod documented
18 90 my $self = shift;
19 90 ▶ $self->type eq '*/*' && $self->params_are_empty
Branch: 1 branch
BranchTrueFalseTotal
$self->type eq '*/*' && $self->params_are_empty ? : 14 76 90
Condition66%2/3
$self->type eq "*/*" and $self->params_are_empty
!ll&&!rl&&r
76014
MC/DC50%1/2
$self->type eq "*/*" and $self->params_are_empty
$self->type eq "*/*" $self->params_are_empty
Truth table66%2/3
A and B
A= $self->type eq "*/*"B= $self->params_are_empty
ABresult
0X0
100
111
20 ? 1 : 0;
21 }
22  
23 # must be exactly the same
24 4 ▶sub equals {
Subroutine equals: called CC=4 SCAR=14.9
Pod documented
25 4 my ($self, $other) = @_;
26 4 ▶ $other = (ref $self)->new_from_string( $other ) unless blessed $other;
Branch: 1 branch
BranchTrueFalseTotal
unless builtin::blessed($other) 2 2 4
27 4 ▶ $other->type eq $self->type && _compare_params( $self->params, $other->params )
Branch: 1 branch
BranchTrueFalseTotal
$other->type eq $self->type && _compare_params($self->params, $other->params) ? : 4 0 4
Condition33%1/3
$other->type eq $self->type and _compare_params($self->params, $other->params)
!ll&&!rl&&r
004
MC/DC0%0/2
$other->type eq $self->type and _compare_params($self->params, $other->params)
$other->type eq $self->type _compare_params($self->params, $other->params)
Truth table33%1/3
A and B
A= $other->type eq $self->typeB= _compare_params($self->params, $other->params)
ABresult
0X0
100
111
28 ? 1 : 0;
29 }
30  
31 # types must be compatible and params much match exactly
32 10 ▶sub exact_match {
Subroutine exact_match: called CC=4 SCAR=13.9
Pod documented
33 10 my ($self, $other) = @_;
34 10 ▶ $other = (ref $self)->new_from_string( $other ) unless blessed $other;
Branch: 1 branch
BranchTrueFalseTotal
unless builtin::blessed($other) 10 0 10
35 10 ▶ $self->type_matches( $other ) && _compare_params( $self->params, $other->params )
Branch: 1 branch
BranchTrueFalseTotal
$self->type_matches($other) && _compare_params($self->params, $other->params) ? : 6 4 10
Condition100%3/3
$self->type_matches($other) and _compare_params($self->params, $other->params)
!ll&&!rl&&r
226
MC/DC100%2/2
$self->type_matches($other) and _compare_params($self->params, $other->params)
$self->type_matches($other) _compare_params($self->params, $other->params)
Truth table100%3/3
A and B
A= $self->type_matches($other)B= _compare_params($self->params, $other->params)
ABresult
0X0
100
111
36 ? 1 : 0;
37 }
38  
39 # types must be be compatible and params should align
40 67 ▶sub match {
Subroutine match: called CC=4 SCAR=13.9
Pod documented
41 67 my ($self, $other) = @_;
42 67 ▶ $other = (ref $self)->new_from_string( $other ) unless blessed $other;
Branch: 1 branch
BranchTrueFalseTotal
unless builtin::blessed($other) 12 55 67
43 67 ▶ $self->type_matches( $other ) && $self->params_match( $other->params )
Branch: 1 branch
BranchTrueFalseTotal
$self->type_matches($other) && $self->params_match($other->params) ? : 19 48 67
Condition100%3/3
$self->type_matches($other) and $self->params_match($other->params)
!ll&&!rl&&r
371119
MC/DC100%2/2
$self->type_matches($other) and $self->params_match($other->params)
$self->type_matches($other) $self->params_match($other->params)
Truth table100%3/3
A and B
A= $self->type_matches($other)B= $self->params_match($other->params)
ABresult
0X0
100
111
44 ? 1 : 0;
45 }
46  
47 ## ...
48  
49 77 ▶sub type_matches {
Subroutine type_matches: called CC=6 SCAR=17.9
Pod documented
50 77 my ($self, $other) = @_;
51 77 ▶ return 1 if $other->type eq '*' || $other->type eq '*/*' || $other->type eq $self->type;
Branch: 1 branch
BranchTrueFalseTotal
if $other->type eq "*" or $other->type eq "*/*" or $other->type eq $self->type 33 44 77
Condition83%5/6
$other->type eq "*" or $other->type eq "*/*" or $other->type eq $self->type
l!l&&r!l&&!r
42944
$other->type eq "*" or $other->type eq "*/*"
l!l&&r!l&&!r
0473
MC/DC66%2/3
$other->type eq "*" or $other->type eq "*/*" or $other->type eq $self->type
$other->type eq "*" $other->type eq "*/*" $other->type eq $self->type
Truth table75%3/4
A or B or C
A= $other->type eq "*"B= $other->type eq "*/*"C= $other->type eq $self->type
ABCresult
1XX1
01X1
0011
0000
52 44 ▶ $other->major eq $self->major && $other->minor eq '*'
Branch: 1 branch
BranchTrueFalseTotal
$other->major eq $self->major && $other->minor eq '*' ? : 5 39 44
Condition100%3/3
$other->major eq $self->major and $other->minor eq "*"
!ll&&!rl&&r
6335
MC/DC100%2/2
$other->major eq $self->major and $other->minor eq "*"
$other->major eq $self->major $other->minor eq "*"
Truth table100%3/3
A and B
A= $other->major eq $self->majorB= $other->minor eq "*"
ABresult
0X0
100
111
53 ? 1 : 0;
54 }
55  
56 30 ▶sub params_match {
Subroutine params_match: called CC=5 SCAR=16.1
Pod documented
57 30 my ($self, $other) = @_;
58 30 my $params = $self->params;
59 30 foreach my $k ( keys %$other ) {
60 20 ▶ next if $k eq 'q';
Branch: 1 branch
BranchTrueFalseTotal
if $k eq "q" 4 16 20
61 16 ▶ return 0 if not exists $params->{ $k };
Branch: 1 branch
BranchTrueFalseTotal
unless exists $params->{$k} 10 6 16
62 6 ▶ return 0 if $params->{ $k } ne $other->{ $k };
Branch: 1 branch
BranchTrueFalseTotal
if $params->{$k} ne $other->{$k} 1 5 6
63 }
64 19 return 1;
65 }
66  
67 ## ...
68  
69 12 ▶sub _compare_params {
Subroutine _compare_params: called CC=5 SCAR=16.2
70 12 my ($left, $right) = @_;
71 12 my @left_keys = sort grep { $_ ne 'q' } keys %$left;
72 12 my @right_keys = sort grep { $_ ne 'q' } keys %$right;
73  
74 12 ▶ return 0 unless (scalar @left_keys) == (scalar @right_keys);
Branch: 1 branch
BranchTrueFalseTotal
unless scalar @left_keys == scalar @right_keys 0 12 12
75  
76 12 foreach my $i ( 0 .. $#left_keys ) {
77 12 ▶ return 0 unless $left_keys[$i] eq $right_keys[$i];
Branch: 1 branch
BranchTrueFalseTotal
unless $left_keys[$i] eq $right_keys[$i] 0 12 12
78 12 ▶ return 0 unless $left->{ $left_keys[$i] } eq $right->{ $right_keys[$i] };
Branch: 1 branch
BranchTrueFalseTotal
unless $$left{$left_keys[$i]} eq $$right{$right_keys[$i]} 2 10 12
79 }
80  
81 10 return 1;
82 }
83  
84 9 1;
85  
86 __END__
« ActionPack.pm ↑ Summary ActionPack/MediaTypeList.pm »