line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package HTTP::Headers::ActionPack::MediaType; |
2
|
|
|
|
|
|
|
BEGIN { |
3
|
10
|
|
|
10
|
|
42373
|
$HTTP::Headers::ActionPack::MediaType::AUTHORITY = 'cpan:STEVAN'; |
4
|
|
|
|
|
|
|
} |
5
|
|
|
|
|
|
|
{ |
6
|
|
|
|
|
|
|
$HTTP::Headers::ActionPack::MediaType::VERSION = '0.09'; |
7
|
|
|
|
|
|
|
} |
8
|
|
|
|
|
|
|
# ABSTRACT: A Media Type |
9
|
|
|
|
|
|
|
|
10
|
10
|
|
|
10
|
|
67
|
use strict; |
|
10
|
|
|
|
|
20
|
|
|
10
|
|
|
|
|
335
|
|
11
|
10
|
|
|
10
|
|
53
|
use warnings; |
|
10
|
|
|
|
|
19
|
|
|
10
|
|
|
|
|
351
|
|
12
|
|
|
|
|
|
|
|
13
|
10
|
|
|
10
|
|
55
|
use Scalar::Util qw[ blessed ]; |
|
10
|
|
|
|
|
29
|
|
|
10
|
|
|
|
|
697
|
|
14
|
|
|
|
|
|
|
|
15
|
10
|
|
|
10
|
|
3951
|
use parent 'HTTP::Headers::ActionPack::Core::BaseHeaderType'; |
|
10
|
|
|
|
|
1552
|
|
|
10
|
|
|
|
|
67
|
|
16
|
|
|
|
|
|
|
|
17
|
577
|
|
|
577
|
1
|
2347
|
sub type { (shift)->subject } |
18
|
90
|
|
|
90
|
1
|
184
|
sub major { (split '/' => (shift)->type)[0] } |
19
|
80
|
|
|
80
|
1
|
192
|
sub minor { (split '/' => (shift)->type)[1] } |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
sub matches_all { |
22
|
90
|
|
|
90
|
1
|
122
|
my $self = shift; |
23
|
90
|
100
|
66
|
|
|
181
|
$self->type eq '*/*' && $self->params_are_empty |
24
|
|
|
|
|
|
|
? 1 : 0; |
25
|
|
|
|
|
|
|
} |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
# must be exactly the same |
28
|
|
|
|
|
|
|
sub equals { |
29
|
4
|
|
|
4
|
1
|
9
|
my ($self, $other) = @_; |
30
|
4
|
100
|
|
|
|
26
|
$other = (ref $self)->new_from_string( $other ) unless blessed $other; |
31
|
4
|
50
|
33
|
|
|
15
|
$other->type eq $self->type && _compare_params( $self->params, $other->params ) |
32
|
|
|
|
|
|
|
? 1 : 0; |
33
|
|
|
|
|
|
|
} |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
# types must be compatible and params much match exactly |
36
|
|
|
|
|
|
|
sub exact_match { |
37
|
10
|
|
|
10
|
1
|
20
|
my ($self, $other) = @_; |
38
|
10
|
50
|
|
|
|
62
|
$other = (ref $self)->new_from_string( $other ) unless blessed $other; |
39
|
10
|
100
|
100
|
|
|
28
|
$self->type_matches( $other ) && _compare_params( $self->params, $other->params ) |
40
|
|
|
|
|
|
|
? 1 : 0; |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
# types must be be compatible and params should align |
44
|
|
|
|
|
|
|
sub match { |
45
|
67
|
|
|
67
|
1
|
118
|
my ($self, $other) = @_; |
46
|
67
|
100
|
|
|
|
250
|
$other = (ref $self)->new_from_string( $other ) unless blessed $other; |
47
|
67
|
100
|
100
|
|
|
169
|
$self->type_matches( $other ) && $self->params_match( $other->params ) |
48
|
|
|
|
|
|
|
? 1 : 0; |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
## ... |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
sub type_matches { |
54
|
77
|
|
|
77
|
1
|
102
|
my ($self, $other) = @_; |
55
|
77
|
100
|
66
|
|
|
146
|
return 1 if $other->type eq '*' || $other->type eq '*/*' || $other->type eq $self->type; |
|
|
|
100
|
|
|
|
|
56
|
44
|
100
|
100
|
|
|
109
|
$other->major eq $self->major && $other->minor eq '*' |
57
|
|
|
|
|
|
|
? 1 : 0; |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
sub params_match { |
61
|
30
|
|
|
30
|
1
|
43
|
my ($self, $other) = @_; |
62
|
30
|
|
|
|
|
80
|
my $params = $self->params; |
63
|
30
|
|
|
|
|
95
|
foreach my $k ( keys %$other ) { |
64
|
21
|
100
|
|
|
|
61
|
next if $k eq 'q'; |
65
|
17
|
100
|
|
|
|
115
|
return 0 if not exists $params->{ $k }; |
66
|
6
|
50
|
|
|
|
22
|
return 0 if $params->{ $k } ne $other->{ $k }; |
67
|
|
|
|
|
|
|
} |
68
|
19
|
|
|
|
|
214
|
return 1; |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
## ... |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
sub _compare_params { |
74
|
12
|
|
|
12
|
|
18
|
my ($left, $right) = @_; |
75
|
12
|
|
|
|
|
33
|
my @left_keys = sort grep { $_ ne 'q' } keys %$left; |
|
12
|
|
|
|
|
48
|
|
76
|
12
|
|
|
|
|
30
|
my @right_keys = sort grep { $_ ne 'q' } keys %$right; |
|
12
|
|
|
|
|
31
|
|
77
|
|
|
|
|
|
|
|
78
|
12
|
50
|
|
|
|
44
|
return 0 unless (scalar @left_keys) == (scalar @right_keys); |
79
|
|
|
|
|
|
|
|
80
|
12
|
|
|
|
|
102
|
foreach my $i ( 0 .. $#left_keys ) { |
81
|
12
|
50
|
|
|
|
32
|
return 0 unless $left_keys[$i] eq $right_keys[$i]; |
82
|
12
|
100
|
|
|
|
74
|
return 0 unless $left->{ $left_keys[$i] } eq $right->{ $right_keys[$i] }; |
83
|
|
|
|
|
|
|
} |
84
|
|
|
|
|
|
|
|
85
|
10
|
|
|
|
|
106
|
return 1; |
86
|
|
|
|
|
|
|
} |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
1; |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
__END__ |