| 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
Condition66%2/3
$self->type eq "*/*" and $self->params_are_empty
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
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 27 | 4 | ▶ | $other->type eq $self->type && _compare_params( $self->params, $other->params ) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$other->type eq $self->type and _compare_params($self->params, $other->params)
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)
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 35 | 10 | ▶ | $self->type_matches( $other ) && _compare_params( $self->params, $other->params ) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$self->type_matches($other) and _compare_params($self->params, $other->params)
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)
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 43 | 67 | ▶ | $self->type_matches( $other ) && $self->params_match( $other->params ) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$self->type_matches($other) and $self->params_match($other->params)
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)
| |||||||||||||||||||||||||||||||||||||||||||
| 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
Condition83%5/6
$other->type eq "*" or $other->type eq "*/*" or $other->type eq $self->type
$other->type eq "*" or $other->type eq "*/*"
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
| |||||||||||||||||||||||||||||||||||||||||||
| 52 | 44 | ▶ | $other->major eq $self->major && $other->minor eq '*' | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$other->major eq $self->major and $other->minor eq "*"
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 "*"
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 61 | 16 | ▶ | return 0 if not exists $params->{ $k }; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 62 | 6 | ▶ | return 0 if $params->{ $k } ne $other->{ $k }; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||||||||||||||||
| 76 | 12 | foreach my $i ( 0 .. $#left_keys ) { | |||||||||||||||||||||||||||||||||||||||||
| 77 | 12 | ▶ | return 0 unless $left_keys[$i] eq $right_keys[$i]; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 78 | 12 | ▶ | return 0 unless $left->{ $left_keys[$i] } eq $right->{ $right_keys[$i] }; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 79 | } | ||||||||||||||||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||||||||||||||||
| 81 | 10 | return 1; | |||||||||||||||||||||||||||||||||||||||||
| 82 | } | ||||||||||||||||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||||||||||||||||
| 84 | 9 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||||||||||||||||
| 86 | __END__ | ||||||||||||||||||||||||||||||||||||||||||