File Coverage

blib/lib/XHTML/Instrumented/Form/Element.pm
Criterion Covered Total %
statement 15 69 21.7
branch 0 36 0.0
condition 0 4 0.0
subroutine 5 17 29.4
pod 12 12 100.0
total 32 138 23.1


line stmt bran cond sub pod time code
1 2     2   13 use strict;
  2         3  
  2         63  
2 2     2   11 use warnings;
  2         4  
  2         66  
3              
4             package
5             XHTML::Instrumented::Form::Element;
6              
7 2     2   7 use base 'XHTML::Instrumented::Form::ElementControl';
  2         4  
  2         208  
8              
9 2     2   12 use Params::Validate qw( validate SCALAR BOOLEAN HASHREF OBJECT ARRAYREF );
  2         6  
  2         202  
10              
11 2     2   12 use Carp qw (croak);
  2         3  
  2         1808  
12              
13             sub new
14             {
15 0     0 1   my $class = shift;
16 0           my %p = validate(@_, {
17             name => 1,
18             type => 1,
19             value => 0,
20             required => 0,
21             optional => 0,
22             default => 0,
23             remove => 0,
24             });
25              
26 0           bless({ %p }, $class);
27             }
28              
29             sub exp_args
30             {
31 0     0 1   my $self = shift;
32 0 0         die caller if ref $_[0];
33 0           my @extra = ();
34              
35 0 0         if (my $data = $self->{onclick}) {
36 0           push(@extra, 'onclick', $data);
37             }
38              
39 0           my $ret = $self->SUPER::exp_args(@_, name => $self->name, @extra);
40              
41 0           $ret;
42             }
43              
44             sub add_option
45             {
46 0     0 1   my $self = shift;
47 0           push(@{$self->{data}}, bless {@_}, 'XHTML::Instrumented::Form::Option');
  0            
48 0           $self;
49             }
50              
51             sub set_default
52             {
53 0     0 1   my $self = shift;
54              
55 0           $self->{default} = shift;
56             }
57              
58             sub value
59             {
60 0     0 1   my $self = shift;
61              
62 0           my $x;
63 0 0         if (defined $self->{value}) {
64 0           $x = $self->{value};
65             } else {
66 0   0       $x = $self->{default} || '';
67             }
68 0 0         if (ref($x)) {
69 0   0       return $x->[0] || '';
70             }
71              
72 0           $x;
73             }
74              
75             sub type
76             {
77 0     0 1   my $self = shift;
78 0           $self->{type};
79             }
80              
81             sub name
82             {
83 0     0 1   my $self = shift;
84 0 0         $self->{name} or die "unamed form element";
85             }
86              
87             sub args
88             {
89 0     0 1   my $self = shift;
90 0           my %ret = $self->SUPER::args(@_);
91              
92 0           $ret{name} = $self->name;
93              
94 0 0         if ($self->type eq 'text') {
    0          
    0          
    0          
    0          
    0          
    0          
95 0           $ret{value} = $self->value;
96             } elsif ($self->type eq 'hidden') {
97 0           $ret{value} = $self->value;
98             } elsif ($self->type eq 'textarea') {
99              
100             } elsif ($self->type eq 'checkbox') {
101 0 0         if ($self->checked($ret{value})) {
102 0           $ret{checked} = 'checked';
103             }
104             } elsif ($self->type eq 'radio') {
105 0 0         if ($ret{value} eq $self->value) {
106 0           $ret{checked} = 'checked';
107             }
108             } elsif ($self->type eq 'checkboxes') {
109             } elsif ($self->type eq 'submit') {
110             } else {
111 0           die "unknown type [" . $self->type . "]";
112             }
113              
114 0           %ret;
115             }
116              
117             sub expand_content
118             {
119 0     0 1   my $self = shift;
120 0           my @ret = ();
121              
122 0 0         if ($self->type eq 'textarea') {
123 0           @ret = ($self->value);
124             }
125 0           @ret;
126             }
127              
128             sub to_text
129             {
130 0     0 1   my $self = shift;
131 0           my %p = @_;
132              
133 0 0         die $p{tag} if $p{tag} eq 'form';
134              
135 0           my @ret = $self->SUPER::to_text(@_);
136              
137 0           @ret;
138             }
139              
140             sub optional
141             {
142 0     0 1   my $self = shift;
143 0 0         $self->{optional} || 0;
144             }
145              
146             sub required
147             {
148 0     0 1   my $self = shift;
149 0 0         $self->{required} || 0;
150             }
151              
152             1;
153              
154             __END__