| 1 | package HTML::ValidationRules::Parser; | ||||||||||||||||||||||||||||||||||||||
| 2 | 3 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 3 | 3 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 4 | 3 | ▶ | use autodie; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 5 | 3 | ▶ | use HTML::Parser; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||||||
| 7 | 3 | my %ELEMENTS = ( | |||||||||||||||||||||||||||||||||||||
| 8 | input => [qw( | ||||||||||||||||||||||||||||||||||||||
| 9 | max | ||||||||||||||||||||||||||||||||||||||
| 10 | maxlength | ||||||||||||||||||||||||||||||||||||||
| 11 | min | ||||||||||||||||||||||||||||||||||||||
| 12 | pattern | ||||||||||||||||||||||||||||||||||||||
| 13 | required | ||||||||||||||||||||||||||||||||||||||
| 14 | ), { | ||||||||||||||||||||||||||||||||||||||
| 15 | name => 'type', | ||||||||||||||||||||||||||||||||||||||
| 16 | values => [qw( | ||||||||||||||||||||||||||||||||||||||
| 17 | url | ||||||||||||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||||||||||||
| 19 | number | ||||||||||||||||||||||||||||||||||||||
| 20 | range | ||||||||||||||||||||||||||||||||||||||
| 21 | )], | ||||||||||||||||||||||||||||||||||||||
| 22 | }], | ||||||||||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||||||||||
| 24 | textarea => [qw( | ||||||||||||||||||||||||||||||||||||||
| 25 | maxlength | ||||||||||||||||||||||||||||||||||||||
| 26 | required | ||||||||||||||||||||||||||||||||||||||
| 27 | )], | ||||||||||||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||||||||||||
| 29 | select => [qw( | ||||||||||||||||||||||||||||||||||||||
| 30 | required | ||||||||||||||||||||||||||||||||||||||
| 31 | )], | ||||||||||||||||||||||||||||||||||||||
| 32 | ); | ||||||||||||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||||||||||||
| 34 | 3 | my $ELEMENTS_PATTERN = qr/(@{[join '|', (map { quotemeta } keys %ELEMENTS)]})/o; | |||||||||||||||||||||||||||||||||||||
| 35 | my %ATTRS_MAP = map { | ||||||||||||||||||||||||||||||||||||||
| 36 | 3 | ▶ | my $attr = ref $_ ? $_->{name} : $_; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 37 | 9 | $attr => +{ map { $_ => 1 } @{$ELEMENTS{$_}} }; | |||||||||||||||||||||||||||||||||||||
| 38 | } keys %ELEMENTS; | ||||||||||||||||||||||||||||||||||||||
| 39 | my %TYPE_ATTR_MAP = map { | ||||||||||||||||||||||||||||||||||||||
| 40 | 3 | my $attr = $_; | |||||||||||||||||||||||||||||||||||||
| 41 | 3 | map { $_ => 1 } @{$attr->{values}}; | |||||||||||||||||||||||||||||||||||||
| 42 | 3 | ▶ | } grep { ref $_ && $_->{name} eq 'type' } @{$ELEMENTS{input}}; | ||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
ref $_ && $_->{'name'} eq 'type'
MC/DC50%1/2
ref $_ && $_->{'name'} eq 'type'
ref $_
$_->{'name'} eq 'type'
Truth table66%2/3
A && B
A= ref $_B= $_->{'name'} eq 'type'
| |||||||||||||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||||||||||||
| 44 | 52 | ▶ | sub new { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||
| 45 | 52 | my ($class, %args) = @_; | |||||||||||||||||||||||||||||||||||||
| 46 | 52 | bless \%args, $class; | |||||||||||||||||||||||||||||||||||||
| 47 | } | ||||||||||||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||||||||||||
| 49 | 208 | ▶ | sub parser { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
parser: called CC=3 SCAR=11.4
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||
| 50 | 208 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||
| 51 | $self->{parser} ||= HTML::Parser->new( | ||||||||||||||||||||||||||||||||||||||
| 52 | api_version => 3, | ||||||||||||||||||||||||||||||||||||||
| 53 | start_h => [\&start, 'self, tagname, attr, attrseq'], | ||||||||||||||||||||||||||||||||||||||
| 54 | 208 | ▶ | %{$self->{options} || {}}, | ||||||||||||||||||||||||||||||||||||
|
Condition60%3/5
$self->{"parser"} ||= "HTML::Parser"->new("api_version", 3, "start_h", [\&HTML::ValidationRules::Parser::start, "self, tagname, attr, attrseq"], %{$self->{"options"} or {};})
$self->{'options'} || {}
MC/DC0%0/2
$self->{"parser"} ||= "HTML::Parser"->new("api_version", 3, "start_h", [\&HTML::ValidationRules::Parser::start, "self, tagname, attr, attrseq"], %{$self->{"options"} or {};})
$self->{"parser"}
"HTML::Parser"->new("api_version", 3, "start_h", [\&HTML::ValidationRules::Parser::start, "self, tagname, attr, attrseq"], %{$self->{"options"} or {};})
MC/DC0%0/1
$self->{'options'} || {}
$self->{'options'}
Truth table66%2/3
A ||= B
A= $self->{"parser"}B= "HTML::Parser"->new("api_version", 3, "start_h", [\&HTML::ValidationRules::Parser::start, "self, tagname, attr, attrseq"], %{$self->{"options"} or {};})
Truth table50%1/2
A
A= $self->{'options'}
| |||||||||||||||||||||||||||||||||||||||
| 55 | ); | ||||||||||||||||||||||||||||||||||||||
| 56 | } | ||||||||||||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||||||||||||
| 58 | 52 | ▶ | sub load_rules { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
load_rules: called CC=2 SCAR=7.1
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||
| 59 | 52 | my ($self, %args) = @_; | |||||||||||||||||||||||||||||||||||||
| 60 | 52 | my $file = delete $args{file}; | |||||||||||||||||||||||||||||||||||||
| 61 | 52 | my $html = delete $args{html}; | |||||||||||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||||||||||||
| 63 | 52 | undef $self->parser->{rules}; | |||||||||||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||||||||||||
| 65 | 52 | ▶ | if ($file) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 66 | 0 | $self->parser->parse_file($file); | |||||||||||||||||||||||||||||||||||||
| 67 | } | ||||||||||||||||||||||||||||||||||||||
| 68 | else { | ||||||||||||||||||||||||||||||||||||||
| 69 | 52 | $self->parser->parse($html); | |||||||||||||||||||||||||||||||||||||
| 70 | 52 | $self->parser->eof; | |||||||||||||||||||||||||||||||||||||
| 71 | } | ||||||||||||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||||||||||||
| 73 | 52 | $self->parser->{rules}; | |||||||||||||||||||||||||||||||||||||
| 74 | } | ||||||||||||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||||||||||||
| 76 | 65 | ▶ | sub start { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
start: called CC=13 SCAR=25.7
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||
| 77 | 65 | my ($parser, $tag, $attr, $attrseq) = @_; | |||||||||||||||||||||||||||||||||||||
| 78 | 65 | ▶ | return if $tag !~ $ELEMENTS_PATTERN; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||||||||||||
| 80 | 61 | my $name = $attr->{name}; | |||||||||||||||||||||||||||||||||||||
| 81 | 61 | ▶ | return if !defined $name; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||||||||||||
| 83 | 60 | my @rules; | |||||||||||||||||||||||||||||||||||||
| 84 | 60 | my $attrs = $ATTRS_MAP{lc $tag}; | |||||||||||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||||||||||||
| 86 | 60 | ▶ | if (defined $attr->{type} && $TYPE_ATTR_MAP{lc $attr->{type} || ''}) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition80%4/5
defined $attr->{"type"} and $TYPE_ATTR_MAP{lc $attr->{"type"} or ""}
lc $attr->{'type'} || ''
MC/DC100%2/2
defined $attr->{"type"} and $TYPE_ATTR_MAP{lc $attr->{"type"} or ""}
defined $attr->{"type"}
$TYPE_ATTR_MAP{lc $attr->{"type"} or ""}
MC/DC0%0/1
lc $attr->{'type'} || ''
lc $attr->{'type'}
Truth table100%3/3
A and B
A= defined $attr->{"type"}B= $TYPE_ATTR_MAP{lc $attr->{"type"} or ""}
Truth table50%1/2
A
A= lc $attr->{'type'}
| |||||||||||||||||||||||||||||||||||||||
| 87 | 37 | my $type = $attr->{type}; | |||||||||||||||||||||||||||||||||||||
| 88 | 37 | unshift @rules, key($type); | |||||||||||||||||||||||||||||||||||||
| 89 | 37 | $attrseq = [ grep { lc $_ ne 'type' } @$attrseq ]; | |||||||||||||||||||||||||||||||||||||
| 90 | } | ||||||||||||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||||||||||||
| 92 | 60 | ▶ | for my $key (@{$attrseq || []}) { | ||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$attrseq || []
MC/DC0%0/1
$attrseq || []
$attrseq
Truth table50%1/2
A
A= $attrseq
| |||||||||||||||||||||||||||||||||||||||
| 93 | 133 | ▶ | next if !$attrs->{$key}; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||||||||||||
| 95 | 52 | my $value = $attr->{$key}; | |||||||||||||||||||||||||||||||||||||
| 96 | 52 | ▶ | if (defined $value && $key ne $value) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition66%2/3
defined $value and $key ne $value
MC/DC50%1/2
defined $value and $key ne $value
defined $value
$key ne $value
Truth table66%2/3
A and B
A= defined $valueB= $key ne $value
| |||||||||||||||||||||||||||||||||||||||
| 97 | 43 | push @rules, [ key($key) => $value ]; | |||||||||||||||||||||||||||||||||||||
| 98 | } | ||||||||||||||||||||||||||||||||||||||
| 99 | elsif ($key eq $value) { | ||||||||||||||||||||||||||||||||||||||
| 100 | 9 | push @rules, key($key); | |||||||||||||||||||||||||||||||||||||
| 101 | } | ||||||||||||||||||||||||||||||||||||||
| 102 | } | ||||||||||||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||||||||||||
| 104 | 60 | ▶ | $parser->{rules} ||= []; | ||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$parser->{"rules"} ||= []
MC/DC100%1/1
$parser->{"rules"} ||= []
$parser->{"rules"}
Truth table100%2/2
A
A= $parser->{"rules"}
| |||||||||||||||||||||||||||||||||||||||
| 105 | 60 | push @{$parser->{rules}}, $name => \@rules; | |||||||||||||||||||||||||||||||||||||
| 106 | } | ||||||||||||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||||||||||||
| 108 | 89 | ▶ | sub key { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
key: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||
| 109 | 89 | my $key = shift; | |||||||||||||||||||||||||||||||||||||
| 110 | 89 | ▶ | return 'NOT_BLANK' if $key eq 'required'; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 111 | 80 | sprintf 'HTML_%s', uc $key; | |||||||||||||||||||||||||||||||||||||
| 112 | } | ||||||||||||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||||||||||||
| 114 | 3 | !!1; | |||||||||||||||||||||||||||||||||||||