Miner/HTML.pm

filter: Statementstmt 100% 32 / 32 Branchbran 100% 10 / 10 Conditioncond 66.6% 2 / 3 MC/DCmcdc 50.0% 1 / 2 Subroutinesub 100% 8 / 8 Podpod 100% 5 / 5 totaltotal 96.6% 58 / 60 CC 7 SCAR 8.3
CC
7
Cov
98%
start
4.0
mine
2.0
text
2.0
CRAP 2.3
« Miner/Ext.pm ↑ Summary Miner.pm »
1 package FileMetadata::Miner::HTML;
2  
3 1 require HTML::Parser;
4 1 @ISA = qw(HTML::Parser);
5 1 ▶use HTML::Entities ();
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 our $VERSION = '1.0';
9  
10 1 ▶sub new {
Subroutine new: called CC=1 SCAR=0.0
Pod documented
11  
12 1 my $class = shift;
13 1 my $self = $class->SUPER::new(); # Inheriting
14  
15 # Set handlers
16  
17 1 $self->handler (text => 'text', "self, text");
18 1 $self->handler (start => 'start', 'self, tagname, attr');
19 1 $self->handler (end => 'end', 'self, tagname');
20  
21 1 return $self;
22  
23 }
24  
25 2 ▶sub mine {
Subroutine mine: called CC=2 SCAR=6.9
Pod documented
26  
27 2 my ($self, $path, $meta) = @_;
28 2 $self->{data} = $meta;
29 2 ▶ return 0 unless defined $self->parse_file ($path);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->parse_file($path) 1 1 2
30 1 return 1;
31  
32 }
33  
34 #
35 # This method handles text by appending it to the title key of
36 # $self->{'data'} when the tag is title. We are not interested in
37 # any other text
38 #
39  
40 6 ▶sub text {
Subroutine text: called CC=2 SCAR=6.9
Pod documented
41  
42 6 my ($self, $text) = @_;
43 $self->{'data'}->{ref ($self)."::".'title'} .= $text
44 6 ▶ if defined $self->{'tag-title'};
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"tag-title"} 1 5 6
45  
46 }
47  
48 #
49 # This method handles start tags. It ignores all but meta and title tags
50 #
51  
52 5 ▶sub start {
Subroutine start: called CC=4 SCAR=13.9
Pod documented
53  
54 5 my($self, $tag, $attr) = @_;
55  
56 5 ▶ if ($tag eq 'meta' && defined $attr->{'name'}) {
Branch: 2 branches
BranchTrueFalseTotal
if ($tag eq 'meta' and defined $attr->{'name'}) { } 2 3 5
elsif ($tag eq 'title') { } 1 2 3
Condition66%2/3
$tag eq "meta" and defined $attr->{"name"}
!ll&&!rl&&r
302
MC/DC50%1/2
$tag eq "meta" and defined $attr->{"name"}
$tag eq "meta" defined $attr->{"name"}
Truth table66%2/3
A and B
A= $tag eq "meta"B= defined $attr->{"name"}
ABresult
0X0
100
111
57 2 $self->{'data'}->{ref ($self)."::".$attr->{'name'}} = $attr->{'content'};
58 } elsif ($tag eq 'title') {
59 # Flag this
60 1 $self->{'tag-title'} = '';
61 }
62  
63 }
64  
65 2 ▶sub end {
Subroutine end: called CC=2 SCAR=6.9
Pod documented
66  
67 2 my($self, $tag) = @_;
68  
69 # Stop processing
70 2 ▶ $self->eof() if ($tag eq 'head');
Branch: 1 branch
BranchTrueFalseTotal
if $tag eq "head" 1 1 2
71  
72 # Unflag
73 2 delete $self->{'tag-title'};
74  
75 }
76  
77 1 1;
78  
79 __END__
« Miner/Ext.pm ↑ Summary Miner.pm »