Skip to content

Commit

Permalink
do not use $self for event examples
Browse files Browse the repository at this point in the history
  • Loading branch information
kraih committed Oct 17, 2011
1 parent 7321e4c commit 93ba1b1
Show file tree
Hide file tree
Showing 14 changed files with 37 additions and 34 deletions.
3 changes: 3 additions & 0 deletions Changes
@@ -1,5 +1,8 @@
This file documents the revision history for Perl extension Mojolicious.

2.01 2011-10-18 00:00:00
- Improved documentation.

2.0 2011-10-17 00:00:00
- Code name "Leaf Fluttering In Wind", this is a major release.
- Increased Perl version requirement to 5.10.1.
Expand Down
2 changes: 1 addition & 1 deletion lib/Mojo/EventEmitter.pm
Expand Up @@ -112,7 +112,7 @@ Mojo::EventEmitter - Event emitter base class
# Subscribe to events
my $tiger = Cat->new;
$tiger->on(roar => sub {
my ($self, $times) = @_;
my ($tiger, $times) = @_;
say 'RAWR!' for 1 .. $times;
});
$tiger->poke;
Expand Down
14 changes: 7 additions & 7 deletions lib/Mojo/IOLoop.pm
Expand Up @@ -428,13 +428,13 @@ Mojo::IOLoop - Minimalistic reactor for non-blocking TCP clients and servers
Mojo::IOLoop->listen(
port => 3000,
on_read => sub {
my ($self, $id, $chunk) = @_;
my ($loop, $id, $chunk) = @_;
# Process input
say $chunk;
# Got some data, time to write
$self->write($id, 'HTTP/1.1 200 OK');
$loop->write($id, 'HTTP/1.1 200 OK');
}
);
Expand All @@ -444,13 +444,13 @@ Mojo::IOLoop - Minimalistic reactor for non-blocking TCP clients and servers
port => 3000,
tls => 1,
on_connect => sub {
my ($self, $id) = @_;
my ($loop, $id) = @_;
# Write request
$self->write($id, "GET / HTTP/1.1\r\n\r\n");
$loop->write($id, "GET / HTTP/1.1\r\n\r\n");
},
on_read => sub {
my ($self, $id, $chunk) = @_;
my ($loop, $id, $chunk) = @_;
# Process input
say $chunk;
Expand All @@ -459,8 +459,8 @@ Mojo::IOLoop - Minimalistic reactor for non-blocking TCP clients and servers
# Add a timer
Mojo::IOLoop->timer(5 => sub {
my $self = shift;
$self->drop($id);
my $loop = shift;
$loop->drop($id);
});
# Start and stop loop
Expand Down
4 changes: 2 additions & 2 deletions lib/Mojo/IOLoop/Client.pm
Expand Up @@ -167,11 +167,11 @@ Mojo::IOLoop::Client - IOLoop socket client
# Create socket connection
my $client = Mojo::IOLoop::Client->new;
$client->on(connect => sub {
my ($self, $handle) = @_;
my ($client, $handle) = @_;
...
});
$client->on(error => sub {
my ($self, $error) = @_;
my ($client, $error) = @_;
...
});
$client->connect(address => 'mojolicio.us', port => 80);
Expand Down
4 changes: 2 additions & 2 deletions lib/Mojo/IOLoop/Resolver.pm
Expand Up @@ -361,13 +361,13 @@ Mojo::IOLoop::Resolver - IOLoop DNS stub resolver
# Lookup address
my $resolver = Mojo::IOLoop::Resolver->new;
$resolver->lookup('mojolicio.us' => sub {
my ($self, $address) = @_;
my ($resolver, $address) = @_;
...
});
# Resolve "MX" records
$resolver->resolve('mojolicio.us', 'MX', sub {
my ($self, $records) = @_;
my ($resolver, $records) = @_;
...
});
Expand Down
2 changes: 1 addition & 1 deletion lib/Mojo/IOLoop/Server.pm
Expand Up @@ -268,7 +268,7 @@ Mojo::IOLoop::Server - IOLoop socket server
# Create listen socket
my $server = Mojo::IOLoop::Server->new;
$server->on(accept => sub {
my ($self, $handle) = @_;
my ($server, $handle) = @_;
...
});
$server->listen(port => 3000);
Expand Down
6 changes: 3 additions & 3 deletions lib/Mojo/IOLoop/Stream.pm
Expand Up @@ -149,15 +149,15 @@ Mojo::IOLoop::Stream - IOLoop stream
# Create stream
my $stream = Mojo::IOLoop::Stream->new($handle);
$stream->on(read => sub {
my ($self, $chunk) = @_;
my ($stream, $chunk) = @_;
...
});
$stream->on(close => sub {
my $self = shift;
my $stream = shift;
...
});
$stream->on(error => sub {
my ($self, $error) = @_;
my ($stream, $error) = @_;
...
});
Expand Down
2 changes: 1 addition & 1 deletion lib/Mojo/Server/CGI.pm
Expand Up @@ -111,7 +111,7 @@ Mojo::Server::CGI - CGI server
my $cgi = Mojo::Server::CGI->new;
$cgi->unsubscribe_all('request')
$cgi->on(request => sub {
my ($self, $tx) = @_;
my ($cgi, $tx) = @_;
# Request
my $method = $tx->req->method;
Expand Down
2 changes: 1 addition & 1 deletion lib/Mojo/Server/Daemon.pm
Expand Up @@ -338,7 +338,7 @@ Mojo::Server::Daemon - Non-blocking I/O HTTP 1.1 and WebSocket server
my $daemon = Mojo::Server::Daemon->new(listen => ['http://*:8080']);
$daemon->unsubscribe_all('request');
$daemon->on(request => sub {
my ($self, $tx) = @_;
my ($daemon, $tx) = @_;
# Request
my $method = $tx->req->method;
Expand Down
2 changes: 1 addition & 1 deletion lib/Mojo/Server/PSGI.pm
Expand Up @@ -91,7 +91,7 @@ Mojo::Server::PSGI - PSGI server
my $psgi = Mojo::Server::PSGI->new;
$psgi->unsubscribe_all('request');
$psgi->on(request => sub {
my ($self, $tx) = @_;
my ($psgi, $tx) = @_;
# Request
my $method = $tx->req->method;
Expand Down
20 changes: 10 additions & 10 deletions lib/Mojo/UserAgent.pm
Expand Up @@ -604,7 +604,7 @@ Mojo::UserAgent - Non-blocking I/O HTTP 1.1 and WebSocket user agent
for my $url ('mojolicio.us', 'cpan.org') {
$t->begin;
$ua->get($url => sub {
my ($self, $tx) = @_;
my ($ua, $tx) = @_;
$t->end($tx->res->dom->at('title')->text);
});
}
Expand All @@ -615,7 +615,7 @@ Mojo::UserAgent - Non-blocking I/O HTTP 1.1 and WebSocket user agent
# WebSocket request
$ua->websocket('ws://websockets.org:8787' => sub {
my ($self, $tx) = @_;
my ($ua, $tx) = @_;
$tx->on(finish => sub { Mojo::IOLoop->stop });
$tx->on(message => sub {
my ($tx, $message) = @_;
Expand Down Expand Up @@ -812,7 +812,7 @@ L<Mojo::UserAgent::Transactor/"tx"> (except for the method).
You can also append a callback to perform requests non-blocking.
$ua->delete('http://kraih.com' => sub {
my ($self, $tx) = @_;
my ($ua, $tx) = @_;
say $tx->res->body;
Mojo::IOLoop->stop;
});
Expand All @@ -835,7 +835,7 @@ L<Mojo::UserAgent::Transactor/"tx"> (except for the method).
You can also append a callback to perform requests non-blocking.
$ua->get('http://kraih.com' => sub {
my ($self, $tx) = @_;
my ($ua, $tx) = @_;
say $tx->res->body;
Mojo::IOLoop->stop;
});
Expand All @@ -851,7 +851,7 @@ L<Mojo::UserAgent::Transactor/"tx"> (except for the method).
You can also append a callback to perform requests non-blocking.
$ua->head('http://kraih.com' => sub {
my ($self, $tx) = @_;
my ($ua, $tx) = @_;
say $tx->res->body;
Mojo::IOLoop->stop;
});
Expand All @@ -874,7 +874,7 @@ L<Mojo::UserAgent::Transactor/"tx"> (except for the method).
You can also append a callback to perform requests non-blocking.
$ua->post('http://kraih.com' => sub {
my ($self, $tx) = @_;
my ($ua, $tx) = @_;
say $tx->res->body;
Mojo::IOLoop->stop;
});
Expand All @@ -890,7 +890,7 @@ L<Mojo::UserAgent::Transactor/"form">.
You can also append a callback to perform requests non-blocking.
$ua->post_form('http://kraih.com' => {q => 'test'} => sub {
my ($self, $tx) = @_;
my ($ua, $tx) = @_;
say $tx->res->body;
Mojo::IOLoop->stop;
});
Expand All @@ -906,7 +906,7 @@ L<Mojo::UserAgent::Transactor/"tx"> (except for the method).
You can also append a callback to perform requests non-blocking.
$ua->put('http://kraih.com' => sub {
my ($self, $tx) = @_;
my ($ua, $tx) = @_;
say $tx->res->body;
Mojo::IOLoop->stop;
});
Expand All @@ -920,7 +920,7 @@ Process blocking transaction.
You can also append a callback to perform transactions non-blocking.
$ua->start($tx => sub {
my ($self, $tx) = @_;
my ($ua, $tx) = @_;
say $tx->res->body;
Mojo::IOLoop->stop;
});
Expand All @@ -945,7 +945,7 @@ the exact same arguments as L<Mojo::UserAgent::Transactor/"websocket">.
Note that this method is EXPERIMENTAL and might change without warning!
$ua->websocket('ws://localhost:3000/echo' => sub {
my ($self, $tx) = @_;
my ($ua, $tx) = @_;
$tx->on(finish => sub { Mojo::IOLoop->stop });
$tx->on(message => sub {
my ($tx, $message) = @_;
Expand Down
2 changes: 1 addition & 1 deletion lib/Mojolicious.pm
Expand Up @@ -35,7 +35,7 @@ has static => sub { Mojolicious::Static->new };
has types => sub { Mojolicious::Types->new };

our $CODENAME = 'Leaf Fluttering In Wind';
our $VERSION = '2.0';
our $VERSION = '2.01';

# "These old doomsday devices are dangerously unstable.
# I'll rest easier not knowing where they are."
Expand Down
4 changes: 2 additions & 2 deletions lib/Mojolicious/Controller.pm
Expand Up @@ -1000,7 +1000,7 @@ A L<Mojo::UserAgent> prepared for the current environment.
# Non-blocking
$c->ua->get('http://mojolicio.us' => sub {
my ($self, $tx) = @_;
my ($ua, $tx) = @_;
$c->render_data($tx->res->body);
});
Expand All @@ -1012,7 +1012,7 @@ A L<Mojo::UserAgent> prepared for the current environment.
for my $url ('http://mojolicio.us', 'https://metacpan.org') {
$t->begin;
$c->ua->get($url => sub {
my ($self, $tx) = @_;
my ($ua, $tx) = @_;
$t->end($tx->res->dom->html->head->title->text);
});
}
Expand Down
4 changes: 2 additions & 2 deletions lib/Mojolicious/Guides/Cookbook.pod
Expand Up @@ -297,7 +297,7 @@ been initialized and before a connection gets associated with them.

# Add a witty header to every request
$ua->on(start => sub {
my ($self, $tx) = @_;
my ($ua, $tx) = @_;
$tx->req->headers->header('X-Bender' => 'Bite my shiny metal ass!');
say 'Request: ', $tx->req->url->clone->to_abs;
});
Expand Down Expand Up @@ -403,7 +403,7 @@ time.

# Fetch non-blocking just by adding a callback
$ua->get($url => sub {
my ($self, $tx) = @_;
my ($ua, $tx) = @_;

# Extract URLs
say "[$id] $url";
Expand Down

0 comments on commit 93ba1b1

Please sign in to comment.