line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package RPC::Switch::Client::Steps; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
7
|
use Mojo::Base -base; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
7
|
|
4
|
1
|
|
|
1
|
|
165
|
use Mojo::IOLoop; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
9
|
|
5
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
49
|
use Carp qw(croak); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
532
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
has ioloop => sub { Mojo::IOLoop->singleton }; |
9
|
|
|
|
|
|
|
has _remaining => sub { [] }; |
10
|
|
|
|
|
|
|
has _errcb => sub { sub { say STDERR "caught >>> $_[0] <<<" } }; |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub steps { |
13
|
0
|
|
|
0
|
0
|
|
my ($self, $cbs, $errcb, @args) = @_; |
14
|
0
|
0
|
|
|
|
|
croak "no callbacks" unless ref $cbs eq 'ARRAY'; |
15
|
|
|
|
|
|
|
# todo: check that array elements are coderefs? |
16
|
0
|
|
|
|
|
|
$self->_remaining($cbs); |
17
|
0
|
0
|
|
|
|
|
$self->_errcb($errcb) if ref $errcb eq 'CODE'; |
18
|
|
|
|
|
|
|
|
19
|
0
|
|
|
0
|
|
|
$self->ioloop->next_tick(sub { $self->_next(@args) }); |
|
0
|
|
|
|
|
|
|
20
|
0
|
|
|
|
|
|
return $self; |
21
|
|
|
|
|
|
|
} |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
sub next { |
24
|
0
|
|
|
0
|
0
|
|
my ($self) = @_; |
25
|
0
|
|
|
0
|
|
|
return sub { $self->_next(@_) }; |
|
0
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
} |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
sub _next { |
29
|
0
|
|
|
0
|
|
|
my $self = shift; |
30
|
0
|
0
|
|
|
|
|
my $cb = shift @{$self->_remaining} |
|
0
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
or return; |
32
|
0
|
0
|
|
|
|
|
unless (eval { $cb->($self, @_); 1 }) { |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
33
|
0
|
|
|
|
|
|
my $e = $@; |
34
|
0
|
|
|
|
|
|
eval { $self->_errcb->($e) }; |
|
0
|
|
|
|
|
|
|
35
|
0
|
0
|
|
|
|
|
warn $@ if $@; |
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
#sub DESTROY { |
40
|
|
|
|
|
|
|
# say STDERR "destroying $_[0]"; |
41
|
|
|
|
|
|
|
#} |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
1; |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
=encoding utf8 |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
=head1 NAME |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
RPC::Switch::Client::Steps - simplistic chained callbacks |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
=cut |
53
|
|
|
|
|
|
|
|