Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
improved Mojo::IOLoop::Delay with circular reference protection
  • Loading branch information
kraih committed Apr 26, 2014
1 parent fedce7c commit 0caa913
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 18 deletions.
1 change: 1 addition & 0 deletions Changes
@@ -1,5 +1,6 @@

4.95 2014-04-26
- Imprived Mojo::IOLoop::Delay with circular reference protection.
- Improved Mojo::IOLoop::Delay to allow argument splicing.
- Improved Mojo::IOLoop::Server to reuse cipher list from IO::Socket::SSL.

Expand Down
3 changes: 3 additions & 0 deletions lib/Mojo/Base.pm
Expand Up @@ -11,6 +11,9 @@ use Carp ();
# Only Perl 5.14+ requires it on demand
use IO::Handle ();

# Protect subclasses using AUTOLOAD
sub DESTROY { }

sub import {
my $class = shift;
return unless my $flag = shift;
Expand Down
27 changes: 17 additions & 10 deletions lib/Mojo/IOLoop/Delay.pm
Expand Up @@ -3,9 +3,13 @@ use Mojo::Base 'Mojo::EventEmitter';

use Mojo;
use Mojo::IOLoop;
use Scalar::Util 'refaddr';

has ioloop => sub { Mojo::IOLoop->singleton };
has remaining => sub { [] };
has ioloop => sub { Mojo::IOLoop->singleton };

my %REMAINING;

sub DESTROY { delete $REMAINING{refaddr shift} }

sub begin {
my ($self, $offset, $len) = @_;
Expand All @@ -18,8 +22,11 @@ sub data { shift->Mojo::_dict(data => @_) }

sub pass { $_[0]->begin->(@_) }

sub remaining { $REMAINING{refaddr shift} //= [] }

sub steps {
my $self = shift->remaining([@_]);
my $self = shift;
@{$self->remaining} = @_;
$self->ioloop->next_tick($self->begin);
return $self;
}
Expand Down Expand Up @@ -151,13 +158,6 @@ L<Mojo::IOLoop::Delay> implements the following attributes.
Event loop object to control, defaults to the global L<Mojo::IOLoop>
singleton.
=head2 remaining
my $remaining = $delay->remaining;
$delay = $delay->remaining([sub {...}]);
Remaining L</"steps"> in chain.
=head1 METHODS
L<Mojo::IOLoop::Delay> inherits all methods from L<Mojo::EventEmitter> and
Expand Down Expand Up @@ -213,6 +213,13 @@ values to the next step.
# Longer version
$delay->begin(0)->(@args);
=head2 remaining
my $remaining = $delay->remaining;
Remaining L</"steps"> in chain, stored outside the object to protect from
circular references.
=head2 steps
$delay = $delay->steps(sub {...}, sub {...});
Expand Down
2 changes: 0 additions & 2 deletions lib/Mojolicious.pm
Expand Up @@ -58,8 +58,6 @@ sub AUTOLOAD {
return $self->build_controller->$helper(@_);
}

sub DESTROY { }

sub build_controller {
my ($self, $tx) = @_;
$tx ||= $self->build_tx;
Expand Down
2 changes: 0 additions & 2 deletions lib/Mojolicious/Controller.pm
Expand Up @@ -37,8 +37,6 @@ sub AUTOLOAD {
return $self->$helper(@_);
}

sub DESTROY { }

sub continue { $_[0]->app->routes->continue($_[0]) }

sub cookie {
Expand Down
2 changes: 0 additions & 2 deletions lib/Mojolicious/Routes/Route.pm
Expand Up @@ -22,8 +22,6 @@ sub AUTOLOAD {
return $self->$shortcut(@_);
}

sub DESTROY { }

sub add_child {
my ($self, $route) = @_;
weaken $route->remove->parent($self)->{parent};
Expand Down
2 changes: 0 additions & 2 deletions lib/Mojolicious/Validator/Validation.pm
Expand Up @@ -19,8 +19,6 @@ sub AUTOLOAD {
return $self->check($method => @_);
}

sub DESTROY { }

sub check {
my ($self, $check) = (shift, shift);

Expand Down

0 comments on commit 0caa913

Please sign in to comment.