File Coverage

blib/lib/HTTP/Headers/ActionPack/AcceptCharset.pm
Criterion Covered Total %
statement 21 21 100.0
branch 6 8 75.0
condition 3 3 100.0
subroutine 7 7 100.0
pod 2 2 100.0
total 39 41 95.1


line stmt bran cond sub pod time code
1             package HTTP::Headers::ActionPack::AcceptCharset;
2             BEGIN {
3 1     1   930 $HTTP::Headers::ActionPack::AcceptCharset::AUTHORITY = 'cpan:STEVAN';
4             }
5             {
6             $HTTP::Headers::ActionPack::AcceptCharset::VERSION = '0.09';
7             }
8             # ABSTRACT: A Priority List customized for Media Types
9              
10 1     1   7 use strict;
  1         2  
  1         33  
11 1     1   12 use warnings;
  1         5  
  1         35  
12              
13 1     1   1223 use Encode qw[ find_encoding ];
  1         415974  
  1         257  
14              
15 1     1   1432 use parent 'HTTP::Headers::ActionPack::PriorityList';
  1         666  
  1         5  
16              
17             sub new_from_string {
18 13     13 1 369 my $self = shift->SUPER::new_from_string(@_);
19             # From RFC-2616 sec14.2
20             # If no "*" is present in an Accept-Charset
21             # field, then all character sets not explicitly
22             # mentioned get a quality value of 0, except for
23             # ISO-8859-1, which gets a quality value of 1
24             # if not explicitly mentioned.
25 13 100 100     38 unless ( defined $self->priority_of('*')
26             || defined $self->priority_of('ISO-8859-1') ) {
27              
28 4         12 $self->add( 1 => 'ISO-8859-1' );
29             }
30              
31 13         43 return $self;
32             }
33              
34             sub canonicalize_choice {
35 121 50   121 1 217 return unless defined $_[1];
36 121 100       257 return '*' if $_[1] eq '*';
37 93 50       224 my $charset = find_encoding($_[1])
38             or return;
39 93         7818 return $charset->mime_name;
40             }
41              
42             1;
43              
44             __END__