| 1 | package HTML::DisableForm; | ||||||||||||||||||||||||||||||||
| 2 | 7 | ▶ | use strict; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 3 | 7 | ▶ | use warnings; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 4 | 7 | ▶ | use base qw/HTML::Parser/; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||||
| 6 | 7 | our $VERSION = 0.01; | |||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||
| 8 | 7 | my %can_disable = ( | |||||||||||||||||||||||||||||||
| 9 | input => 1, | ||||||||||||||||||||||||||||||||
| 10 | textarea => 1, | ||||||||||||||||||||||||||||||||
| 11 | select => 1, | ||||||||||||||||||||||||||||||||
| 12 | ); | ||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||
| 14 | 5 | ▶ | sub new { | ||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||
| 15 | 5 | my $class = shift; | |||||||||||||||||||||||||||||||
| 16 | 5 | my $self = $class->SUPER::new(api_version => 3); | |||||||||||||||||||||||||||||||
| 17 | 5 | $self->handler(start => \&_handle_start, "self, tagname, attr, text"); | |||||||||||||||||||||||||||||||
| 18 | 5 | $self->handler(end => \&_handle_end, "self, tagname, text"); | |||||||||||||||||||||||||||||||
| 19 | 5 | $self->handler(default => \&_handle_default, "self, text"); | |||||||||||||||||||||||||||||||
| 20 | 5 | $self->attr_encoded(1); | |||||||||||||||||||||||||||||||
| 21 | 5 | bless $self, $class; | |||||||||||||||||||||||||||||||
| 22 | } | ||||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||||
| 24 | 1 | ▶ | sub readonly_form { | ||||||||||||||||||||||||||||||
|
Subroutine
readonly_form: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||
| 25 | 1 | my ($self, %option) = @_; | |||||||||||||||||||||||||||||||
| 26 | 1 | $self->disable_form(%option, readonly => 1); | |||||||||||||||||||||||||||||||
| 27 | } | ||||||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||||||
| 29 | 5 | ▶ | sub disable_form { | ||||||||||||||||||||||||||||||
|
Subroutine
disable_form: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||||||
| 30 | 5 | my ($self, %option) = @_; | |||||||||||||||||||||||||||||||
| 31 | 5 | ▶ | $self->{target} = $option{target} if $option{target}; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 32 | 5 | ▶ | $self->{readonly} = 1 if $option{readonly}; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 33 | 5 | $self->_set_options_map($_, $option{$_}) for qw/ignore_fields ignore_forms/; | |||||||||||||||||||||||||||||||
| 34 | 5 | $self->_parse(%option); | |||||||||||||||||||||||||||||||
| 35 | 5 | delete $self->{output}; | |||||||||||||||||||||||||||||||
| 36 | } | ||||||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||||||
| 38 | 10 | ▶ | sub _set_options_map { | ||||||||||||||||||||||||||||||
|
Subroutine
_set_options_map: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||
| 39 | 10 | my ($self, $name, $value) = @_; | |||||||||||||||||||||||||||||||
| 40 | 10 | ▶ | return unless defined $value; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 41 | 2 | ▶ | my %options_map = map { $_ => 1 } ref $value eq 'ARRAY' ? @$value : $value; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 42 | 2 | $self->{$name} = \%options_map; | |||||||||||||||||||||||||||||||
| 43 | } | ||||||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||||||
| 45 | 5 | ▶ | sub _parse { | ||||||||||||||||||||||||||||||
|
Subroutine
_parse: called CC=5 SCAR=20.9
| |||||||||||||||||||||||||||||||||
| 46 | 5 | my $self = shift; | |||||||||||||||||||||||||||||||
| 47 | 5 | my %option = @_; | |||||||||||||||||||||||||||||||
| 48 | 5 | ▶ | if (my $file = $option{file}){ | ||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||
| 49 | 0 | $self->parse_file($file); | |||||||||||||||||||||||||||||||
| 50 | } elsif (my $scalarref = $option{scalarref}){ | ||||||||||||||||||||||||||||||||
| 51 | 5 | $self->parse($$scalarref); | |||||||||||||||||||||||||||||||
| 52 | } elsif (my $arrayref = $option{arrayref}){ | ||||||||||||||||||||||||||||||||
| 53 | 0 | $self->parse($_) for @$arrayref; | |||||||||||||||||||||||||||||||
| 54 | } | ||||||||||||||||||||||||||||||||
| 55 | } | ||||||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||||||
| 57 | 57 | ▶ | sub _can_disable { | ||||||||||||||||||||||||||||||
|
Subroutine
_can_disable: called CC=10 SCAR=23.1
| |||||||||||||||||||||||||||||||||
| 58 | 57 | my ($self, $tagname, $attr) = @_; | |||||||||||||||||||||||||||||||
| 59 | 57 | ▶ | $can_disable{$tagname} or return; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 60 | 24 | ▶ | return 0 if defined $self->{target} && !$self->{current_form}; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
defined $self->{"target"} and not $self->{"current_form"}
MC/DC100%2/2
defined $self->{"target"} and not $self->{"current_form"}
defined $self->{"target"}
not $self->{"current_form"}
Truth table100%3/3
A and not(B)
A= defined $self->{"target"}B= not $self->{"current_form"}
| |||||||||||||||||||||||||||||||||
| 61 | 21 | ▶ | if (my $current_form = $self->{current_form}) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 62 | 9 | ▶ | if (defined $self->{target}) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 63 | 6 | ▶ | $current_form eq $self->{target} ? return 1 : return 0; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 64 | } | ||||||||||||||||||||||||||||||||
| 65 | 3 | ▶ | return 0 if $self->{ignore_forms}->{$current_form}; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 66 | } | ||||||||||||||||||||||||||||||||
| 67 | 12 | ▶ | if ($attr->{name}) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 68 | 12 | ▶ | return 0 if $self->{ignore_fields}->{$attr->{name}}; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 69 | } | ||||||||||||||||||||||||||||||||
| 70 | 10 | return 1; | |||||||||||||||||||||||||||||||
| 71 | } | ||||||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||||||
| 73 | 57 | ▶ | sub _handle_start { | ||||||||||||||||||||||||||||||
|
Subroutine
_handle_start: called CC=9 SCAR=22.0
| |||||||||||||||||||||||||||||||||
| 74 | 57 | my ($self, $tagname, $attr, $text) = @_; | |||||||||||||||||||||||||||||||
| 75 | 57 | ▶ | $self->{current_form} = $attr->{name} || $attr->{id} || '' | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition80%4/5
$attr->{'name'} || $attr->{'id'} || ''
$attr->{"name"} or $attr->{"id"}
MC/DC50%1/2
$attr->{'name'} || $attr->{'id'} || ''
$attr->{"name"}
$attr->{"id"}
Truth table66%2/3
A or B
A= $attr->{"name"}B= $attr->{"id"}
| |||||||||||||||||||||||||||||||||
| 76 | if $tagname eq 'form'; | ||||||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||||||
| 78 | 57 | ▶ | if ($self->_can_disable($tagname, $attr)) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 79 | 13 | $self->{output} .= "<$tagname"; | |||||||||||||||||||||||||||||||
| 80 | 13 | ▶ | while (my ($key, $value) = each %$attr) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 81 | 35 | ▶ | next if $key eq '/'; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 82 | 26 | $self->{output} .= sprintf qq( %s="%s"), $key, $value; | |||||||||||||||||||||||||||||||
| 83 | } | ||||||||||||||||||||||||||||||||
| 84 | 13 | ▶ | $self->{output} .= $self->{readonly} ? ' readonly="readonly"' : ' disabled="disabled"'; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 85 | 13 | ▶ | $self->{output} .= ' /' if $attr->{'/'}; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 86 | 13 | $self->{output} .= '>'; | |||||||||||||||||||||||||||||||
| 87 | } else { | ||||||||||||||||||||||||||||||||
| 88 | 44 | $self->{output} .= $text; | |||||||||||||||||||||||||||||||
| 89 | } | ||||||||||||||||||||||||||||||||
| 90 | } | ||||||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||||||
| 92 | 41 | ▶ | sub _handle_end { | ||||||||||||||||||||||||||||||
|
Subroutine
_handle_end: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||
| 93 | 41 | my ($self, $tagname, $text) = @_; | |||||||||||||||||||||||||||||||
| 94 | delete $self->{current_form} | ||||||||||||||||||||||||||||||||
| 95 | 41 | ▶ | if $tagname eq 'form' and exists $self->{current_form}; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$tagname eq "form" and exists $self->{"current_form"}
MC/DC50%1/2
$tagname eq "form" and exists $self->{"current_form"}
$tagname eq "form"
exists $self->{"current_form"}
Truth table66%2/3
A and B
A= $tagname eq "form"B= exists $self->{"current_form"}
| |||||||||||||||||||||||||||||||||
| 96 | 41 | $self->{output} .= $text; | |||||||||||||||||||||||||||||||
| 97 | } | ||||||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||||||
| 99 | 80 | ▶ | sub _handle_default { | ||||||||||||||||||||||||||||||
|
Subroutine
_handle_default: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 100 | 80 | my ($self, $text) = @_; | |||||||||||||||||||||||||||||||
| 101 | 80 | $self->{output} .= $text; | |||||||||||||||||||||||||||||||
| 102 | } | ||||||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||||||
| 104 | 7 | 1; | |||||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||||||
| 106 | __END__ | ||||||||||||||||||||||||||||||||