File Coverage

blib/lib/SparkX/Form/Field/Radio.pm
Criterion Covered Total %
statement 13 14 92.8
branch 2 2 100.0
condition n/a
subroutine 5 6 83.3
pod 2 2 100.0
total 22 24 91.6


line stmt bran cond sub pod time code
1             package SparkX::Form::Field::Radio;
2             our $VERSION = '0.2102';
3              
4              
5             # ABSTRACT: A set of radio buttons for SparkX::Form
6              
7 1     1   581 use Moose;
  1         1  
  1         7  
8 1     1   6053 use HTML::Tiny;
  1         2159  
  1         348  
9              
10             extends 'Spark::Form::Field';
11             with 'Spark::Form::Field::Role::Printable::HTML',
12             'Spark::Form::Field::Role::Printable::XHTML';
13              
14             has '+value' => (
15             isa => 'Str',
16             );
17              
18             has options => (
19             isa => 'ArrayRef',
20             is => 'rw',
21             required => 0,
22             lazy => 1,
23             default => sub { return shift->value },
24             );
25              
26             sub to_html {
27 0     0 1 0 return shift->_render(HTML::Tiny->new(mode => 'html'));
28             }
29              
30             sub to_xhtml {
31 1     1 1 12 return shift->_render(HTML::Tiny->new(mode => 'xml'));
32             }
33              
34             sub _render_element {
35 3     3   6 my ($self, $html, $option) = @_;
36 3 100       130 return $html->input({
37             type => 'radio',
38             value => $option,
39             ($self->value eq $option ? (checked => 'checked') : ()),
40             name => $self->name,
41             });
42              
43             }
44              
45             sub _render {
46 1     1   42 my ($self, $html) = @_;
47 1         2 return join q{ }, map { $self->_render_element($html, $_) } @{$self->options};
  3         237  
  1         38  
48             }
49             __PACKAGE__->meta->make_immutable;
50             1;
51              
52              
53              
54             =pod
55              
56             =head1 NAME
57              
58             SparkX::Form::Field::Radio - A set of radio buttons for SparkX::Form
59              
60             =head1 VERSION
61              
62             version 0.2102
63              
64             =head1 METHODS
65              
66             =head2 to_html() => Str
67              
68             Renders the field(s) to HTML
69              
70             =head2 to_xhtml() => Str
71              
72             Renders the field(s) to XHTML
73              
74             =head2 validate() => Bool
75              
76             Validates the field. Before composition with validators, always returns 1.
77              
78             =head1 SEE ALSO
79              
80             =over 4
81              
82             =item L<SparkX::Form> - The forms module this is to be used with
83              
84             =item L<SparkX::Form::BasicFields> - A collection of fields for use with C<Spark::Form>
85              
86             =back
87              
88              
89              
90             =head1 AUTHOR
91              
92             James Laver L<http://jameslaver.com>
93              
94             =head1 COPYRIGHT AND LICENSE
95              
96             This software is copyright (c) 2009 by James Laver C<< <sprintf qw(%s@%s.%s cpan jameslaver com)> >>.
97              
98             This is free software; you can redistribute it and/or modify it under
99             the same terms as the Perl 5 programming language system itself.
100              
101             =cut
102              
103              
104              
105             __END__
106