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.02'; |
6
|
|
|
|
|
|
|
|
7
|
1
|
|
|
1
|
|
66203
|
use Moo; |
|
1
|
|
|
|
|
11493
|
|
|
1
|
|
|
|
|
6
|
|
8
|
1
|
|
|
1
|
|
1413
|
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
|
34
|
|
|
34
|
1
|
12089
|
my ($self, @values_to_check) = @_; |
15
|
|
|
|
|
|
|
|
16
|
34
|
100
|
|
|
|
108
|
return '' if !@values_to_check; |
17
|
29
|
100
|
|
|
|
73
|
return '' if !defined $values_to_check[0]; |
18
|
|
|
|
|
|
|
|
19
|
28
|
50
|
|
|
|
39
|
my @charsets = @{ $self->values || [] }; |
|
28
|
|
|
|
|
631
|
|
20
|
28
|
50
|
|
|
|
269
|
return $values_to_check[0] if !@charsets; |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
CHARSET: |
23
|
28
|
|
|
|
|
56
|
for my $charset ( @charsets ) { |
24
|
36
|
100
|
|
|
|
126
|
return $values_to_check[0] if $charset eq '*'; |
25
|
|
|
|
|
|
|
|
26
|
31
|
|
|
43
|
|
148
|
my $found = first { $_ eq $charset }@values_to_check; |
|
43
|
|
|
|
|
81
|
|
27
|
31
|
100
|
|
|
|
150
|
return $found if $found; |
28
|
|
|
|
|
|
|
} |
29
|
|
|
|
|
|
|
|
30
|
10
|
|
|
|
|
47
|
return ''; |
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
around BUILDARGS => sub { |
34
|
|
|
|
|
|
|
my ($orig, $class, @args) = @_; |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
return { string => $args[0] } |
37
|
|
|
|
|
|
|
if @args == 1 && !ref $args[0]; |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
return $class->$orig(@args); |
40
|
|
|
|
|
|
|
}; |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
sub _parse_string { |
43
|
15
|
|
|
15
|
|
13636
|
my ($self) = @_; |
44
|
|
|
|
|
|
|
|
45
|
15
|
|
|
|
|
74
|
my @charsets = split /\s*,\s*/, $self->string; |
46
|
15
|
|
|
|
|
29
|
my %weighted; |
47
|
|
|
|
|
|
|
|
48
|
15
|
|
|
|
|
31
|
for my $charset ( @charsets ) { |
49
|
21
|
|
|
|
|
59
|
my ($charset_name, $quality) = split /;/, $charset; |
50
|
|
|
|
|
|
|
|
51
|
21
|
|
100
|
|
|
124
|
my ($weight) = ($quality // 'q=1') =~ m{\Aq=(.*)\z}; |
52
|
21
|
|
|
|
|
35
|
push @{ $weighted{$weight} }, $charset_name; |
|
21
|
|
|
|
|
74
|
|
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
|
55
|
15
|
50
|
|
|
|
53
|
my @charset_names = map{ @{ $weighted{$_} || [] } } sort { $b <=> $a }keys %weighted; |
|
21
|
|
|
|
|
32
|
|
|
21
|
|
|
|
|
76
|
|
|
6
|
|
|
|
|
34
|
|
56
|
|
|
|
|
|
|
|
57
|
15
|
|
|
|
|
104
|
return \@charset_names; |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
1; |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
__END__ |