Skip to content

Commit

Permalink
do not use $self for callbacks
Browse files Browse the repository at this point in the history
  • Loading branch information
kraih committed Jun 24, 2014
1 parent 6560294 commit cfdae5a
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 11 deletions.
2 changes: 1 addition & 1 deletion Changes
@@ -1,5 +1,5 @@

5.09 2014-06-23
5.09 2014-06-24

5.08 2014-06-17
- Added reset method to Mojo::IOLoop.
Expand Down
2 changes: 1 addition & 1 deletion t/mojo/eventemitter.t
Expand Up @@ -35,7 +35,7 @@ my ($echo, $err);
$e->catch(sub { $err = pop })->on(test2 => sub { $echo .= 'echo: ' . pop });
$e->on(
test2 => sub {
my ($self, $msg) = @_;
my ($e, $msg) = @_;
die "test2: $msg\n";
}
);
Expand Down
2 changes: 1 addition & 1 deletion t/mojolicious/lib/MojoliciousTest.pm
Expand Up @@ -38,7 +38,7 @@ sub startup {
# Templateless renderer
$self->renderer->add_handler(
test => sub {
my ($self, $c, $output) = @_;
my ($renderer, $c, $output) = @_;
$$output = 'Hello Mojo from a templateless renderer!';
}
);
Expand Down
17 changes: 9 additions & 8 deletions t/mojolicious/renderer.t
Expand Up @@ -9,43 +9,44 @@ $c->app->log->level('fatal');
is $c->render_to_string(text => 'works'), 'works', 'renderer is working';

# Normal rendering with default format
my $r = $c->app->renderer->default_format('test');
$r->add_handler(
my $renderer = $c->app->renderer->default_format('test');
$renderer->add_handler(
debug => sub {
my ($self, $c, $output) = @_;
my ($renderer, $c, $output) = @_;
$$output .= 'Hello Mojo!';
}
);
$c->stash->{template} = 'something';
$c->stash->{handler} = 'debug';
is_deeply [$r->render($c)], ['Hello Mojo!', 'test'], 'normal rendering';
is_deeply [$renderer->render($c)], ['Hello Mojo!', 'test'], 'normal rendering';

# Normal rendering with custom format
$c->stash->{format} = 'something';
$c->stash->{template} = 'something';
$c->stash->{handler} = 'debug';
is_deeply [$r->render($c)], ['Hello Mojo!', 'something'], 'normal rendering';
is_deeply [$renderer->render($c)], ['Hello Mojo!', 'something'],
'normal rendering';

# Normal rendering with layout
delete $c->stash->{format};
$c->stash->{template} = 'something';
$c->stash->{layout} = 'something';
$c->stash->{handler} = 'debug';
is_deeply [$r->render($c)], ['Hello Mojo!Hello Mojo!', 'test'],
is_deeply [$renderer->render($c)], ['Hello Mojo!Hello Mojo!', 'test'],
'normal rendering with layout';
is delete $c->stash->{layout}, 'something';

# Rendering a path with dots
$c->stash->{template} = 'some.path.with.dots/template';
$c->stash->{handler} = 'debug';
is_deeply [$r->render($c)], ['Hello Mojo!', 'test'],
is_deeply [$renderer->render($c)], ['Hello Mojo!', 'test'],
'rendering a path with dots';

# Unrecognized handler
my $log = '';
my $cb = $c->app->log->on(message => sub { $log .= pop });
$c->stash->{handler} = 'not_defined';
is $r->render($c), undef, 'return undef for unrecognized handler';
is $renderer->render($c), undef, 'return undef for unrecognized handler';
like $log, qr/No handler for "not_defined" available\./, 'right message';
$c->app->log->unsubscribe(message => $cb);

Expand Down

0 comments on commit cfdae5a

Please sign in to comment.