Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
better callback examples
  • Loading branch information
kraih committed Dec 18, 2011
1 parent 5a7b9ae commit d5aa46c
Show file tree
Hide file tree
Showing 17 changed files with 32 additions and 2 deletions.
2 changes: 2 additions & 0 deletions lib/Mojo/Content.pm
Expand Up @@ -429,6 +429,7 @@ L<Mojo::Content> can emit the following events.
$content->on(body => sub {
my $content = shift;
...
});
Emitted once all headers have been parsed and the body starts. Note that this
Expand All @@ -443,6 +444,7 @@ event is EXPERIMENTAL and might change without warning!
$content->on(read => sub {
my ($content, $chunk) = @_;
...
});
Emitted when a new chunk of content arrives.
Expand Down
1 change: 1 addition & 0 deletions lib/Mojo/Content/MultiPart.pm
Expand Up @@ -253,6 +253,7 @@ emit the following new ones.
$multi->on(part => sub {
my ($multi, $single) = @_;
...
});
Emitted when a new L<Mojo::Content::Single> part starts. Note that this event
Expand Down
1 change: 1 addition & 0 deletions lib/Mojo/Content/Single.pm
Expand Up @@ -91,6 +91,7 @@ emit the following new ones.
$single->on(upgrade => sub {
my ($single, $multi) = @_;
...
});
Emitted when content gets upgraded to a L<Mojo::Content::MultiPart> object.
Expand Down
2 changes: 2 additions & 0 deletions lib/Mojo/EventEmitter.pm
Expand Up @@ -149,6 +149,7 @@ Subscribe to event.
$e->on(foo => sub {
my ($e, @args) = @_;
...
});
=head2 C<once>
Expand All @@ -159,6 +160,7 @@ Subscribe to event and unsubscribe again after it has been emitted once.
$e->once(foo => sub {
my ($e, @args) = @_;
...
});
=head2 C<subscribers>
Expand Down
5 changes: 3 additions & 2 deletions lib/Mojo/IOLoop.pm
Expand Up @@ -476,7 +476,6 @@ Mojo::IOLoop - Minimalistic reactor for non-blocking TCP clients and servers
# Got some data, time to write
$stream->write('HTTP/1.1 200 OK');
});
});
# Connect to port 3000
Expand All @@ -487,7 +486,7 @@ Mojo::IOLoop - Minimalistic reactor for non-blocking TCP clients and servers
my ($stream, $chunk) = @_;
# Process input
say $chunk;
say "Input: $chunk";
});
# Write request
Expand Down Expand Up @@ -623,6 +622,7 @@ might change without warning!
Mojo::IOLoop->client({port => 3000} => sub {
my ($loop, $err, $stream) = @_;
...
});
=head2 C<defer>
Expand Down Expand Up @@ -714,6 +714,7 @@ might change without warning!
Mojo::IOLoop->server({port => 3000} => sub {
my ($loop, $stream, $id) = @_;
...
});
=head2 C<singleton>
Expand Down
2 changes: 2 additions & 0 deletions lib/Mojo/IOLoop/Client.pm
Expand Up @@ -177,6 +177,7 @@ L<Mojo::IOLoop::Client> can emit the following events.
$client->on(connect => sub {
my ($client, $handle) = @_;
...
});
Emitted safely once the connection is established.
Expand All @@ -185,6 +186,7 @@ Emitted safely once the connection is established.
$client->on(error => sub {
my ($client, $err) = @_;
...
});
Emitted safely if an error happens on the connection.
Expand Down
1 change: 1 addition & 0 deletions lib/Mojo/IOLoop/Delay.pm
Expand Up @@ -65,6 +65,7 @@ L<Mojo::IOLoop::Delay> can emit the following events.
$delay->on(finish => sub {
my $delay = shift;
...
});
Emitted safely once the active event counter reaches zero.
Expand Down
1 change: 1 addition & 0 deletions lib/Mojo/IOLoop/Server.pm
Expand Up @@ -294,6 +294,7 @@ L<Mojo::IOLoop::Server> can emit the following events.
$server->on(accept => sub {
my ($server, $handle) = @_;
...
});
Emitted safely for each accepted connection.
Expand Down
6 changes: 6 additions & 0 deletions lib/Mojo/IOLoop/Stream.pm
Expand Up @@ -209,6 +209,7 @@ L<Mojo::IOLoop::Stream> can emit the following events.
$stream->on(close => sub {
my $stream = shift;
...
});
Emitted safely if the stream gets closed.
Expand All @@ -217,6 +218,7 @@ Emitted safely if the stream gets closed.
$stream->on(drain => sub {
my $stream = shift;
...
});
Emitted safely once all data has been written.
Expand All @@ -225,6 +227,7 @@ Emitted safely once all data has been written.
$stream->on(error => sub {
my ($stream, $err) = @_;
...
});
Emitted safely if an error happens on the stream.
Expand All @@ -233,6 +236,7 @@ Emitted safely if an error happens on the stream.
$stream->on(read => sub {
my ($stream, $chunk) = @_;
...
});
Emitted safely if new data arrives on the stream.
Expand All @@ -241,6 +245,7 @@ Emitted safely if new data arrives on the stream.
$stream->on(timeout => sub {
my $stream = shift;
...
});
Emitted safely if the stream has been inactive for too long and will get
Expand All @@ -251,6 +256,7 @@ without warning!
$stream->on(write => sub {
my ($stream, $chunk) = @_;
...
});
Emitted safely if new data has been written to the stream.
Expand Down
1 change: 1 addition & 0 deletions lib/Mojo/IOWatcher.pm
Expand Up @@ -172,6 +172,7 @@ L<Mojo::IOWatcher> can emit the following events.
$watcher->on(error => sub {
my ($watcher, $err) = @_;
...
});
Emitted safely if an error happens.
Expand Down
1 change: 1 addition & 0 deletions lib/Mojo/Log.pm
Expand Up @@ -121,6 +121,7 @@ L<Mojo::Log> can emit the following events.
$log->on(message => sub {
my ($log, $level, @messages) = @_;
...
});
Emitted when a new message gets logged. Note that this event is EXPERIMENTAL
Expand Down
2 changes: 2 additions & 0 deletions lib/Mojo/Message.pm
Expand Up @@ -540,6 +540,7 @@ L<Mojo::Message> can emit the following events.
$message->on(finish => sub {
my $message = shift;
...
});
Emitted after message building or parsing is finished.
Expand All @@ -554,6 +555,7 @@ Emitted after message building or parsing is finished.
$message->on(progress => sub {
my $message = shift;
...
});
Emitted when message building or parsing makes progress.
Expand Down
1 change: 1 addition & 0 deletions lib/Mojo/Server.pm
Expand Up @@ -101,6 +101,7 @@ L<Mojo::Server> can emit the following events.
$server->on(request => sub {
my ($server, $tx) = @_;
...
});
Emitted when a request is ready and needs to be handled.
Expand Down
3 changes: 3 additions & 0 deletions lib/Mojo/Transaction.pm
Expand Up @@ -122,6 +122,7 @@ L<Mojo::Transaction> can emit the following events.
$tx->on(connection => sub {
my ($tx, $connection) = @_;
...
});
Emitted when a connection has been assigned to transaction. Note that this
Expand All @@ -131,6 +132,7 @@ event is EXPERIMENTAL and might change without warning!
$tx->on(finish => sub {
my $tx = shift;
...
});
Emitted when transaction is finished.
Expand All @@ -139,6 +141,7 @@ Emitted when transaction is finished.
$tx->on(resume => sub {
my $tx = shift;
...
});
Emitted when transaction is resumed.
Expand Down
2 changes: 2 additions & 0 deletions lib/Mojo/Transaction/HTTP.pm
Expand Up @@ -299,6 +299,7 @@ can emit the following new ones.
$tx->on(request => sub {
my $tx = shift;
...
});
Emitted when a request is ready and needs to be handled.
Expand All @@ -312,6 +313,7 @@ Emitted when a request is ready and needs to be handled.
$tx->on(upgrade => sub {
my ($tx, $ws) = @_;
...
});
Emitted when transaction gets upgraded to a L<Mojo::Transaction::WebSocket>
Expand Down
2 changes: 2 additions & 0 deletions lib/Mojo/Transaction/WebSocket.pm
Expand Up @@ -356,6 +356,7 @@ and can emit the following new ones.
$ws->on(frame => sub {
my ($ws, $frame) = @_;
...
});
Emitted when a WebSocket frame has been received.
Expand All @@ -371,6 +372,7 @@ Emitted when a WebSocket frame has been received.
$ws->on(message => sub {
my ($ws, $message) = @_;
...
});
Emitted when a complete WebSocket message has been received.
Expand Down
1 change: 1 addition & 0 deletions lib/Mojo/UserAgent.pm
Expand Up @@ -637,6 +637,7 @@ L<Mojo::UserAgent> can emit the following events.
$ua->on(start => sub {
my ($ua, $tx) = @_;
...
});
Emitted whenever a new transaction is about to start, this includes
Expand Down

2 comments on commit d5aa46c

@marcusramberg
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there will be dots!

@memowe
Copy link
Contributor

@memowe memowe commented on d5aa46c Dec 18, 2011

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They look like customers waiting in line to download the latest version from CPAN.

Please sign in to comment.