[Wellington-pm] A question about scopes
Grant McLean
grant at mclean.net.nz
Tue Mar 28 15:14:44 PST 2006
On Wed, 2006-03-29 at 09:34 +1100, Jacinta Richardson wrote:
> Grant McLean wrote:
>
> > I had to do something similar but got away with sticking to published
> > APIs like this:
> >
> > my($form) = $mech->forms;
> >
> > foreach my $input ($form->inputs) {
> > my $name = $input->name || next;
> > next unless $input->type eq 'checkbox';
> > next unless $name =~ /some_pattern/;
> > $input->check;
> > }
> >
> > $mech->submit;
> >
> > Was your requirement more esoteric?
>
> Probably not. I couldn't find a check method (I presume it belongs to
> HTML::Form)
Well it's documented in the HTML::Form POD, but strictly speaking the
method belongs to HTML::Form::Input or one of its descendants.
> and the way that *seemed* obvious from the mech documentation was this:
>
> foreach ( 1 .. 100 ) { # I know in advance that there will be 100
> my $value = $mech->value( $name, $_ );
> $mech->tick( $name, $value );
> }
>
> Except that value() returns undef when the element is not ticked,
Yes, the HTML::Form::ListInput (used for checkboxes) has the same
problem - the 'value' method returns undef if the input is not checked.
However there is also a 'possible_values' method which, for a checkbox,
returns a list of two values: undef or the value you're after. So you
could do something like this:
my($value) = grep { defined } $input->possible_values;
and then look in $value.
Regards
Grant
More information about the Wellington-pm
mailing list