ActionPack/MediaType.pm

filter: Statementstmt 100% 50 / 50 Branchbran 83.3% 25 / 30 Conditioncond 80.9% 17 / 21 MC/DCmcdc 69.2% 9 / 13 Subroutinesub 100% 15 / 15 Podpod 100% 9 / 9 totaltotal 90.5% 125 / 138 CC 25 SCAR 13.7
CC
25
Cov
91%
type_matches
6.0
_compare_params
5.0
params_match
5.0
CRAP 3.9
« ActionPack/ContentNegotiation.pm ↑ Summary ActionPack.pm »
1 package HTTP::Headers::ActionPack::MediaType;
2 10 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
3 10 $HTTP::Headers::ActionPack::MediaType::AUTHORITY = 'cpan:STEVAN';
4 }
5 {
6 10 $HTTP::Headers::ActionPack::MediaType::VERSION = '0.09';
7 }
8 # ABSTRACT: A Media Type
9  
10 10 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 10 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 10 ▶use Scalar::Util qw[ blessed ];
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 10 ▶use parent 'HTTP::Headers::ActionPack::Core::BaseHeaderType';
Subroutine BEGIN: called CC=1 SCAR=0.0
16  
17 577 ▶sub type { (shift)->subject }
Subroutine type: called CC=1 SCAR=0.0
Pod documented
18 90 ▶sub major { (split '/' => (shift)->type)[0] }
Subroutine major: called CC=1 SCAR=0.0
Pod documented
19 80 ▶sub minor { (split '/' => (shift)->type)[1] }
Subroutine minor: called CC=1 SCAR=0.0
Pod documented
20  
21 90 ▶sub matches_all {
Subroutine matches_all: called CC=3 SCAR=11.1
Pod documented
22 90 my $self = shift;
23 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
24 ? 1 : 0;
25 }
26  
27 # must be exactly the same
28 4 ▶sub equals {
Subroutine equals: called CC=4 SCAR=14.9
Pod documented
29 4 my ($self, $other) = @_;
30 4 ▶ $other = (ref $self)->new_from_string( $other ) unless blessed $other;
Branch: 1 branch
BranchTrueFalseTotal
unless builtin::blessed($other) 2 2 4
31 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
32 ? 1 : 0;
33 }
34  
35 # types must be compatible and params much match exactly
36 10 ▶sub exact_match {
Subroutine exact_match: called CC=4 SCAR=13.9
Pod documented
37 10 my ($self, $other) = @_;
38 10 ▶ $other = (ref $self)->new_from_string( $other ) unless blessed $other;
Branch: 1 branch
BranchTrueFalseTotal
unless builtin::blessed($other) 10 0 10
39 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
40 ? 1 : 0;
41 }
42  
43 # types must be be compatible and params should align
44 67 ▶sub match {
Subroutine match: called CC=4 SCAR=13.9
Pod documented
45 67 my ($self, $other) = @_;
46 67 ▶ $other = (ref $self)->new_from_string( $other ) unless blessed $other;
Branch: 1 branch
BranchTrueFalseTotal
unless builtin::blessed($other) 12 55 67
47 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
48 ? 1 : 0;
49 }
50  
51 ## ...
52  
53 77 ▶sub type_matches {
Subroutine type_matches: called CC=6 SCAR=17.9
Pod documented
54 77 my ($self, $other) = @_;
55 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
56 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
57 ? 1 : 0;
58 }
59  
60 30 ▶sub params_match {
Subroutine params_match: called CC=5 SCAR=16.1
Pod documented
61 30 my ($self, $other) = @_;
62 30 my $params = $self->params;
63 30 foreach my $k ( keys %$other ) {
64 19 ▶ next if $k eq 'q';
Branch: 1 branch
BranchTrueFalseTotal
if $k eq "q" 4 15 19
65 15 ▶ return 0 if not exists $params->{ $k };
Branch: 1 branch
BranchTrueFalseTotal
unless exists $params->{$k} 11 4 15
66 4 ▶ return 0 if $params->{ $k } ne $other->{ $k };
Branch: 1 branch
BranchTrueFalseTotal
if $params->{$k} ne $other->{$k} 0 4 4
67 }
68 19 return 1;
69 }
70  
71 ## ...
72  
73 12 ▶sub _compare_params {
Subroutine _compare_params: called CC=5 SCAR=16.2
74 12 my ($left, $right) = @_;
75 12 my @left_keys = sort grep { $_ ne 'q' } keys %$left;
76 12 my @right_keys = sort grep { $_ ne 'q' } keys %$right;
77  
78 12 ▶ return 0 unless (scalar @left_keys) == (scalar @right_keys);
Branch: 1 branch
BranchTrueFalseTotal
unless scalar @left_keys == scalar @right_keys 0 12 12
79  
80 12 foreach my $i ( 0 .. $#left_keys ) {
81 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
82 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
83 }
84  
85 10 return 1;
86 }
87  
88 10 1;
89  
90 __END__
« ActionPack/ContentNegotiation.pm ↑ Summary ActionPack.pm »