Mozilla-Mechanize
view release on metacpan or search on metacpan
lib/Mozilla/Mechanize/Form.pm view on Meta::CPAN
my $form = $self->{form};
my $typere = qr/.*/;
$type and $typere = $type =~ /^select/i ? qr/^$type/i : qr/^$type$/i;
if ( wantarray ) {
my( $cnt, @res ) = ( 0 );
for my $input ( $self->inputs ) {
if ( defined $name ) {
$input->name or next;
$input->name ne $name and next;
}
$input->type =~ $typere or next;
$cnt++;
$index && $index ne $cnt and next;
push @res, $input;
}
return @res;
} else {
$index ||= 1;
for my $input ( $self->inputs ) {
if ( defined $name ) {
$input->name or next;
$input->name ne $name and next;
}
$input->type =~ $typere or next;
--$index and next;
return $input;
}
return undef;
}
}
=head2 $form->value( $name[, $new_value] )
Get/Set the value for the input-control with specified name.
=cut
sub value {
my $self = shift;
my $input = $self->find_input( shift );
return $input->value( @_ );
}
=head2 $form->submit()
Submit this form. (Note: does B<not> trigger onSubmit.)
=cut
sub submit {
my $self = shift;
my $form = $self->{form};
$form->Submit();
# XXX: if they didn't pass $moz to `new', they're stuck..
my $moz = $self->{moz} || return;
$moz->_wait_while_busy();
}
=head2 $form->reset()
Reset inputs to their default values.
(Note: I added this method, though it wasn't in WWW::Mechanize.)
=cut
sub reset {
my $self = shift;
my $form = $self->{form};
$form->Reset();
# XXX: if they didn't pass $moz to `new', they're stuck..
my $moz = $self->{moz} || return;
$moz->_wait_while_busy();
}
=head2 $self->_radio_group( $name )
Returns a list of Mozilla::DOM::HTMLInputElement objects with name eq $name.
(Intended for use with Input.pm's radio_value method.)
=cut
sub _radio_group {
my $self = shift;
my $form = $self->{form};
my $name = shift or return;
my @rgroup;
my @inputs = $form->GetElementsByTagName('input');
my $iid = Mozilla::DOM::HTMLInputElement->GetIID;
foreach my $input (map {$_->QueryInterface($iid)} @inputs) {
next unless lc($input->GetType) eq 'radio';
next unless lc($input->GetName) eq lc($name);
push @rgroup, $input;
}
return wantarray ? @rgroup : \@rgroup;
}
sub debug {
my ($self, $msg) = @_;
my (undef, $file, $line) = caller();
print STDERR "$msg at $file line $line\n" if $self->{debug};
}
1;
__END__
=head1 COPYRIGHT AND LICENSE
Copyright 2005,2009 Scott Lanning <slanning@cpan.org>. All rights reserved.
This library is free software; you can redistribute it and/or modify
it under the same terms as Perl itself.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
=cut
( run in 1.042 second using v1.01-cache-2.11-cpan-5a3173703d6 )