Skip to content

Commit

Permalink
added a few examples for important events
Browse files Browse the repository at this point in the history
  • Loading branch information
kraih committed Oct 19, 2011
1 parent 77adeb4 commit 6d5bedb
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
10 changes: 10 additions & 0 deletions lib/Mojo/Content.pm
Expand Up @@ -447,6 +447,11 @@ L<Mojo::Content> can emit the following events.
Emitted once all headers have been parsed and the body starts.
Note that this event is EXPERIMENTAL and might change without warning!
$content->on(body => sub {
my $content = shift;
$content->auto_upgrade(0) if $content->headers->header('X-No-MultiPart');
});
=head2 C<read>
$content->on(read => sub {
Expand All @@ -456,6 +461,11 @@ Note that this event is EXPERIMENTAL and might change without warning!
Emitted when a new chunk of content arrives, also disables normal content
storage in asset objects.
$content->on(read => sub {
my ($content, $chunk) = @_;
say "STREAMING: $chunk";
});
=head1 ATTRIBUTES
L<Mojo::Content> implements the following attributes.
Expand Down
6 changes: 6 additions & 0 deletions lib/Mojo/Message.pm
Expand Up @@ -568,6 +568,12 @@ L<Mojo::Message> can emit the following events.
Emitted after message building or parsing is finished.
my $before = time;
$message->on(finish => sub {
my $message = shift;
$message->headers->header('X-Parser-Time' => time - $before);
});
=head2 C<progress>
$message->on(progress => sub {
Expand Down
2 changes: 1 addition & 1 deletion lib/Mojo/Server.pm
Expand Up @@ -161,7 +161,7 @@ Start server.
=head2 C<upgrade_tx>
my $ws = $server->upgrade_tx(tx);
my $upgraded = $server->upgrade_tx(tx);
Let application upgrade transaction.
Expand Down

0 comments on commit 6d5bedb

Please sign in to comment.