| Line | |
|---|
| 1 | package HTML::AutoForm::Field::InputSet; |
|---|
| 2 | |
|---|
| 3 | use strict; |
|---|
| 4 | use warnings; |
|---|
| 5 | use utf8; |
|---|
| 6 | |
|---|
| 7 | our @ISA; |
|---|
| 8 | BEGIN { |
|---|
| 9 | @ISA = qw(HTML::AutoForm::Field); |
|---|
| 10 | Class::Accessor::Lite->mk_accessors(qw(options)); |
|---|
| 11 | }; |
|---|
| 12 | |
|---|
| 13 | sub 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 | |
|---|
| 35 | sub render { |
|---|
| 36 | my ($self, $values) = @_; |
|---|
| 37 | my $html = join( |
|---|
| 38 | ' ', |
|---|
| 39 | map { |
|---|
| 40 | $_->render($values) |
|---|
| 41 | } @{$self->{options}}, |
|---|
| 42 | ); |
|---|
| 43 | $html; |
|---|
| 44 | } |
|---|
| 45 | |
|---|
| 46 | 1; |
|---|