root/lang/perl/HTML-AutoForm/trunk/lib/HTML/AutoForm/Field/Option.pm @ 25263

Revision 25263, 0.6 kB (checked in by kazuho, 4 years ago)

initial import, although the tests fail

Line 
1package HTML::AutoForm::Field::Option;
2
3use strict;
4use warnings;
5use utf8;
6
7BEGIN {
8    Class::Accessor::Lite->mk_accessors(qw(value label selected));
9};
10
11sub new {
12    my $klass = shift;
13    my $self = bless {
14        @_ == 1 ? %{$_[0]} : @_,
15    }, $klass;
16    $self;
17}
18
19sub render {
20    my ($self, $values) = @_;
21    return HTML::AutoForm::_build_element(
22        'option',
23        $self,
24        ($values ? grep { $_ eq $self->{value} } @$values : $self->{selected})
25            ? { selected => 1 } : {},
26        { selected => 1 },
27        $self->{label},
28    );
29}
30
311;
Note: See TracBrowser for help on using the browser.