Mozilla-Mechanize
view release on metacpan or search on metacpan
lib/Mozilla/Mechanize.pm view on Meta::CPAN
my $uri = $self->uri
? URI->new_abs($url, $self->uri->as_string)
: URI->new($url);
# XXX: how to add headers?
# $agent->navigate({ URL => $uri->as_string,
# Headers => $self->_extra_headers($uri) });
$agent->embedded->load_url($uri->as_string);
$self->_wait_while_busy;
}
=head2 $moz->reload()
Reload the page.
=cut
sub reload {
$_[0]->agent->embedded->reload('reloadnormal');
$_[0]->_wait_while_busy;
}
=head2 $moz->back()
Go back a page in the browser history.
=cut
sub back {
$_[0]->agent->embedded->go_back;
$_[0]->_wait_while_busy;
}
=head1 STATUS METHODS
=head2 $moz->success
B<XXX: I don't know how to implement this yet.
So this always returns true for now.>
In fact, if a URL doesn't exist, it'll pop up a dialog. :/
lib/Mozilla/Mechanize.pm view on Meta::CPAN
}
# Continue only at the top-level
return if defined $subelement;
$self->{images} = \@images;
return wantarray ? @{ $self->{forms} } : $self->{forms};
}
}
=head2 $self->_wait_while_busy()
This adds a "single-shot" idle callback that does Gtk2->main_quit,
then does Gtk2->main. The result is that whenever the UI becomes idle
it will exit the main loop. Thanks to muppet for the idea.
This is repeated until the net_stop event fires, indicating that
the new page has finished loading. (Note therefore that you can only
call this when you expect a new page to load.)
=cut
sub _wait_while_busy {
my $self = shift;
my $agent = $self->agent;
do {
Glib::Idle->add(sub {
Gtk2->main_quit;
FALSE; # uninstall
}, undef, G_PRIORITY_LOW);
Gtk2->main;
} until $agent->{netstopped};
lib/Mozilla/Mechanize/Form.pm view on Meta::CPAN
=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 {
lib/Mozilla/Mechanize/Input.pm view on Meta::CPAN
=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.
lib/Mozilla/Mechanize/Link.pm view on Meta::CPAN
my $event = $docevent->CreateEvent('MouseEvents');
$event->InitEvent('click', 1, 1);
# Dispatch the click event
my $etiid = Mozilla::DOM::EventTarget->GetIID();
my $target = $link->QueryInterface($etiid);
$target->DispatchEvent($event);
# 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.
use_ok 'Mozilla::Mechanize';
my $uri = URI::file->new_abs( "t/html/jstest.html" )->as_string;
my $new_uri = URI::file->new_abs( "t/html/jstestok.html" )->as_string;
isa_ok my $moz = Mozilla::Mechanize->new(visible => 0), 'Mozilla::Mechanize';
$moz->get( $uri );
sleep 1; # XXX: problem with _wait_while_busy
is $moz->title, 'JS Redirection Success', "Right title()";
# for some reason, submits cause Mozilla to append a question mark,
# so this just tests if the beginning part of the URL is right
like $moz->uri, qr/^$new_uri/, "Got the new uri()";
$moz->close();
ok my $prev_uri = $moz->uri, "Got an uri back";
my $form = $moz->form_number(1);
isa_ok( $form, 'Mozilla::Mechanize::Form' );
$moz->tick("foo","hello");
$moz->tick("foo","bye");
$moz->untick("foo","hello");
$moz->click( 'submit' ); $moz->_wait_while_busy;
like $moz->uri, qr/[&?]foo=bye\b/, "(un)tick actions [foo=bye]";
like $moz->uri, qr/[&?]submit=Submit\b/, "(un)tick actions [submit=Submit]";
unlike $moz->uri, qr/[&?]foo=hello\b/, "(un)tick actions ![foo=hello]";
$moz->close();
( run in 0.299 second using v1.01-cache-2.11-cpan-3cd7ad12f66 )