File Coverage

blib/lib/SparkX/Form/Field/Button.pm
Criterion Covered Total %
statement 9 10 90.0
branch n/a
condition n/a
subroutine 4 5 80.0
pod 2 2 100.0
total 15 17 88.2


line stmt bran cond sub pod time code
1             package SparkX::Form::Field::Button;
2             our $VERSION = '0.2102';
3              
4              
5             # ABSTRACT: A Button for SparkX::Form
6              
7 1     1   568 use Moose;
  1         1  
  1         6  
8 1     1   5321 use HTML::Tiny;
  1         1990  
  1         173  
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 'content' => (
19             isa => 'Str',
20             is => 'rw',
21             required => 0,
22             default => q(),
23             );
24              
25             sub to_html {
26 0     0 1 0 return shift->_render(HTML::Tiny->new(mode => 'html'));
27             }
28              
29             sub to_xhtml {
30 2     2 1 810 return shift->_render(HTML::Tiny->new(mode => 'xml'));
31             }
32              
33             sub _render {
34 2     2   71 my ($self, $html) = @_;
35              
36 2         58 return $html->button({value => $self->value, name => $self->name}, $self->content);
37             }
38              
39             __PACKAGE__->meta->make_immutable;
40              
41             1;
42              
43              
44              
45             =pod
46              
47             =head1 NAME
48              
49             SparkX::Form::Field::Button - A Button for SparkX::Form
50              
51             =head1 VERSION
52              
53             version 0.2102
54              
55             =head1 METHODS
56              
57             =head2 to_html() => Str
58              
59             Renders the field to HTML
60              
61             =head2 to_xhtml() => Str
62              
63             Renders the field to XHTML
64              
65             =head2 validate() => Bool
66              
67             Validates the field. Before composition with validators, always returns 1.
68              
69             =head1 SEE ALSO
70              
71             =over 4
72              
73             =item L<SparkX::Form> - The forms module this is to be used with
74              
75             =item L<SparkX::Form::BasicFields> - A collection of fields for use with C<Spark::Form>
76              
77             =back
78              
79              
80              
81             =head1 AUTHOR
82              
83             James Laver L<http://jameslaver.com>
84              
85             =head1 COPYRIGHT AND LICENSE
86              
87             This software is copyright (c) 2009 by James Laver C<< <sprintf qw(%s@%s.%s cpan jameslaver com)> >>.
88              
89             This is free software; you can redistribute it and/or modify it under
90             the same terms as the Perl 5 programming language system itself.
91              
92             =cut
93              
94              
95              
96             __END__
97