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