Skip to content

Commit

Permalink
deprecate Mojo::IOLoop::Delay::data
Browse files Browse the repository at this point in the history
  • Loading branch information
kraih committed Oct 28, 2017
1 parent 358b96b commit c13de4f
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 39 deletions.
3 changes: 2 additions & 1 deletion Changes
@@ -1,5 +1,6 @@

7.49 2017-10-25
7.49 2017-10-28
- Deprecated Mojo::IOLoop::Delay::data.
- Added Promises/A+ support. Note that Mojo::IOLoop::Delay previously
inherited a catch method from Mojo::EventEmitter that was passed the error
message as second argument instead of the first, so you might have to change
Expand Down
23 changes: 6 additions & 17 deletions lib/Mojo/IOLoop/Delay.pm
Expand Up @@ -2,7 +2,7 @@ package Mojo::IOLoop::Delay;
use Mojo::Base 'Mojo::EventEmitter';

use Mojo::IOLoop;
use Mojo::Util;
use Mojo::Util qw(deprecated);
use Scalar::Util qw(blessed weaken);

has ioloop => sub { Mojo::IOLoop->singleton };
Expand Down Expand Up @@ -37,7 +37,11 @@ sub begin {

sub catch { shift->then(undef, shift) }

sub data { Mojo::Util::_stash(data => @_) }
# DEPRECATED!
sub data {
deprecated 'Mojo::IOLoop::Delay::data is DEPRECATED';
Mojo::Util::_stash(data => @_);
}

sub finally {
my ($self, $finally) = @_;
Expand Down Expand Up @@ -424,21 +428,6 @@ fulfilled.
return "This is bad: $reason[0]";
});
=head2 data
my $hash = $delay->data;
my $foo = $delay->data('foo');
$delay = $delay->data({foo => 'bar', baz => 23});
$delay = $delay->data(foo => 'bar', baz => 23);
Data shared between all L</"steps">.
# Remove value
my $foo = delete $delay->data->{foo};
# Assign multiple values at once
$delay->data(foo => 'test', bar => 23);
=head2 finally
my $new = $delay->finally(sub {...});
Expand Down
30 changes: 10 additions & 20 deletions t/mojo/delay.t
Expand Up @@ -210,17 +210,6 @@ my @numbers;
$delay->steps(sub { (undef, @numbers) = @_ })->wait;
is_deeply \@numbers, [2, 3, 5, 7, 11, 14, 15, 19, 20], 'right values';

# Data
is $delay->data('foo'), undef, 'no value';
is_deeply $delay->data(foo => 'bar')->data, {foo => 'bar'}, 'right value';
is $delay->data('foo'), 'bar', 'right value';
delete $delay->data->{foo};
is $delay->data('foo'), undef, 'no value';
$delay->data(foo => 'bar', baz => 'yada');
is $delay->data({test => 23})->data->{test}, 23, 'right value';
is_deeply $delay->data, {foo => 'bar', baz => 'yada', test => 23},
'right value';

# Steps
my ($finished, $result);
$delay = Mojo::IOLoop::Delay->new;
Expand All @@ -235,8 +224,7 @@ $delay->steps(
sub {
my ($delay, @numbers) = @_;
my $end = $delay->begin;
Mojo::IOLoop->next_tick(
sub { $end->(undef, @numbers, 4)->data(foo => 'bar') });
Mojo::IOLoop->next_tick(sub { $end->(undef, @numbers, 4) });
},
sub {
my ($delay, @numbers) = @_;
Expand All @@ -245,7 +233,6 @@ $delay->steps(
)->wait;
is $finished, 1, 'finish event has been emitted once';
is_deeply $result, [2, 3, 2, 1, 4, 5], 'right results';
is $delay->data('foo'), 'bar', 'right value';

# One step
$result = undef;
Expand Down Expand Up @@ -370,11 +357,11 @@ my $double = sub {
Mojo::IOLoop->next_tick(sub { $end->($num * 2) });
};
$result = undef;
$delay = Mojo::IOLoop::Delay->new->data(num => 9)->steps(
$delay = Mojo::IOLoop::Delay->new->steps(
sub {
my $delay = shift;
my $end = $delay->begin(0);
Mojo::IOLoop->next_tick(sub { $end->($delay->data('num')) });
Mojo::IOLoop->next_tick(sub { $end->(9) });
unshift @{$delay->remaining}, $double;
},
sub {
Expand All @@ -385,7 +372,6 @@ $delay = Mojo::IOLoop::Delay->new->data(num => 9)->steps(
is scalar @{$delay->remaining}, 2, 'two steps remaining';
$delay->wait;
is scalar @{$delay->remaining}, 0, 'no steps remaining';
is $delay->data('num'), 9, 'right value';
is $result, 18, 'right result';

# Exception in first step
Expand Down Expand Up @@ -418,7 +404,12 @@ $delay->on(finish => sub { $finished++ });
$delay->steps(
sub {
my $end = shift->begin;
Mojo::IOLoop->next_tick(sub { $end->()->data(foo => 'bar') });
Mojo::IOLoop->next_tick(
sub {
$result = 'pass';
$end->();
}
);
},
sub { die 'Second step!' },
sub { $result = 'failed' }
Expand All @@ -428,8 +419,7 @@ $delay->wait;
is_deeply $delay->remaining, [], 'no remaining steps';
like $failed, qr/^Second step!/, 'right error';
ok !$finished, 'finish event has not been emitted';
ok !$result, 'no result';
is $delay->data('foo'), 'bar', 'right value';
is $result, 'pass', 'right result';

# Exception in second step (with active event)
($failed, $finished, $result) = ();
Expand Down
2 changes: 1 addition & 1 deletion t/pod_coverage.t
Expand Up @@ -8,4 +8,4 @@ plan skip_all => 'Test::Pod::Coverage 1.04+ required for this test!'
unless eval 'use Test::Pod::Coverage 1.04; 1';

# DEPRECATED!
all_pod_coverage_ok({also_private => ['watch']});
all_pod_coverage_ok({also_private => ['data']});

0 comments on commit c13de4f

Please sign in to comment.