root/lang/perl/MENTA/trunk/extlib/HTML/AutoForm/Field/InputSet.pm @ 25497

Revision 25497, 1.0 kB (checked in by tokuhirom, 6 years ago)

HTML::AutoForm? をとりあえず足してみるよ

Line 
1package HTML::AutoForm::Field::InputSet;
2
3use strict;
4use warnings;
5use utf8;
6
7our @ISA;
8BEGIN {
9    @ISA = qw(HTML::AutoForm::Field);
10    Class::Accessor::Lite->mk_accessors(qw(options));
11};
12
13sub new {
14    my $klass = shift;
15    my $self = $klass->SUPER::new(@_);
16    my @options; # build new list
17    if (my $in = $self->{options}) {
18        die 'options should be in value => attributes form'
19            unless @$in % 2 == 0;
20        for (my $i = 0; $i < @$in; $i += 2) {
21            my $value = $in->[$i];
22            my $attributes = $in->[$i + 1];
23            push @options, HTML::AutoForm::Field::InputCheckable->new(
24                label  => ucfirst $value,
25                %$attributes,
26                value  => $value,
27                parent => $self,
28            );
29        }
30    }
31    $self->{options} = \@options;
32    $self;
33}
34
35sub render {
36    my ($self, $values) = @_;
37    my $html = join(
38        ' ',
39        map {
40            $_->render($values)
41        } @{$self->{options}},
42    );
43    $html;
44}
45
461;
Note: See TracBrowser for help on using the browser.