Mozilla-Mechanize
view release on metacpan or search on metacpan
lib/Mozilla/Mechanize/Input.pm view on Meta::CPAN
# Make sure only the last value is set for:
# select-one type with multiple values;
# XXX: not sure if same type in Mozilla
@values = ( $values[-1] ) if lc($self->type) eq 'select-one';
%vals = map { ( $_ => undef ) } @values;
for ( my $i = 0; $i < @options; $i++ ) {
$options[$i]->SetSelected(exists $vals{ $options[$i]->GetValue });
}
} else {
for ( my $i = 0; $i < @options; $i++ ) {
$options[$i]->GetSelected and
$vals{ $options[$i]->GetValue } = 1;
}
}
return keys %vals;
}
=head2 $input->radio_value( [$value] )
Locate all radio-buttons with the same name within this form. Now
uncheck all values that are not equal to C<$value>.
=cut
sub radio_value {
my $self = shift;
my $input = $self->{input};
return unless $self->type =~ /^radio/i;
my $form = Mozilla::Mechanize::Form->new($input->GetForm, $self->{moz});
my @radios = $form->_radio_group($self->name);
if (@_) {
my $value = shift;
for (@radios) {
$_->SetChecked(($_->GetValue eq $value) || 0);
}
}
my ($value) = map($_->GetValue, grep($_->GetChecked, @radios));
return $value;
}
=head2 $input->click
Calls the C<click()> method on the actual object.
=cut
sub click {
my $self = shift;
my $input = $self->{input};
$input->Click();
# XXX: if they didn't pass $moz to `new', they're stuck..
my $moz = $self->{moz} || return;
$moz->_wait_while_busy();
}
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 0.875 second using v1.01-cache-2.11-cpan-600a1bdf6e4 )