Decode/Encode/HTTP/Response/Parser.pm untested

filter: Statementstmt 0.0% 0 / 28 Branchbran 0.0% 0 / 8 Conditioncond 0.0% 0 / 10 MC/DCmcdc 0.0% 0 / 6 Subroutinesub 0.0% 0 / 5 Podpod 0.0% 0 / 3 totaltotal 0.0% 0 / 60 CC 5 SCAR 23.9
CC
5
Cov
0%
_parse_meta
20.0
extract_encodings
6.0
FOREIGNBUILDARGS
2.0
CRAP 10.9
1  
2 package Data::Decode::Encode::HTTP::Response::Parser;
3 use Moose;
4 use MooseX::NonMoose;
5  
6 extends 'HTML::Parser';
7  
8 sub FOREIGNBUILDARGS {
9 my ($class, %args) = @_;
10  
11 $args{api_version} ||= 3;
12 $args{start_h} ||= [ \&_parse_meta, "self, tagname, attr" ];
13 return %args;
14 }
15  
16 sub extract_encodings {
17 my $self = shift;
18  
19 my @encodings;
20 $self->utf8_mode(1);
21 $self->{encodings} = \@encodings;
22 $self->parse($_[0]);
23 $self->eof;
24 delete $self->{encodings};
25 return wantarray ? @encodings : \@encodings;
26 }
27  
28 sub _parse_meta
29 {
30 my ($self, $tag, $attrs) = @_;
31 return unless $tag eq 'meta';
32 return unless $attrs->{'http-equiv'} &&
33 lc($attrs->{'http-equiv'}) eq 'content-type';
34  
35 my $content = $attrs->{content};
36 if (defined $content && $content =~ /charset=([A-Za-z0-9_\-]+)/i) {
37 push @{ $self->{encodings} }, $1;
38 }
39 }
40  
41 1;
42  
43 __END__