| 1 | package HTML::Parser; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 49 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||
| 5 | 49 | our $VERSION = '3.87'; | |||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | 49 | require HTML::Entities; | |||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | 49 | require XSLoader; | |||||||||||||||||||||||||||
| 10 | 49 | XSLoader::load('HTML::Parser', $VERSION); | |||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | sub new | ||||||||||||||||||||||||||||
| 13 | 129 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 14 | 129 | my $class = shift; | |||||||||||||||||||||||||||
| 15 | 129 | my $self = bless {}, $class; | |||||||||||||||||||||||||||
| 16 | 129 | return $self->init(@_); | |||||||||||||||||||||||||||
| 17 | } | ||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||
| 20 | sub init | ||||||||||||||||||||||||||||
| 21 | 129 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
init: called CC=11 SCAR=24.1
Pod
undocumented
| |||||||||||||||||||||||||||||
| 22 | 129 | my $self = shift; | |||||||||||||||||||||||||||
| 23 | 129 | $self->_alloc_pstate; | |||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||
| 25 | 129 | my %arg = @_; | |||||||||||||||||||||||||||
| 26 | 129 | ▶ | my $api_version = delete $arg{api_version} || (@_ ? 3 : 2); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
delete $arg{'api_version'} || (@_ ? 3 : 2)
MC/DC0%0/2
delete $arg{'api_version'} || (@_ ? 3 : 2)
delete $arg{'api_version'}
(@_ ? 3 : 2)
Truth table66%2/3
A || B
A= delete $arg{'api_version'}B= (@_ ? 3 : 2)
| |||||||||||||||||||||||||||||
| 27 | 129 | ▶ | if ($api_version >= 4) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 28 | 1 | require Carp; | |||||||||||||||||||||||||||
| 29 | 1 | Carp::croak("API version $api_version not supported " . | |||||||||||||||||||||||||||
| 30 | "by HTML::Parser $VERSION"); | ||||||||||||||||||||||||||||
| 31 | } | ||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||
| 33 | 128 | ▶ | if ($api_version < 3) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 34 | # Set up method callbacks compatible with HTML-Parser-2.xx | ||||||||||||||||||||||||||||
| 35 | 47 | $self->handler(text => "text", "self,text,is_cdata"); | |||||||||||||||||||||||||||
| 36 | 47 | $self->handler(end => "end", "self,tagname,text"); | |||||||||||||||||||||||||||
| 37 | 47 | $self->handler(process => "process", "self,token0,text"); | |||||||||||||||||||||||||||
| 38 | 47 | $self->handler(start => "start", | |||||||||||||||||||||||||||
| 39 | "self,tagname,attr,attrseq,text"); | ||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||
| 41 | $self->handler(comment => | ||||||||||||||||||||||||||||
| 42 | 53 | ▶ | sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||
| 43 | 53 | my($self, $tokens) = @_; | |||||||||||||||||||||||||||
| 44 | 53 | for (@$tokens) { | |||||||||||||||||||||||||||
| 45 | 55 | $self->comment($_); | |||||||||||||||||||||||||||
| 46 | } | ||||||||||||||||||||||||||||
| 47 | 47 | }, "self,tokens"); | |||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||
| 49 | $self->handler(declaration => | ||||||||||||||||||||||||||||
| 50 | 10 | ▶ | sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 51 | 10 | my $self = shift; | |||||||||||||||||||||||||||
| 52 | 10 | $self->declaration(substr($_[0], 2, -1)); | |||||||||||||||||||||||||||
| 53 | 47 | }, "self,text"); | |||||||||||||||||||||||||||
| 54 | } | ||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||
| 56 | 128 | ▶ | if (my $h = delete $arg{handlers}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 57 | 3 | ▶ | $h = {@$h} if ref($h) eq "ARRAY"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 58 | 3 | ▶ | while (my($event, $cb) = each %$h) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 59 | 3 | $self->handler($event => @$cb); | |||||||||||||||||||||||||||
| 60 | } | ||||||||||||||||||||||||||||
| 61 | } | ||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||
| 63 | # In the end we try to assume plain attribute or handler | ||||||||||||||||||||||||||||
| 64 | 128 | ▶ | while (my($option, $val) = each %arg) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 65 | 101 | ▶ | if ($option =~ /^(\w+)_h$/) { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 66 | 57 | $self->handler($1 => @$val); | |||||||||||||||||||||||||||
| 67 | } | ||||||||||||||||||||||||||||
| 68 | elsif ($option =~ /^(text|start|end|process|declaration|comment)$/) { | ||||||||||||||||||||||||||||
| 69 | 0 | require Carp; | |||||||||||||||||||||||||||
| 70 | 0 | Carp::croak("Bad constructor option '$option'"); | |||||||||||||||||||||||||||
| 71 | } | ||||||||||||||||||||||||||||
| 72 | else { | ||||||||||||||||||||||||||||
| 73 | 44 | $self->$option($val); | |||||||||||||||||||||||||||
| 74 | } | ||||||||||||||||||||||||||||
| 75 | } | ||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||
| 77 | 128 | return $self; | |||||||||||||||||||||||||||
| 78 | } | ||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||
| 81 | sub parse_file | ||||||||||||||||||||||||||||
| 82 | 18 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
parse_file: called CC=7 SCAR=19.5
Pod
documented
| |||||||||||||||||||||||||||||
| 83 | 18 | my($self, $file) = @_; | |||||||||||||||||||||||||||
| 84 | 18 | my $opened; | |||||||||||||||||||||||||||
| 85 | 18 | ▶ | if (!ref($file) && ref(\$file) ne "GLOB") { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
not ref $file and ref \$file ne "GLOB"
MC/DC100%2/2
not ref $file and ref \$file ne "GLOB"
not ref $file
ref \$file ne "GLOB"
Truth table100%3/3
not(A) and B
A= not ref $fileB= ref \$file ne "GLOB"
| |||||||||||||||||||||||||||||
| 86 | # Assume $file is a filename | ||||||||||||||||||||||||||||
| 87 | 10 | local(*F); | |||||||||||||||||||||||||||
| 88 | 10 | ▶ | open(F, "<", $file) || return undef; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 89 | 10 | binmode(F); # should we? good for byte counts | |||||||||||||||||||||||||||
| 90 | 10 | $opened++; | |||||||||||||||||||||||||||
| 91 | 10 | $file = *F; | |||||||||||||||||||||||||||
| 92 | } | ||||||||||||||||||||||||||||
| 93 | 18 | my $chunk = ''; | |||||||||||||||||||||||||||
| 94 | 18 | ▶ | while (read($file, $chunk, 512)) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 95 | 5006 | ▶ | $self->parse($chunk) || last; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 96 | } | ||||||||||||||||||||||||||||
| 97 | 18 | ▶ | close($file) if $opened; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 98 | 18 | $self->eof; | |||||||||||||||||||||||||||
| 99 | } | ||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||
| 102 | sub netscape_buggy_comment # legacy | ||||||||||||||||||||||||||||
| 103 | 1 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
netscape_buggy_comment: called CC=2 SCAR=7.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 104 | 1 | my $self = shift; | |||||||||||||||||||||||||||
| 105 | 1 | require Carp; | |||||||||||||||||||||||||||
| 106 | 1 | Carp::carp("netscape_buggy_comment() is deprecated. " . | |||||||||||||||||||||||||||
| 107 | "Please use the strict_comment() method instead"); | ||||||||||||||||||||||||||||
| 108 | 1 | my $old = !$self->strict_comment; | |||||||||||||||||||||||||||
| 109 | 1 | ▶ | $self->strict_comment(!shift) if @_; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 110 | 1 | return $old; | |||||||||||||||||||||||||||
| 111 | } | ||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||
| 113 | # set up method stubs | ||||||||||||||||||||||||||||
| 114 | 15504 | ▶ | sub text { } | ||||||||||||||||||||||||||
|
Subroutine
text: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 115 | 49 | *start = \&text; | |||||||||||||||||||||||||||
| 116 | 49 | *end = \&text; | |||||||||||||||||||||||||||
| 117 | 49 | *comment = \&text; | |||||||||||||||||||||||||||
| 118 | 49 | *declaration = \&text; | |||||||||||||||||||||||||||
| 119 | 49 | *process = \&text; | |||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||
| 121 | 49 | 1; | |||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||
| 123 | __END__ | ||||||||||||||||||||||||||||