blib/lib/Data/FormValidator/Util/HTML.pm

filter: Statementstmt 85.3% 35 / 41 Branchbran 56.2% 9 / 16 Conditioncond 40.0% 2 / 5 MC/DCmcdc 0.0% 0 / 3 Subroutinesub 100% 7 / 7 Podpod 0.0% 0 / 1 totaltotal 72.6% 53 / 73 CC 11 SCAR 25.6
CC
11
Cov
74%
add_error_tokens
19.4
BEGIN
1.0
BEGIN
1.0
CRAP 12.9
↑ Summary
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
BranchTrueFalseTotal
defined $styles{$in{"style"}} or die qq[unknown style: $in{"style"}] 6 1 7
45  
46 # Default to style if none is provided
47 6 ▶ $in{prepend} = $styles{$in{style}}->{prepend} unless defined $in{prepend};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $in{"prepend"} 5 1 6
48 6 ▶ $in{append} = $styles{$in{style}}->{append} unless defined $in{append};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $in{"append"} 5 1 6
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: $!")
l!l
60
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'})
Aresult
11
00
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
BranchTrueFalseTotal
if (my $token = $p->get_token) 6 6 12
56 6 ▶ if ( ( $token->is_start_tag( 'input' ) ) &&
Branch: 4 branches
BranchTrueFalseTotal
if ($token->is_start_tag('input') and not $token->return_attr->{'type'} =~ /^(button|submit|image)$/i) { } 6 0 6
elsif ($token->is_start_tag('select')) { } 0 0 0
elsif ($token->is_end_tag('select')) { } 0 0 0
elsif ($token->is_start_tag('textarea')) { } 0 0 0
Condition33%1/3
$token->is_start_tag("input") and not $token->return_attr->{"type"} =~ /^(button|submit|image)$/i
!ll&&!rl&&r
006
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
ABresult
0X0
100
111
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__
↑ Summary