blib/lib/HTML/HTML5/Parser/Charset/UniversalCharDet.pm

filter: Statementstmt 73.0% 19 / 26 Branchbran 25.0% 3 / 12 Conditioncond 33.3% 1 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 100% 5 / 5 Podpod 0.0% 0 / 1 totaltotal 57.1% 28 / 49 CC 8 SCAR 20.9
CC
8
Cov
56%
detect_byte_string
12.0
_detect
7.2
BEGIN
1.0
CRAP 8.1
« blib/lib/HTML/HTML5/Parser/Charset/WebLatin1.pm ↑ Summary
1 package HTML::HTML5::Parser::Charset::UniversalCharDet;
2  
3 ## skip Test::Tabs
4 9 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 9 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 9 ▶use IO::HTML ();
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 9 our $VERSION='0.991';
9 9 our $DEBUG;
10  
11 # this really shouldn't work, but for some reason it does...
12 sub _detect {
13 708 ▶ return +{ encoding => 'UTF-8' } if !utf8::is_utf8($_[0]); # huh?
Subroutine _detect: called CC=3 SCAR=19.8
Branch: 1 branch
BranchTrueFalseTotal
unless utf8::is_utf8($_[0]) 708 0 708
14 0 open my $fh, '<:raw', \$_[0];
15 0 my $e = IO::HTML::sniff_encoding($fh => 'string');
16 0 ▶ return +{ encoding => $e } if defined $e;
Branch: 1 branch
BranchTrueFalseTotal
if defined $e 0 0 0
17 0 return +{};
18 }
19  
20 sub detect_byte_string ($$) {
21 708 ▶ my $de;
Subroutine detect_byte_string: called CC=6 SCAR=24.8
Pod undocumented
22 eval {
23 708 $de = _detect $_[1];
24 708 1;
25 708 ▶ } or do {
Branch: 1 branch
BranchTrueFalseTotal
eval { do { $de = _detect($_[1]); 1 } } or do { warn $@ unless $HTML::HTML5::Parser::Charset::UniversalCharDet::DEBUG; die $@ if $HTML::HTML5::Parser::Charset::UniversalCharDet::DEBUG } 0 708 708
26 0 ▶ warn $@ unless $DEBUG;
Branch: 1 branch
BranchTrueFalseTotal
unless $HTML::HTML5::Parser::Charset::UniversalCharDet::DEBUG 0 0 0
27 0 ▶ die $@ if $DEBUG;
Branch: 1 branch
BranchTrueFalseTotal
if $HTML::HTML5::Parser::Charset::UniversalCharDet::DEBUG 0 0 0
28 };
29 708 ▶ if (defined $de and defined $de->{encoding}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $de and defined $de->{'encoding'}) { } 708 0 708
Condition33%1/3
defined $de and defined $de->{"encoding"}
!ll&&!rl&&r
00708
MC/DC0%0/2
defined $de and defined $de->{"encoding"}
defined $de defined $de->{"encoding"}
Truth table33%1/3
A and B
A= defined $deB= defined $de->{"encoding"}
ABresult
0X0
100
111
30 708 return lc $de->{encoding};
31 } else {
32 0 return undef;
33 }
34 } # detect_byte_string
35  
36 #Copyright 2007-2011 Wakaba <w@suika.fam.cx>
37 #Copyright 2009-2012 Toby Inkster <tobyink@cpan.org>
38 #
39 #This library is free software; you can redistribute it
40 #and/or modify it under the same terms as Perl itself.
41  
42 9 1;
« blib/lib/HTML/HTML5/Parser/Charset/WebLatin1.pm ↑ Summary