Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
more consistent examples
  • Loading branch information
kraih committed May 5, 2013
1 parent 2918bb2 commit 3a7aa40
Show file tree
Hide file tree
Showing 11 changed files with 60 additions and 60 deletions.
2 changes: 1 addition & 1 deletion lib/Mojo.pm
Expand Up @@ -130,7 +130,7 @@ plugins, since non-blocking requests that are already in progress will
interfere with new blocking ones.
# Perform blocking request
my $body = $app->ua->get('mojolicio.us')->res->body;
my $body = $app->ua->get('example.com')->res->body;
=head1 METHODS
Expand Down
2 changes: 1 addition & 1 deletion lib/Mojo/Headers.pm
Expand Up @@ -453,7 +453,7 @@ Shortcut for the C<Range> header.
=head2 referrer
my $referrer = $headers->referrer;
$headers = $headers->referrer('http://mojolicio.us');
$headers = $headers->referrer('http://example.com');
Shortcut for the C<Referer> header, there was a typo in RFC 2068 which
resulted in C<Referer> becoming an official header.
Expand Down
2 changes: 1 addition & 1 deletion lib/Mojo/IOLoop/Client.pm
Expand Up @@ -149,7 +149,7 @@ Mojo::IOLoop::Client - Non-blocking TCP client
my ($client, $err) = @_;
...
});
$client->connect(address => 'mojolicio.us', port => 80);
$client->connect(address => 'example.com', port => 80);
# Start reactor if necessary
$client->reactor->start unless $client->reactor->is_running;
Expand Down
2 changes: 1 addition & 1 deletion lib/Mojo/Transaction/HTTP.pm
Expand Up @@ -169,7 +169,7 @@ Mojo::Transaction::HTTP - HTTP transaction
# Client
my $tx = Mojo::Transaction::HTTP->new;
$tx->req->method('GET');
$tx->req->url->parse('http://mojolicio.us');
$tx->req->url->parse('http://example.com');
$tx->req->headers->accept('application/json');
say $tx->res->code;
say $tx->res->headers->content_type;
Expand Down
36 changes: 18 additions & 18 deletions lib/Mojo/URL.pm
Expand Up @@ -397,14 +397,14 @@ C<wss> schemes and preserve scheme data for all unknown ones.
Path part of this URL, relative paths will be merged with the existing path,
defaults to a L<Mojo::Path> object.
# "http://mojolicio.us/DOM/HTML"
Mojo::URL->new('http://mojolicio.us/perldoc/Mojo')->path('/DOM/HTML');
# "http://example.com/DOM/HTML"
Mojo::URL->new('http://example.com/perldoc/Mojo')->path('/DOM/HTML');
# "http://mojolicio.us/perldoc/DOM/HTML"
Mojo::URL->new('http://mojolicio.us/perldoc/Mojo')->path('DOM/HTML');
# "http://example.com/perldoc/DOM/HTML"
Mojo::URL->new('http://example.com/perldoc/Mojo')->path('DOM/HTML');
# "http://mojolicio.us/perldoc/Mojo/DOM/HTML"
Mojo::URL->new('http://mojolicio.us/perldoc/Mojo/')->path('DOM/HTML');
# "http://example.com/perldoc/Mojo/DOM/HTML"
Mojo::URL->new('http://example.com/perldoc/Mojo/')->path('DOM/HTML');
=head2 protocol
Expand All @@ -413,7 +413,7 @@ defaults to a L<Mojo::Path> object.
Normalized version of C<scheme>.
# "http"
Mojo::URL->new('HtTp://mojolicio.us')->protocol;
Mojo::URL->new('HtTp://example.com')->protocol;
=head2 query
Expand All @@ -427,22 +427,22 @@ Query part of this URL, pairs in an array will be merged and pairs in a hash
appended, defaults to a L<Mojo::Parameters> object.
# "2"
Mojo::URL->new('http://mojolicio.us?a=1&b=2')->query->param('b');
Mojo::URL->new('http://example.com?a=1&b=2')->query->param('b');
# "http://mojolicio.us?a=2&c=3"
Mojo::URL->new('http://mojolicio.us?a=1&b=2')->query(a => 2, c => 3);
# "http://example.com?a=2&c=3"
Mojo::URL->new('http://example.com?a=1&b=2')->query(a => 2, c => 3);
# "http://mojolicio.us?a=2&a=3"
Mojo::URL->new('http://mojolicio.us?a=1&b=2')->query(a => [2, 3]);
# "http://example.com?a=2&a=3"
Mojo::URL->new('http://example.com?a=1&b=2')->query(a => [2, 3]);
# "http://mojolicio.us?a=2&b=2&c=3"
Mojo::URL->new('http://mojolicio.us?a=1&b=2')->query([a => 2, c => 3]);
# "http://example.com?a=2&b=2&c=3"
Mojo::URL->new('http://example.com?a=1&b=2')->query([a => 2, c => 3]);
# "http://mojolicio.us?b=2"
Mojo::URL->new('http://mojolicio.us?a=1&b=2')->query([a => undef]);
# "http://example.com?b=2"
Mojo::URL->new('http://example.com?a=1&b=2')->query([a => undef]);
# "http://mojolicio.us?a=1&b=2&a=2&c=3"
Mojo::URL->new('http://mojolicio.us?a=1&b=2')->query({a => 2, c => 3});
# "http://example.com?a=1&b=2&a=2&c=3"
Mojo::URL->new('http://example.com?a=1&b=2')->query({a => 2, c => 3});
=head2 to_abs
Expand Down
2 changes: 1 addition & 1 deletion lib/Mojo/UserAgent.pm
Expand Up @@ -874,7 +874,7 @@ append a callback to perform requests non-blocking.
=head2 need_proxy
my $success = $ua->need_proxy('intranet.mojolicio.us');
my $success = $ua->need_proxy('intranet.example.com');
Check if request for domain would use a proxy server.
Expand Down
10 changes: 5 additions & 5 deletions lib/Mojo/UserAgent/Transactor.pm
Expand Up @@ -262,10 +262,10 @@ Mojo::UserAgent::Transactor - User agent transactor
# Simple GET request
my $t = Mojo::UserAgent::Transactor->new;
say $t->tx(GET => 'http://mojolicio.us')->req->to_string;
say $t->tx(GET => 'http://example.com')->req->to_string;
# PATCH request with "Do Not Track" header and content
say $t->tx(PATCH => 'mojolicio.us' => {DNT => 1} => 'Hi!')->req->to_string;
say $t->tx(PATCH => 'example.com' => {DNT => 1} => 'Hi!')->req->to_string;
# POST request with form data
say $t->tx(POST => 'example.com' => form => {a => 'b'})->req->to_string;
Expand Down Expand Up @@ -351,14 +351,14 @@ Versatile general purpose L<Mojo::Transaction::HTTP> transaction builder for
requests, with support for content generators.
# Inspect generated request
say $t->tx(GET => 'mojolicio.us' => {DNT => 1} => 'Bye!')->req->to_string;
say $t->tx(GET => 'example.com' => {DNT => 1} => 'Bye!')->req->to_string;
# Streaming response
my $tx = $t->tx(GET => 'http://mojolicio.us');
my $tx = $t->tx(GET => 'http://example.com');
$tx->res->body(sub { say $_[1] });
# Custom socket
my $tx = $t->tx(GET => 'http://mojolicio.us');
my $tx = $t->tx(GET => 'http://example.com');
$tx->connection($sock);
# Generate query parameters
Expand Down
6 changes: 3 additions & 3 deletions lib/Mojolicious/Controller.pm
Expand Up @@ -547,7 +547,7 @@ implements the following new ones.
Access request cookie values and create new response cookies.
# Create response cookie with domain and expiration date
$c->cookie(user => 'sri', {domain => 'mojolicio.us', expires => time + 60});
$c->cookie(user => 'sri', {domain => 'example.com', expires => time + 60});
=head2 finish
Expand Down Expand Up @@ -918,11 +918,11 @@ Get L<Mojo::UserAgent> object from L<Mojo/"ua">.
my $ua = $c->app->ua;
# Blocking
my $tx = $c->ua->get('http://mojolicio.us');
my $tx = $c->ua->get('http://example.com');
my $tx = $c->ua->post('example.com/login' => form => {user => 'mojo'});
# Non-blocking
$c->ua->get('http://mojolicio.us' => sub {
$c->ua->get('http://example.com' => sub {
my ($ua, $tx) = @_;
$c->render_data($tx->res->body);
});
Expand Down
18 changes: 9 additions & 9 deletions lib/Mojolicious/Guides/Cookbook.pod
Expand Up @@ -804,7 +804,7 @@ You can just add username and password to the URL.
use Mojo::UserAgent;

my $ua = Mojo::UserAgent->new;
say $ua->get('https://sri:secret@mojolicio.us/hideout')->res->body;
say $ua->get('https://sri:secret@example.com/hideout')->res->body;

=head2 Decorating followup requests

Expand Down Expand Up @@ -845,22 +845,22 @@ Generate the same type of content repeatedly for multiple requests.
});

# Send multiple files streaming via PUT and POST
$ua->put('http://mojolicio.us/upload' => stream => '/home/sri/mojo.png');
$ua->post('http://mojolicio.us/upload' => stream => '/home/sri/mango.png');
$ua->put('http://example.com/upload' => stream => '/home/sri/mojo.png');
$ua->post('http://example.com/upload' => stream => '/home/sri/mango.png');

The C<json> and C<form> content generators are always available.

use Mojo::UserAgent;

# Send JSON content via PATCH
my $ua = Mojo::UserAgent->new;
my $tx = $ua->patch('http://api.mojolicio.us' => json => {foo => 'bar'});
my $tx = $ua->patch('http://api.example.com' => json => {foo => 'bar'});

# Send "application/x-www-form-urlencoded" content via POST
my $tx2 = $ua->post('http://search.mojolicio.us' => form => {q => 'test'});
my $tx2 = $ua->post('http://search.example.com' => form => {q => 'test'});

# Send "multipart/form-data" content via PUT
my $tx3 = $ua->put('http://upload.mojolicio.us' =>
my $tx3 = $ua->put('http://upload.example.com' =>
form => {test => {content => 'Hello World!'}});

For more information about available content generators see also
Expand All @@ -875,7 +875,7 @@ L<Mojo::UserAgent> makes it actually easy.

# Build a normal transaction
my $ua = Mojo::UserAgent->new;
my $tx = $ua->build_tx(GET => 'http://mojolicio.us');
my $tx = $ua->build_tx(GET => 'http://example.com');

# Replace "read" events to disable default content parser
$tx->res->content->unsubscribe('read')->on(read => sub {
Expand All @@ -898,7 +898,7 @@ Sending a streaming request is almost just as easy.

# Build a normal transaction
my $ua = Mojo::UserAgent->new;
my $tx = $ua->build_tx(GET => 'http://mojolicio.us');
my $tx = $ua->build_tx(GET => 'http://example.com');

# Prepare content
my $content = 'Hello world!';
Expand Down Expand Up @@ -948,7 +948,7 @@ Uploading a large file is even easier.

# Upload file via POST and "multipart/form-data"
my $ua = Mojo::UserAgent->new;
$ua->post('mojolicio.us/upload' =>
$ua->post('example.com/upload' =>
form => {image => {file => '/home/sri/hello.png'}});

And once again you don't have to worry about memory usage, all data will be
Expand Down
6 changes: 3 additions & 3 deletions lib/Mojolicious/Plugin/Mount.pm
Expand Up @@ -41,13 +41,13 @@ Mojolicious::Plugin::Mount - Application mount plugin
$example->to(message => 'It works great!');
# Mount application with host
plugin Mount => {'mojolicio.us' => '/home/sri/myapp.pl'};
plugin Mount => {'example.com' => '/home/sri/myapp.pl'};
# Host and path
plugin Mount => {'mojolicio.us/myapp' => '/home/sri/myapp.pl'};
plugin Mount => {'example.com/myapp' => '/home/sri/myapp.pl'};
# Or even hosts with wildcard subdomains
plugin Mount => {'*.mojolicio.us/myapp' => '/home/sri/myapp.pl'};
plugin Mount => {'*.example.com/myapp' => '/home/sri/myapp.pl'};
=head1 DESCRIPTION
Expand Down
34 changes: 17 additions & 17 deletions lib/ojo.pm
Expand Up @@ -65,12 +65,12 @@ A collection of automatically exported functions for fun Perl oneliners. Ten
redirects will be followed by default, you can change this behavior with the
MOJO_MAX_REDIRECTS environment variable.
$ MOJO_MAX_REDIRECTS=0 perl -Mojo -E 'say g("mojolicio.us")->code'
$ MOJO_MAX_REDIRECTS=0 perl -Mojo -E 'say g("example.com")->code'
Proxy detection is enabled by default, but you can disable it with the
MOJO_PROXY environment variable.
$ MOJO_PROXY=0 perl -Mojo -E 'say g("mojolicio.us")->body'
$ MOJO_PROXY=0 perl -Mojo -E 'say g("example.com")->body'
=head1 FUNCTIONS
Expand Down Expand Up @@ -102,16 +102,16 @@ Turn list into a L<Mojo::Collection> object.
=head2 d
my $res = d('mojolicio.us');
my $res = d('http://mojolicio.us' => {DNT => 1} => 'Hi!');
my $res = d('example.com');
my $res = d('http://example.com' => {DNT => 1} => 'Hi!');
Perform C<DELETE> request with L<Mojo::UserAgent/"delete"> and return
resulting L<Mojo::Message::Response> object.
=head2 g
my $res = g('mojolicio.us');
my $res = g('http://mojolicio.us' => {DNT => 1} => 'Hi!');
my $res = g('example.com');
my $res = g('http://example.com' => {DNT => 1} => 'Hi!');
Perform C<GET> request with L<Mojo::UserAgent/"get"> and return resulting
L<Mojo::Message::Response> object.
Expand All @@ -120,8 +120,8 @@ L<Mojo::Message::Response> object.
=head2 h
my $res = h('mojolicio.us');
my $res = h('http://mojolicio.us' => {DNT => 1} => 'Hi!');
my $res = h('example.com');
my $res = h('http://example.com' => {DNT => 1} => 'Hi!');
Perform C<HEAD> request with L<Mojo::UserAgent/"head"> and return resulting
L<Mojo::Message::Response> object.
Expand All @@ -138,16 +138,16 @@ Encode Perl data structure or decode JSON with L<Mojo::JSON>.
=head2 o
my $res = o('mojolicio.us');
my $res = o('http://mojolicio.us' => {DNT => 1} => 'Hi!');
my $res = o('example.com');
my $res = o('http://example.com' => {DNT => 1} => 'Hi!');
Perform C<OPTIONS> request with L<Mojo::UserAgent/"options"> and return
resulting L<Mojo::Message::Response> object.
=head2 p
my $res = p('mojolicio.us');
my $res = p('http://mojolicio.us' => {DNT => 1} => 'Hi!');
my $res = p('example.com');
my $res = p('http://example.com' => {DNT => 1} => 'Hi!');
Perform C<POST> request with L<Mojo::UserAgent/"post"> and return resulting
L<Mojo::Message::Response> object.
Expand All @@ -158,20 +158,20 @@ L<Mojo::Message::Response> object.
Dump a Perl data structure with L<Data::Dumper>.
perl -Mojo -E 'say r(g("mojolicio.us")->headers->to_hash)'
perl -Mojo -E 'say r(g("example.com")->headers->to_hash)'
=head2 t
my $res = t('mojolicio.us');
my $res = t('http://mojolicio.us' => {DNT => 1} => 'Hi!');
my $res = t('example.com');
my $res = t('http://example.com' => {DNT => 1} => 'Hi!');
Perform C<PATCH> request with L<Mojo::UserAgent/"patch"> and return resulting
L<Mojo::Message::Response> object.
=head2 u
my $res = u('mojolicio.us');
my $res = u('http://mojolicio.us' => {DNT => 1} => 'Hi!');
my $res = u('example.com');
my $res = u('http://example.com' => {DNT => 1} => 'Hi!');
Perform C<PUT> request with L<Mojo::UserAgent/"put"> and return resulting
L<Mojo::Message::Response> object.
Expand Down

0 comments on commit 3a7aa40

Please sign in to comment.