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.04'; |
6
|
|
|
|
|
|
|
|
7
|
1
|
|
|
1
|
|
66691
|
use Moo; |
|
1
|
|
|
|
|
11020
|
|
|
1
|
|
|
|
|
4
|
|
8
|
1
|
|
|
1
|
|
1453
|
use List::Util qw(first); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
568
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
has string => ( is => 'ro', required => 1 ); |
11
|
|
|
|
|
|
|
has values => ( is => 'ro', lazy => 1, default => \&_parse_string ); |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
sub match { |
14
|
52
|
|
|
52
|
1
|
19816
|
my ($self, @values_to_check) = @_; |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
@values_to_check = |
17
|
64
|
|
|
|
|
175
|
map{ lc $_ } |
18
|
52
|
100
|
|
|
|
115
|
grep{ defined $_ && length $_ } |
|
66
|
|
|
|
|
261
|
|
19
|
|
|
|
|
|
|
@values_to_check; |
20
|
|
|
|
|
|
|
|
21
|
52
|
100
|
|
|
|
154
|
return '' if !@values_to_check; |
22
|
|
|
|
|
|
|
|
23
|
43
|
50
|
|
|
|
63
|
my @charsets = @{ $self->values || [] }; |
|
43
|
|
|
|
|
1006
|
|
24
|
43
|
100
|
|
|
|
447
|
return $values_to_check[0] if !@charsets; |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
CHARSET: |
28
|
29
|
|
|
|
|
59
|
for my $charset ( @charsets ) { |
29
|
37
|
100
|
|
|
|
109
|
return $values_to_check[0] if $charset eq '*'; |
30
|
|
|
|
|
|
|
|
31
|
30
|
|
|
42
|
|
134
|
my $found = first { $_ eq $charset }@values_to_check; |
|
42
|
|
|
|
|
76
|
|
32
|
30
|
100
|
|
|
|
154
|
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
|
21
|
|
|
21
|
|
18802
|
my ($self) = @_; |
49
|
|
|
|
|
|
|
|
50
|
21
|
|
100
|
|
|
126
|
my @charsets = split /\s*,\s*/, $self->string // ''; |
51
|
21
|
|
|
|
|
37
|
my %weighted; |
52
|
|
|
|
|
|
|
|
53
|
21
|
|
|
|
|
48
|
for my $charset ( @charsets ) { |
54
|
21
|
|
|
|
|
58
|
my ($charset_name, $quality) = split /;/, $charset; |
55
|
|
|
|
|
|
|
|
56
|
21
|
|
100
|
|
|
119
|
my ($weight) = ($quality // 'q=1') =~ m{\Aq=(.*)\z}; |
57
|
21
|
|
|
|
|
36
|
push @{ $weighted{$weight} }, $charset_name; |
|
21
|
|
|
|
|
76
|
|
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
|
60
|
21
|
50
|
|
|
|
77
|
my @charset_names = map{ @{ $weighted{$_} || [] } } sort { $b <=> $a }keys %weighted; |
|
21
|
|
|
|
|
28
|
|
|
21
|
|
|
|
|
77
|
|
|
6
|
|
|
|
|
34
|
|
61
|
|
|
|
|
|
|
|
62
|
21
|
|
|
|
|
169
|
return \@charset_names; |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
1; |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
__END__ |