Mojo::Transaction::HTTP::Role::Mechanize - Mechanize Mojo a little
use Mojo::UserAgent; use Mojo::Transaction::HTTP::Role::Mechanize; my $ua = Mojo::UserAgent->new; my $tx = $ua->get('/')->with_roles('+Mechanize'); # call submit immediately my $submit_tx = $tx->submit('#submit-id', username => 'fry'); $ua->start($submit_tx); # first extract form values my $values = $tx->extract_forms->first->val; $submit_tx = $tx->submit('#submit-id', counter => $values->{counter} + 3); $ua->start($submit_tx);
Role::Tiny based role to compose a form submission "trait" into Mojo::Transaction::HTTP.
Mojo::Transaction::HTTP::Role::Mechanize implements the following method.
$collection = $tx->extract_forms;
Returns a Mojo::Collection of Mojo::DOM elements with activated Mojo::DOM::Role::Form that contains all the forms of the page.
# result using selector $submit_tx = $tx->submit('#id', username => 'fry'); # result without selector using default submission $submit_tx = $tx->submit(username => 'fry'); # passing hash, rather than list, of values $submit_tx = $tx->submit({username => 'fry'}); # passing hash, rather than list, of values and a selector $submit_tx = $tx->submit('#id', {username => 'fry'});
Build a new Mojo::Transaction::HTTP object with "tx" in Mojo::UserAgent::Transactor and the contents of the form with the $id and merged values. If no selector is given, the first non-disabled button or appropriate input element (of type button, submit, or image) will be used for the submission.
form
$id
kiwiroy - Roy Storey kiwiroy@cpan.org
kiwiroy@cpan.org
tekki - Rolf Stöckli tekki@cpan.org
tekki@cpan.org
lindleyw - William Lindley wlindley+remove+this@wlindley.com
wlindley+remove+this@wlindley.com
This library is free software and may be distributed under the same terms as perl itself.
Mojo::DOM::Role::Form, Mojolicious.
To install Mojo::Transaction::HTTP::Role::Mechanize, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Mojo::Transaction::HTTP::Role::Mechanize
CPAN shell
perl -MCPAN -e shell install Mojo::Transaction::HTTP::Role::Mechanize
For more information on module installation, please visit the detailed CPAN module installation guide.