$mech->set_fields($feldname2=>$val2) or die;
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
sub set_fields { my $self = shift; my %fields = @_; my $form = $self->current_form or $self->die( 'No form defined' ); while ( my ( $field, $value ) = each %fields ) { if ( ref $value eq 'ARRAY' ) { $form->find_input( $field, undef, $value->[1])->value($value->[0] ); } else { $form->value($field => $value); } } # while } # set_fields()
1 2 3 4 5 6 7 8 9 10 11 12 13
sub value { my $self = shift; my $name = shift; my $number = shift || 1; my $form = $self->current_form; if ( $number > 1 ) { return $form->find_input( $name, undef, $number )->value(); } else { return $form->value( $name ); } } # value
1 2 3 4 5 6 7 8 9 10 11 12 13
sub value { my $self = shift; my $key = shift; my $input = $self->find_input($key); unless ($input) { Carp::croak("No such field '$key'") if $self->{strict}; return undef unless @_; $input = $self->push_input("text", { name => $key, value => "" }); } local $Carp::CarpLevel = 1; $input->value(@_); }