Form/Input.pm

filter: Statementstmt 79.0% 68 / 86 Branchbran 62.9% 34 / 54 Conditioncond 0.0% 0 / 9 MC/DCmcdc 0.0% 0 / 5 Subroutinesub 84.2% 16 / 19 Podpod 0.0% 0 / 18 totaltotal 61.7% 118 / 191 SCAR 41.6
CC
32
Cov
68%
dump
116.5
selected
6.0
form_name_value
4.0
CRAP 64.1
« Form.pm ↑ Summary Form/ListInput.pm »
1 package HTML::Form::Input;
2  
3 11 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 11 our $VERSION = '6.11';
6  
7 # ABSTRACT: A generic HTML form input element for use with HTML::Form
8  
9 sub new {
10 154 ▶ my $class = shift;
Subroutine new: called CC=1 SCAR=0.0
Pod undocumented
11 154 my $self = bless {@_}, $class;
12 154 $self;
13 }
14  
15 sub add_to_form {
16 116 ▶ my ( $self, $form ) = @_;
Subroutine add_to_form: called CC=1 SCAR=0.0
Pod undocumented
17 116 push( @{ $form->{'inputs'} }, $self );
18 116 $self;
19 }
20  
21 sub strict {
22 10 ▶ my $self = shift;
Subroutine strict: called CC=2 SCAR=6.9
Pod undocumented
23 10 my $old = $self->{strict};
24 10 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 8 2 10
25 8 $self->{strict} = shift;
26 }
27 10 $old;
28 }
29  
30 ▶sub fixup { }
Subroutine fixup: called CC=1 SCAR=0.0
Pod undocumented
31  
32 sub type {
33 145 ▶ shift->{type};
Subroutine type: called CC=1 SCAR=0.0
Pod undocumented
34 }
35  
36 sub name {
37 234 ▶ my $self = shift;
Subroutine name: called CC=2 SCAR=6.9
Pod undocumented
38 234 my $old = $self->{name};
39 234 ▶ $self->{name} = shift if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 1 233 234
40 234 $old;
41 }
42  
43 sub id {
44 1 ▶ my $self = shift;
Subroutine id: called CC=2 SCAR=7.0
Pod undocumented
45 1 my $old = $self->{id};
46 1 ▶ $self->{id} = shift if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 0 1 1
47 1 $old;
48 }
49  
50 sub class {
51 1 ▶ my $self = shift;
Subroutine class: called CC=2 SCAR=7.0
Pod undocumented
52 1 my $old = $self->{class};
53 1 ▶ $self->{class} = shift if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 0 1 1
54 1 $old;
55 }
56  
57 sub selected {
58 580 ▶ my ( $self, $sel ) = @_;
Subroutine selected: called CC=6 SCAR=17.9
Pod undocumented
59 580 ▶ return undef unless defined $sel;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $sel 0 580 580
60 580 ▶ my $attr
Branch: 3 branches
BranchTrueFalseTotal
$sel =~ s/^\^// ? : 6 574 580
$sel =~ s/^#// ? : 20 554 574
$sel =~ s/^\.// ? : 14 540 554
61 = $sel =~ s/^\^// ? "name"
62 : $sel =~ s/^#// ? "id"
63 : $sel =~ s/^\.// ? "class"
64 : "name";
65 580 ▶ return 0 unless defined $self->{$attr};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->{$attr} 5 575 580
66 575 return $self->{$attr} eq $sel;
67 }
68  
69 sub value {
70 11 ▶ my $self = shift;
Subroutine value: called CC=2 SCAR=6.9
Pod undocumented
71 11 my $old = $self->{value};
72 11 ▶ $self->{value} = shift if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 1 10 11
73 11 $old;
74 }
75  
76 sub autocomplete {
77 6 ▶ my $self = shift;
Subroutine autocomplete: called CC=2 SCAR=6.9
Pod undocumented
78 6 my $old = $self->{autocomplete};
79 6 ▶ $self->{autocomplete} = shift if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 2 4 6
80 6 $old;
81 }
82  
83 sub possible_values {
84 0 ▶ return;
Subroutine possible_values: not called CC=1 SCAR=6.9
Pod undocumented
85 }
86  
87 sub other_possible_values {
88 0 ▶ return;
Subroutine other_possible_values: not called CC=1 SCAR=6.9
Pod undocumented
89 }
90  
91 sub value_names {
92 0 ▶ return;
Subroutine value_names: not called CC=1 SCAR=6.9
Pod undocumented
93 }
94  
95 sub readonly {
96 6 ▶ my $self = shift;
Subroutine readonly: called CC=2 SCAR=6.9
Pod undocumented
97 6 my $old = $self->{readonly};
98 6 ▶ $self->{readonly} = shift if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 1 5 6
99 6 $old;
100 }
101  
102 sub disabled {
103 60 ▶ my $self = shift;
Subroutine disabled: called CC=2 SCAR=6.9
Pod undocumented
104 60 my $old = $self->{disabled};
105 60 ▶ $self->{disabled} = shift if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 1 59 60
106 60 $old;
107 }
108  
109 sub form_name_value {
110 76 ▶ my $self = shift;
Subroutine form_name_value: called CC=4 SCAR=13.9
Pod undocumented
111 76 my $name = $self->{'name'};
112 76 ▶ return unless defined $name;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $name 8 68 76
113 68 ▶ return if $self->disabled;
Branch: 1 branch
BranchTrueFalseTotal
if $self->disabled 3 65 68
114 65 my $value = $self->value;
115 65 ▶ return unless defined $value;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $value 5 60 65
116 60 return ( $name => $value );
117 }
118  
119 sub dump {
120 1 ▶ my $self = shift;
Subroutine dump: called CC=16 SCAR=47.6
Pod undocumented
121 1 my $name = $self->name;
122 1 ▶ $name = "<NONAME>" unless defined $name;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $name 0 1 1
123 1 my $value = $self->value;
124 1 ▶ $value = "<UNDEF>" unless defined $value;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $value 0 1 1
125 1 my $dump = "$name=$value";
126  
127 1 my $type = $self->type;
128  
129 1 ▶ $type .= " disabled" if $self->disabled;
Branch: 1 branch
BranchTrueFalseTotal
if $self->disabled 0 1 1
130 1 ▶ $type .= " readonly" if $self->readonly;
Branch: 1 branch
BranchTrueFalseTotal
if $self->readonly 0 1 1
131 1 ▶ return sprintf "%-30s %s", $dump, "($type)" unless $self->{menu};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"menu"} 1 0 1
132  
133 0 my @menu;
134 0 my $i = 0;
135 0 for ( @{ $self->{menu} } ) {
136 0 my $opt = $_->{value};
137 0 ▶ $opt = "<UNDEF>" unless defined $opt;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $opt 0 0 0
138 $opt .= "/$_->{name}"
139 0 ▶ if defined $_->{name} && length $_->{name} && $_->{name} ne $opt;
Branch: 1 branch
BranchTrueFalseTotal
if defined $_->{"name"} and length $_->{"name"} and $_->{"name"} ne $opt 0 0 0
Condition0%0/6
defined $_->{"name"} and length $_->{"name"} and $_->{"name"} ne $opt
!ll&&!rl&&r
000
defined $_->{"name"} and length $_->{"name"}
!ll&&!rl&&r
000
MC/DC0%0/3
defined $_->{"name"} and length $_->{"name"} and $_->{"name"} ne $opt
defined $_->{"name"} length $_->{"name"} $_->{"name"} ne $opt
Truth table0%0/4
A and B and C
A= defined $_->{"name"}B= length $_->{"name"}C= $_->{"name"} ne $opt
ABCresult
0XX0
10X0
1100
1111
140 0 ▶ substr( $opt, 0, 0 ) = "-" if $_->{disabled};
Branch: 1 branch
BranchTrueFalseTotal
if $_->{"disabled"} 0 0 0
141 0 ▶ if ( exists $self->{current} && $self->{current} == $i ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $self->{'current'} and $self->{'current'} == $i) { } 0 0 0
Condition0%0/3
exists $self->{"current"} and $self->{"current"} == $i
!ll&&!rl&&r
000
MC/DC0%0/2
exists $self->{"current"} and $self->{"current"} == $i
exists $self->{"current"} $self->{"current"} == $i
Truth table0%0/3
A and B
A= exists $self->{"current"}B= $self->{"current"} == $i
ABresult
0X0
100
111
142 0 ▶ substr( $opt, 0, 0 ) = "!" unless $_->{seen};
Branch: 1 branch
BranchTrueFalseTotal
unless $_->{"seen"} 0 0 0
143 0 substr( $opt, 0, 0 ) = "*";
144 }
145 else {
146 0 ▶ substr( $opt, 0, 0 ) = ":" if $_->{seen};
Branch: 1 branch
BranchTrueFalseTotal
if $_->{"seen"} 0 0 0
147 }
148 0 push( @menu, $opt );
149 0 $i++;
150 }
151  
152 0 return sprintf "%-30s %-10s %s", $dump, "($type)",
153 "[" . join( "|", @menu ) . "]";
154 }
155  
156 11 1;
157  
158 __END__
« Form.pm ↑ Summary Form/ListInput.pm »