Skip to content

Commit

Permalink
share stash implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
kraih committed Feb 22, 2014
1 parent 8cf8077 commit 78637fd
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 39 deletions.
17 changes: 2 additions & 15 deletions lib/Mojo/IOLoop/Delay.pm
@@ -1,6 +1,7 @@
package Mojo::IOLoop::Delay;
use Mojo::Base 'Mojo::EventEmitter';

use Mojo;
use Mojo::IOLoop;

has ioloop => sub { Mojo::IOLoop->singleton };
Expand All @@ -13,21 +14,7 @@ sub begin {
return sub { $ignore // 1 and shift; $self->_step($id, @_) };
}

sub data {
my $self = shift;

# Hash
my $data = $self->{data} ||= {};
return $data unless @_;

# Get
return $data->{$_[0]} unless @_ > 1 || ref $_[0];

# Set
%$data = (%$data, %{ref $_[0] ? $_[0] : {@_}});

return $self;
}
sub data { shift->Mojo::_dict(data => @_) }

sub steps {
my $self = shift->remaining([@_]);
Expand Down
21 changes: 1 addition & 20 deletions lib/Mojolicious/Controller.pm
Expand Up @@ -307,26 +307,7 @@ sub signed_cookie {
return wantarray ? @results : $results[0];
}

sub stash {
my $self = shift;

# Hash
my $stash = $self->{stash} ||= {};
return $stash unless @_;

# Get
return $stash->{$_[0]} unless @_ > 1 || ref $_[0];

# Set
my $values = ref $_[0] ? $_[0] : {@_};
for my $key (keys %$values) {
$self->app->log->debug(qq{Careful, "$key" is a reserved stash value.})
if $RESERVED{$key};
$stash->{$key} = $values->{$key};
}

return $self;
}
sub stash { shift->Mojolicious::_dict(stash => @_) }

sub url_for {
my $self = shift;
Expand Down
4 changes: 0 additions & 4 deletions t/mojolicious/app.t
Expand Up @@ -271,13 +271,9 @@ $t->get_ok('/foo/test' => {'X-Test' => 'Hi there!'})->status_is(200)
->header_is(Server => 'Mojolicious (Perl)')->content_like(qr!/bar/test!);

# Foo::index
$log = '';
$cb = $t->app->log->on(message => sub { $log .= pop });
$t->get_ok('/foo' => {'X-Test' => 'Hi there!'})->status_is(200)
->header_is(Server => 'Mojolicious (Perl)')
->content_like(qr|<body>\s+23\nHello Mojo from the template /foo! He|);
like $log, qr/Careful, "handler" is a reserved stash value\./, 'right message';
$t->app->log->unsubscribe(message => $cb);

# Foo::Bar::index
$t->get_ok('/foo-bar' => {'X-Test' => 'Hi there!'})->status_is(200)
Expand Down

0 comments on commit 78637fd

Please sign in to comment.