Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
fixed body method in Mojo::Message
  • Loading branch information
kraih committed Nov 10, 2011
1 parent 12d96b9 commit 3c05aef
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
6 changes: 3 additions & 3 deletions lib/Mojo/Message.pm
Expand Up @@ -52,7 +52,8 @@ sub body {
# Callback
if (ref $new eq 'CODE') {
weaken $self;
return $content->on(read => sub { $self->$new(pop) });
return $content->unsubscribe('read')
->on(read => sub { $self->$new(pop) });
}

# Set text content
Expand Down Expand Up @@ -642,8 +643,7 @@ Check if message is at least a specific version.
$message = $message->body('Hello!');
my $cb = $message->body(sub {...});
Access and replace text content or register C<read> event with C<content>,
which will be emitted when new data arrives.
Access C<content> data or replace all C<read> events.
$message->body(sub {
my ($message, $chunk) = @_;
Expand Down
14 changes: 7 additions & 7 deletions t/mojo/response.t
Expand Up @@ -542,23 +542,23 @@ $res->body('');
is $res->body, '', 'right content';
$res->body('hi there!');
is $res->body, 'hi there!', 'right content';
is scalar @{$res->content->subscribers('read')}, 1, 'one subscriber';
ok $res->content->has_subscribers('read'), 'has subscribers';
$cb = $res->body(sub { });
is scalar @{$res->content->subscribers('read')}, 2, 'two subscribers';
ok $res->content->has_subscribers('read'), 'has subscribers';
$res->content->unsubscribe(read => $cb);
is scalar @{$res->content->subscribers('read')}, 1, 'one subscriber';
ok !$res->content->has_subscribers('read'), 'no subscribers';
$res->body('');
is $res->body, '', 'right content';
$res->body(0);
is $res->body, 0, 'right content';
is scalar @{$res->content->subscribers('read')}, 1, 'one subscriber';
ok !$res->content->has_subscribers('read'), 'no subscribers';
$cb = $res->body(sub { });
is scalar @{$res->content->subscribers('read')}, 2, 'two subscribers';
ok $res->content->has_subscribers('read'), 'has subscribers';
$res->content->unsubscribe(read => $cb);
$res->body('hello!');
is scalar @{$res->content->subscribers('read')}, 1, 'one subscriber';
ok !$res->content->has_subscribers('read'), 'no subscribers';
is $res->body, 'hello!', 'right content';
is scalar @{$res->content->subscribers('read')}, 1, 'one subscriber';
ok !$res->content->has_subscribers('read'), 'no subscribers';
$res->content(Mojo::Content::MultiPart->new);
$res->body('hi!');
is $res->body, 'hi!', 'right content';
Expand Down

0 comments on commit 3c05aef

Please sign in to comment.