line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package HTTP::AcceptCharset; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
# ABSTRACT: Parse the HTTP header 'Accept-Charset' |
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
our $VERSION = '0.03'; |
6
|
|
|
|
|
|
|
|
7
|
1
|
|
|
1
|
|
67391
|
use Moo; |
|
1
|
|
|
|
|
11283
|
|
|
1
|
|
|
|
|
5
|
|
8
|
1
|
|
|
1
|
|
1417
|
use List::Util qw(first); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
581
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
has string => ( is => 'ro', required => 1 ); |
11
|
|
|
|
|
|
|
has values => ( is => 'ro', lazy => 1, default => \&_parse_string ); |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
sub match { |
14
|
44
|
|
|
44
|
1
|
16356
|
my ($self, @values_to_check) = @_; |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
@values_to_check = |
17
|
54
|
|
|
|
|
143
|
map{ lc $_ } |
18
|
44
|
100
|
|
|
|
92
|
grep{ defined $_ && length $_ } |
|
56
|
|
|
|
|
238
|
|
19
|
|
|
|
|
|
|
@values_to_check; |
20
|
|
|
|
|
|
|
|
21
|
44
|
100
|
|
|
|
123
|
return '' if !@values_to_check; |
22
|
|
|
|
|
|
|
|
23
|
36
|
50
|
|
|
|
64
|
my @charsets = @{ $self->values || [] }; |
|
36
|
|
|
|
|
842
|
|
24
|
36
|
100
|
|
|
|
373
|
return $values_to_check[0] if !@charsets; |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
CHARSET: |
28
|
29
|
|
|
|
|
62
|
for my $charset ( @charsets ) { |
29
|
37
|
100
|
|
|
|
108
|
return $values_to_check[0] if $charset eq '*'; |
30
|
|
|
|
|
|
|
|
31
|
30
|
|
|
42
|
|
124
|
my $found = first { $_ eq $charset }@values_to_check; |
|
42
|
|
|
|
|
79
|
|
32
|
30
|
100
|
|
|
|
158
|
return $found if $found; |
33
|
|
|
|
|
|
|
} |
34
|
|
|
|
|
|
|
|
35
|
9
|
|
|
|
|
41
|
return ''; |
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
around BUILDARGS => sub { |
39
|
|
|
|
|
|
|
my ($orig, $class, @args) = @_; |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
return { string => $args[0] } |
42
|
|
|
|
|
|
|
if @args == 1 && !ref $args[0]; |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
return $class->$orig(@args); |
45
|
|
|
|
|
|
|
}; |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
sub _parse_string { |
48
|
18
|
|
|
18
|
|
16537
|
my ($self) = @_; |
49
|
|
|
|
|
|
|
|
50
|
18
|
|
|
|
|
87
|
my @charsets = split /\s*,\s*/, $self->string; |
51
|
18
|
|
|
|
|
38
|
my %weighted; |
52
|
|
|
|
|
|
|
|
53
|
18
|
|
|
|
|
37
|
for my $charset ( @charsets ) { |
54
|
21
|
|
|
|
|
54
|
my ($charset_name, $quality) = split /;/, $charset; |
55
|
|
|
|
|
|
|
|
56
|
21
|
|
100
|
|
|
121
|
my ($weight) = ($quality // 'q=1') =~ m{\Aq=(.*)\z}; |
57
|
21
|
|
|
|
|
38
|
push @{ $weighted{$weight} }, $charset_name; |
|
21
|
|
|
|
|
90
|
|
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
|
60
|
18
|
50
|
|
|
|
68
|
my @charset_names = map{ @{ $weighted{$_} || [] } } sort { $b <=> $a }keys %weighted; |
|
21
|
|
|
|
|
29
|
|
|
21
|
|
|
|
|
80
|
|
|
6
|
|
|
|
|
39
|
|
61
|
|
|
|
|
|
|
|
62
|
18
|
|
|
|
|
116
|
return \@charset_names; |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
1; |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
__END__ |