PROXY  WHOIS  RQUOTE  TEXTS  SOFT  FOREX  BBOARD
 Music  Philosophy  Code  Literature  Russian

= ROOT|Technical|Code_Examples|Perl|site_perl|HTML|Form.pm =

page 7 of 15



not return anything.

=cut

sub try_others
{
    my($self, $cb) = @_;
    my @try;
    for (@{$self->{'inputs'}}) {
	my @not_tried_yet = $_->other_possible_values;
	next unless @not_tried_yet;
	push(@try, [\@not_tried_yet, $_]);
    }
    return unless @try;
    $self->_try($cb, \@try, 0);
}

sub _try
{
    my($self, $cb, $try, $i) = @_;
    for (@{$try->[$i][0]}) {
	$try->[$i][1]->value($_);
	&$cb($self);
	$self->_try($cb, $try, $i+1) if $i+1 < @$try;
    }
}


=item $request = $form->make_request

Will return an C<HTTP::Request> object that reflects the current setting
of the form.  You might want to use the click() method instead.

=cut

sub make_request
{
    my $self = shift;
    my $method  = uc $self->{'method'};
    my $uri     = $self->{'action'};
    my $enctype = $self->{'enctype'};
    my @form    = $self->form;

    if ($method eq "GET") {
	require HTTP::Request;
	$uri = URI->new($uri, "http");
	$uri->query_form(@form);
	return HTTP::Request->new(GET => $uri);
    }
    elsif ($method eq "POST") {
	require HTTP::Request::Common;
	return HTTP::Request::Common::POST($uri, \@form,
					   Content_Type => $enctype);
    }
    else {
	Carp::croak("Unknown method '$method'");
    }
}


=item $request = $form->click

=item $request = $form->click( $name )

=item $request = $form->click( $x, $y )

=item $request = $form->click( $name, $x, $y )

Will "click" on the first clickable input (which will be of type
C<submit> or C<image>).  The result of clicking is an C<HTTP::Request>
object that can then be passed to C<LWP::UserAgent> if you want to
obtain the server response.

If a $name is specified, we will click on the first clickable input
with the given name, and the method will croak if no clickable input
with the given name is found.  If $name is I<not> specified, then it
is ok if the form contains no clickable inputs.  In this case the
click() method returns the same request as the make_request() method
would do.

If there are multiple clickable inputs with the same name, then there
is no way to get the click() method of the C<HTML::Form> to click on
any but the first.  If you need this you would have to locate the
input with find_input() and invoke the click() method on the given
input yourself.

A click coordinate pair can also be provided, but this only makes a
difference if you clicked on an image.  The default coordinate is
(1,1).  The upper-left corner of the image is (0,0), but some badly
coded CGI scripts are known to not recognize this.  Therefore (1,1) was
selected as a safer default.

=cut

sub click
{
    my $self = shift;
    my $name;
    $name = shift if (@_ % 2) == 1;  # odd number of arguments

=7=

1|2|3|4|5|6| < PREV = PAGE 7 = NEXT > |8|9|10|11|12|13|14|15

UP TO ROOT | UP TO DIR | TO FIRST PAGE

Google
 


E-mail Facebook Google Digg del.icio.us BlinkList Fark Furl Ma.gnolia Netscape NewsVine Reddit Slashdot Spurl StumbleUpon Technorati YahooMyWeb LiveJournal Blogmarks TwitThis Live News2.ru BobrDobr.ru Memori.ru MoeMesto.ru

0.00653195 wallclock secs ( 0.01 usr + 0.01 sys = 0.02 CPU)