File Coverage

blib/lib/XHTML/Instrumented/Form/ElementControl.pm
Criterion Covered Total %
statement 12 45 26.6
branch 0 26 0.0
condition 0 6 0.0
subroutine 4 10 40.0
pod 6 6 100.0
total 22 93 23.6


line stmt bran cond sub pod time code
1 2     2   13 use strict;
  2         3  
  2         91  
2 2     2   11 use warnings;
  2         4  
  2         181  
3              
4             package
5             XHTML::Instrumented::Form::ElementControl;
6              
7 2     2   10 use base 'XHTML::Instrumented::Control';
  2         5  
  2         187  
8              
9 2     2   13 use Data::Dumper;
  2         5  
  2         949  
10              
11             sub if
12             {
13 0     0 1   my $self = shift;
14              
15 0           my $x = 0;
16              
17 0 0         $x++ if defined $self->{value};
18 0 0         $x++ if defined $self->{default};
19 0 0         $x++ if defined $self->{required};
20              
21 0           $x;
22             }
23              
24             sub set_value
25             {
26 0     0 1   my $self = shift;
27 0           my $value = shift;
28 0 0         die if @_;
29              
30 0 0         if (my $type = ref($value)) {
31 0 0         die unless $type eq 'ARRAY';
32 0 0         if (@{$value} == 1) {
  0 0          
  0            
33 0           $self->{value} = $value->[0];
34             } elsif (@{$value} == 0) {
35 0           $self->{value} = '';
36             } else {
37 0           die 'bad data ' . "@{$value}";
  0            
38             }
39             } else {
40 0           $self->{value} = $value;
41             }
42             }
43              
44             sub set_label
45             {
46 0     0 1   my $self = shift;
47              
48 0           $self->{label} = shift;
49             }
50              
51             sub is_multi
52             {
53 0     0 1   0;
54             }
55              
56             sub value
57             {
58 0     0 1   my $self = shift;
59              
60 0 0         if ($self->is_multi) {
61 0           die $self;
62 0 0 0       $self->{value} || $self->{default} || [];
63             } else {
64 0 0         $self->{value} || $self->{default};
65             }
66             }
67              
68             sub required
69             {
70 0     0 1   my $self = shift;
71              
72 0 0 0       if (exists $self->{required} and $self->{required}) {
73 0 0         if (exists $self->{value}) {
74 0           !length($self->{value});
75             } else {
76 0           0;
77             }
78             } else {
79 0           0;
80             }
81             }
82              
83             1;
84             __END__