| 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
| |||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||
| 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
Condition66%2/3
$tag eq "meta" and defined $attr->{"name"}
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"}
| |||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||||||
| 72 | # Unflag | ||||||||||||||||||||||||||||||||
| 73 | 2 | delete $self->{'tag-title'}; | |||||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||||||
| 75 | } | ||||||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||||||
| 77 | 1 | 1; | |||||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||||||
| 79 | __END__ | ||||||||||||||||||||||||||||||||