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