App-Pod
view release on metacpan or search on metacpan
t/01-usage-simple.t view on Meta::CPAN
' f - Turn string into a Mojo::File object.',
' g - Perform GET request with "get" in Mojo::UserAg ...',
' h - Perform HEAD request with "head" in Mojo::User ...',
' j - Encode Perl data structure or decode JSON with ...',
' l - Turn a string into a Mojo::URL object.',
' n - Benchmark block and print the results to STDER ...',
' o - Perform OPTIONS request with "options" in Mojo ...',
' p - Perform POST request with "post" in Mojo::User ...',
' r - Dump a Perl data structure with "dumper" in Mo ...',
' t - Perform PATCH request with "patch" in Mojo::Us ...',
' u - Perform PUT request with "put" in Mojo::UserAg ...',
' x - Turn HTML/XML input into Mojo::DOM object.',
'',
'Use --all (or -a) to see all methods.',
],
},
{
name => "Module - ojo, no_color",
input => [qw( ojo --no_color )],
expected_output => [
'',
t/01-usage-simple.t view on Meta::CPAN
' f - Turn string into a Mojo::File object.',
' g - Perform GET request with "get" in Mojo::UserAg ...',
' h - Perform HEAD request with "head" in Mojo::User ...',
' j - Encode Perl data structure or decode JSON with ...',
' l - Turn a string into a Mojo::URL object.',
' n - Benchmark block and print the results to STDER ...',
' o - Perform OPTIONS request with "options" in Mojo ...',
' p - Perform POST request with "post" in Mojo::User ...',
' r - Dump a Perl data structure with "dumper" in Mo ...',
' t - Perform PATCH request with "patch" in Mojo::Us ...',
' u - Perform PUT request with "put" in Mojo::UserAg ...',
' x - Turn HTML/XML input into Mojo::DOM object.',
'',
'Use --all (or -a) to see all methods.',
],
},
{
name => "Module - Mojo2::UserAgent",
input => [qw( Mojo2::UserAgent )],
expected_output => [
'',
t/01-usage-simple.t view on Meta::CPAN
' max_connections - Maximum number of keep-alive ...',
' max_redirects - Maximum number of redirects t ...',
' max_response_size - Maximum response size in byte ...',
' options - Perform blocking OPTIONS requ ...',
' options_p - Same as "options", but perfor ...',
' patch - Perform blocking PATCH reques ...',
' patch_p - Same as "patch", but performs ...',
' post - Perform blocking POST request ...',
' post_p - Same as "post", but performs ...',
' proxy - Proxy manager, defaults to a ...',
' put - Perform blocking PUT request ...',
' put_p - Same as "put", but performs a ...',
' request_timeout - Maximum amount of time in sec ...',
' server - Application server relative U ...',
' socket_options - Additional options for IO::So ...',
' start - Emitted whenever a new transa ...',
' start_p - Same as "start", but performs ...',
' transactor - Transaction builder, defaults ...',
' websocket - Open a non-blocking WebSocket ...',
' websocket_p - Same as "websocket", but retu ...',
'',
t/cpan/Mojo2/UserAgent.pm view on Meta::CPAN
has key => sub { $ENV{MOJO_KEY_FILE} };
has max_connections => 5;
has max_redirects => sub { $ENV{MOJO_MAX_REDIRECTS} || 0 };
has proxy => sub { Mojo::UserAgent::Proxy->new };
has request_timeout => sub { $ENV{MOJO_REQUEST_TIMEOUT} // 0 };
has server => sub { Mojo::UserAgent::Server->new( ioloop => shift->ioloop ) };
has socket_options => sub { {} };
has transactor => sub { Mojo::UserAgent::Transactor->new };
# Common HTTP methods
for my $name ( qw(DELETE GET HEAD OPTIONS PATCH POST PUT) ) {
monkey_patch __PACKAGE__, lc $name, sub {
my ( $self, $cb ) = ( shift, ref $_[-1] eq 'CODE' ? pop : undef );
return $self->start( $self->build_tx( $name, @_ ), $cb );
};
monkey_patch __PACKAGE__, lc( $name ) . '_p', sub {
my $self = shift;
return $self->start_p( $self->build_tx( $name, @_ ) );
};
}
t/cpan/Mojo2/UserAgent.pm view on Meta::CPAN
# Say hello to the Unicode snowman and include an Accept header
say $ua->get('www.â.net?hello=there' => {Accept => '*/*'})->result->body;
# Extract data from HTML and XML resources with CSS selectors
say $ua->get('www.perl.org')->result->dom->at('title')->text;
# Scrape the latest headlines from a news site
say $ua->get('blogs.perl.org')->result->dom->find('h2 > a')->map('text')->join("\n");
# IPv6 PUT request with Content-Type header and content
my $tx = $ua->put('[::1]:3000' => {'Content-Type' => 'text/plain'} => 'Hi!');
# Quick JSON API request with Basic authentication
my $url = Mojo::URL->new('https://example.com/test.json')->userinfo('sri:â');
my $value = $ua->get($url)->result->json;
# JSON POST (application/json) with TLS certificate authentication
my $tx = $ua->cert('tls.crt')->key('tls.key')->post('https://example.com' => json => {top => 'secret'});
# Form POST (application/x-www-form-urlencoded)
t/cpan/Mojo2/UserAgent.pm view on Meta::CPAN
# Disable compression
$ua->transactor->compressed(0);
=head1 METHODS
L<Mojo::UserAgent> inherits all methods from L<Mojo::EventEmitter> and implements the following new ones.
=head2 build_tx
my $tx = $ua->build_tx(GET => 'example.com');
my $tx = $ua->build_tx(PUT => 'http://example.com' => {Accept => '*/*'} => 'Content!');
my $tx = $ua->build_tx(PUT => 'http://example.com' => {Accept => '*/*'} => form => {a => 'b'});
my $tx = $ua->build_tx(PUT => 'http://example.com' => {Accept => '*/*'} => json => {a => 'b'});
Generate L<Mojo::Transaction::HTTP> object with L<Mojo::UserAgent::Transactor/"tx">.
# Request with custom cookie
my $tx = $ua->build_tx(GET => 'https://example.com/account');
$tx->req->cookies({name => 'user', value => 'sri'});
$tx = $ua->start($tx);
# Deactivate gzip compression
my $tx = $ua->build_tx(GET => 'example.com');
t/cpan/Mojo2/UserAgent.pm view on Meta::CPAN
warn "Connection error: $err";
})->wait;
=head2 put
my $tx = $ua->put('example.com');
my $tx = $ua->put('http://example.com' => {Accept => '*/*'} => 'Content!');
my $tx = $ua->put('http://example.com' => {Accept => '*/*'} => form => {a => 'b'});
my $tx = $ua->put('http://example.com' => {Accept => '*/*'} => json => {a => 'b'});
Perform blocking C<PUT> request and return resulting L<Mojo::Transaction::HTTP> object, takes the same arguments as
L<Mojo::UserAgent::Transactor/"tx"> (except for the C<PUT> method, which is implied). You can also append a callback to
perform requests non-blocking.
$ua->put('http://example.com' => json => {a => 'b'} => sub ($ua, $tx) { say $tx->result->body });
Mojo::IOLoop->start unless Mojo::IOLoop->is_running;
=head2 put_p
my $promise = $ua->put_p('http://example.com');
Same as L</"put">, but performs all requests non-blocking and returns a L<Mojo::Promise> object instead of accepting a
t/cpan/ojo.pm view on Meta::CPAN
Perform C<PATCH> request with L<Mojo::UserAgent/"patch"> and return resulting L<Mojo::Message::Response> object.
=head2 u
my $res = u('example.com');
my $res = u('http://example.com' => {Accept => '*/*'} => 'Hi!');
my $res = u('http://example.com' => {Accept => '*/*'} => form => {a => 'b'});
my $res = u('http://example.com' => {Accept => '*/*'} => json => {a => 'b'});
Perform C<PUT> request with L<Mojo::UserAgent/"put"> and return resulting L<Mojo::Message::Response> object.
=head2 x
my $dom = x('<div>Hello!</div>');
Turn HTML/XML input into L<Mojo::DOM> object.
$ perl -Mojo -E 'say x(f("test.html")->slurp)->at("title")->text'
[UnicodeTest: I ⥠Mojolicious!]
( run in 0.273 second using v1.01-cache-2.11-cpan-4e96b696675 )