| 1 | package Data::FormValidator::Util::HTML; | ||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||
| 3 | 1 | ▶ | use 5.005; | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||
| 4 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||||||||||||
| 6 | 1 | require Exporter; | |||||||||||||||||||||||||||||||||||||||
| 7 | 1 | require HTML::TokeParser::Simple; | |||||||||||||||||||||||||||||||||||||||
| 8 | 1 | ▶ | use vars qw($VERSION @ISA @EXPORT); | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||
| 9 | 1 | @ISA = qw(Exporter); | |||||||||||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||||||||||
| 11 | # Items to export into callers namespace by default. Note: do not export | ||||||||||||||||||||||||||||||||||||||||
| 12 | # names by default without a very good reason. Use EXPORT_OK instead. | ||||||||||||||||||||||||||||||||||||||||
| 13 | # Do not simply export all your public functions/methods/constants. | ||||||||||||||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||||||||||||||
| 15 | 1 | @EXPORT = qw(add_error_tokens); | |||||||||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||||||||||
| 17 | 1 | $VERSION = '0.10'; | |||||||||||||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||||||||||||||
| 19 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||
| 20 | 1 | ▶ | use HTML::TokeParser::Simple; | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||
| 21 | 1 | ▶ | use Params::Validate; | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||||||||||||||
| 23 | 7 | ▶ | sub add_error_tokens { | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
add_error_tokens: called CC=11 SCAR=29.6
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||
| 24 | 7 | my %styles = ( | |||||||||||||||||||||||||||||||||||||||
| 25 | 'ht_comment' => { | ||||||||||||||||||||||||||||||||||||||||
| 26 | prepend => ' <!-- tmpl_var name="', | ||||||||||||||||||||||||||||||||||||||||
| 27 | append => '" --> ', | ||||||||||||||||||||||||||||||||||||||||
| 28 | }, | ||||||||||||||||||||||||||||||||||||||||
| 29 | 'ht_tag' => { | ||||||||||||||||||||||||||||||||||||||||
| 30 | prepend => ' <tmpl_var "', | ||||||||||||||||||||||||||||||||||||||||
| 31 | append => '"> ', | ||||||||||||||||||||||||||||||||||||||||
| 32 | }, | ||||||||||||||||||||||||||||||||||||||||
| 33 | ); | ||||||||||||||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||||||||||||||
| 35 | 7 | my %in = validate(@_, { | |||||||||||||||||||||||||||||||||||||||
| 36 | html => { default => *STDIN }, | ||||||||||||||||||||||||||||||||||||||||
| 37 | prefix => { default => 'err_' }, | ||||||||||||||||||||||||||||||||||||||||
| 38 | style => { default => 'ht_comment' }, | ||||||||||||||||||||||||||||||||||||||||
| 39 | prepend => 0, | ||||||||||||||||||||||||||||||||||||||||
| 40 | append => 0, | ||||||||||||||||||||||||||||||||||||||||
| 41 | } | ||||||||||||||||||||||||||||||||||||||||
| 42 | ); | ||||||||||||||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||||||||||||||
| 44 | 7 | ▶ | defined $styles{$in{style}} or die "unknown style: $in{style}"; | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||||||||||||||
| 46 | # Default to style if none is provided | ||||||||||||||||||||||||||||||||||||||||
| 47 | 6 | ▶ | $in{prepend} = $styles{$in{style}}->{prepend} unless defined $in{prepend}; | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 48 | 6 | ▶ | $in{append} = $styles{$in{style}}->{append} unless defined $in{append}; | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||||||||||||||
| 50 | 6 | ▶ | my $p = HTML::TokeParser::Simple->new($in{html}) || | ||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
'HTML::TokeParser::Simple'->new($in{'html'}) || die("failed to create HTML::TokeParser::Simple object: $!")
MC/DC0%0/1
'HTML::TokeParser::Simple'->new($in{'html'}) || die("failed to create HTML::TokeParser::Simple object: $!")
'HTML::TokeParser::Simple'->new($in{'html'})
Truth table50%1/2
A
A= 'HTML::TokeParser::Simple'->new($in{'html'})
| |||||||||||||||||||||||||||||||||||||||||
| 51 | die "failed to create HTML::TokeParser::Simple object: $!"; | ||||||||||||||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||||||||||||||
| 53 | 6 | my $select_name; | |||||||||||||||||||||||||||||||||||||||
| 54 | my $out; | ||||||||||||||||||||||||||||||||||||||||
| 55 | 6 | ▶ | while ( my $token = $p->get_token ) { | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 56 | 6 | ▶ | if ( ( $token->is_start_tag( 'input' ) ) && | ||||||||||||||||||||||||||||||||||||||
|
Branch: 4 branches
Condition33%1/3
$token->is_start_tag("input") and not $token->return_attr->{"type"} =~ /^(button|submit|image)$/i
MC/DC0%0/2
$token->is_start_tag("input") and not $token->return_attr->{"type"} =~ /^(button|submit|image)$/i
$token->is_start_tag("input")
not $token->return_attr->{"type"} =~ /^(button|submit|image)$/i
Truth table33%1/3
A and not(B)
A= $token->is_start_tag("input")B= not $token->return_attr->{"type"} =~ /^(button|submit|image)$/i
| |||||||||||||||||||||||||||||||||||||||||
| 57 | ( $token->return_attr->{type} !~ m/^(button|submit|image)$/i )) { | ||||||||||||||||||||||||||||||||||||||||
| 58 | 6 | my $name = $token->return_attr->{name}; | |||||||||||||||||||||||||||||||||||||||
| 59 | 6 | $out .= $token->as_is.qq/$in{prepend}$in{prefix}$name$in{append}/; | |||||||||||||||||||||||||||||||||||||||
| 60 | } | ||||||||||||||||||||||||||||||||||||||||
| 61 | elsif ( $token->is_start_tag( 'select' ) ) { | ||||||||||||||||||||||||||||||||||||||||
| 62 | 0 | $select_name = $token->return_attr->{name}; | |||||||||||||||||||||||||||||||||||||||
| 63 | 0 | $out .= $token->as_is; | |||||||||||||||||||||||||||||||||||||||
| 64 | } | ||||||||||||||||||||||||||||||||||||||||
| 65 | elsif ( $token->is_end_tag('select') ) { | ||||||||||||||||||||||||||||||||||||||||
| 66 | 0 | $out .= $token->as_is.qq/$in{prepend}$in{prefix}$select_name$in{append}/; | |||||||||||||||||||||||||||||||||||||||
| 67 | } | ||||||||||||||||||||||||||||||||||||||||
| 68 | elsif ( $token->is_start_tag( 'textarea' ) ) { | ||||||||||||||||||||||||||||||||||||||||
| 69 | 0 | my $name = $token->return_attr->{name}; | |||||||||||||||||||||||||||||||||||||||
| 70 | 0 | $out .= qq/$in{prepend}$in{prefix}$name$in{append}/.$token->as_is; | |||||||||||||||||||||||||||||||||||||||
| 71 | } | ||||||||||||||||||||||||||||||||||||||||
| 72 | else { | ||||||||||||||||||||||||||||||||||||||||
| 73 | 0 | $out .= $token->as_is; | |||||||||||||||||||||||||||||||||||||||
| 74 | } | ||||||||||||||||||||||||||||||||||||||||
| 75 | } | ||||||||||||||||||||||||||||||||||||||||
| 76 | 6 | return $out; | |||||||||||||||||||||||||||||||||||||||
| 77 | } | ||||||||||||||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||||||||||||||
| 83 | 1 | 1; | |||||||||||||||||||||||||||||||||||||||
| 84 | __END__ | ||||||||||||||||||||||||||||||||||||||||