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