From: Mischa POSLAWSKY Date: Wed, 22 Oct 2008 19:27:35 +0000 (+0000) Subject: XXX: row method X-Git-Url: http://git.shiar.net/perl/html-form-simple.git/commitdiff_plain XXX: row method --- diff --git a/lib/HTML/Form/Simple.pm b/lib/HTML/Form/Simple.pm index 7d02314..a722151 100644 --- a/lib/HTML/Form/Simple.pm +++ b/lib/HTML/Form/Simple.pm @@ -33,7 +33,7 @@ sub tag { # strip empty if it shouldn't be defined $attr->{$_} and $attr->{$_} eq '' and delete $attr->{$_} - for qw(id type class style); + for qw(id for type class style); my $return = '<' . $tag; @@ -248,6 +248,24 @@ sub check { $self->select($name, $rows, {%$attr, type => 'checkbox'}); } +sub row { + my $self = shift; + my ($name, $contents, $attr) = $self->_attr(2, @_); + + $contents = defined $contents && ref $contents ne 'HASH' + ? $self->quote($contents) : $self->text($name, $contents); + my $label = defined $attr->{label} + ? $self->quote(delete $attr->{label}) + : defined $name ? $self->quote($name) : ''; + + return $self->tag(label => {for => $name, %$attr}) + . $label + . '' + . (defined $, ? $, : ' ') + . $contents + ; +} + 1; __END__ diff --git a/t/html.t b/t/html.t index a82c916..08f0e6b 100644 --- a/t/html.t +++ b/t/html.t @@ -5,7 +5,7 @@ use warnings; use Test::More; -plan tests => 76; +plan tests => 80; use_ok('HTML::Form::Simple'); @@ -543,6 +543,32 @@ is_deeply( 'various checkboxes' ); +# row + +is( + $form->row(undef), + ' ', + 'empty row' +); + +is( + $form->row('test'), + ' ', + 'standard row' +); + +is( + $form->row('test', {type => 'password'}, {for => '', label => '"blah"'}), + ' ', + 'row options' +); + +is( + $form->row('test', '"scalar"', {for => ''}), + ' "scalar"', + 'row scalar' +); + # defaults my $defform = HTML::Form::Simple->new({foo => '<">', '' => 'empty', 0 => 0});