| 1 | package Async::Hooks::Ctl; | ||||||||||||||||||||||
| 2 | { | ||||||||||||||||||||||
| 3 | 4 | $Async::Hooks::Ctl::VERSION = '0.16'; | |||||||||||||||||||||
| 4 | } | ||||||||||||||||||||||
| 5 | |||||||||||||||||||||||
| 6 | # ABSTRACT: Hook control object | ||||||||||||||||||||||
| 7 | |||||||||||||||||||||||
| 8 | 4 | ▶ | use strict; | ||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||
| 9 | 4 | ▶ | use warnings; | ||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||
| 10 | |||||||||||||||||||||||
| 11 | # $self is a arrayref with three positions: | ||||||||||||||||||||||
| 12 | # . first is a arrayref with hooks to call; | ||||||||||||||||||||||
| 13 | # . second is a arrayref with the arguments of each hook; | ||||||||||||||||||||||
| 14 | # . third is the cleanup sub: always called even when done(). | ||||||||||||||||||||||
| 15 | # | ||||||||||||||||||||||
| 16 | |||||||||||||||||||||||
| 17 | 23 | ▶ | sub new { return bless [undef, $_[1] || [], $_[2] || [], $_[3]], $_[0] } | ||||||||||||||||||||
|
Subroutine
new: called CC=3 SCAR=11.0
Pod
documented
Condition100%4/4
$_[1] || []
$_[2] || []
MC/DC100%1/1
$_[1] || []
$_[1]
MC/DC100%1/1
$_[2] || []
$_[2]
Truth table100%2/2
A
A= $_[1]
Truth table100%2/2
A
A= $_[2]
| |||||||||||||||||||||||
| 18 | |||||||||||||||||||||||
| 19 | 2 | ▶ | sub args { return $_[0][2] } | ||||||||||||||||||||
|
Subroutine
args: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||
| 20 | |||||||||||||||||||||||
| 21 | # stop() or done() stops the chain | ||||||||||||||||||||||
| 22 | 7 | ▶ | sub done { | ||||||||||||||||||||
|
Subroutine
done: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||
| 23 | 7 | my $ctl = $_[0]; | |||||||||||||||||||||
| 24 | |||||||||||||||||||||||
| 25 | 7 | @{$ctl->[1]} = (); | |||||||||||||||||||||
| 26 | |||||||||||||||||||||||
| 27 | 7 | return $ctl->_cleanup(1); | |||||||||||||||||||||
| 28 | } | ||||||||||||||||||||||
| 29 | |||||||||||||||||||||||
| 30 | 4 | *stop = \&done; | |||||||||||||||||||||
| 31 | |||||||||||||||||||||||
| 32 | |||||||||||||||||||||||
| 33 | # decline(), declined() or next() will call the next hook in the chain | ||||||||||||||||||||||
| 34 | 48 | ▶ | sub decline { | ||||||||||||||||||||
|
Subroutine
decline: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||
| 35 | 48 | my $ctl = $_[0]; | |||||||||||||||||||||
| 36 | |||||||||||||||||||||||
| 37 | 48 | my $hook = shift @{$ctl->[1]}; | |||||||||||||||||||||
| 38 | 48 | ▶ | return $hook->($ctl, $ctl->[2]) if $hook; | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 39 | |||||||||||||||||||||||
| 40 | 15 | return $ctl->_cleanup(0); | |||||||||||||||||||||
| 41 | } | ||||||||||||||||||||||
| 42 | |||||||||||||||||||||||
| 43 | 4 | *declined = \&decline; | |||||||||||||||||||||
| 44 | 4 | *next = \&declined; | |||||||||||||||||||||
| 45 | |||||||||||||||||||||||
| 46 | |||||||||||||||||||||||
| 47 | # _cleanup ends the chain processing | ||||||||||||||||||||||
| 48 | 22 | ▶ | sub _cleanup { | ||||||||||||||||||||
|
Subroutine
_cleanup: called CC=3 SCAR=11.0
| |||||||||||||||||||||||
| 49 | 22 | my ($ctl, $is_done) = @_; | |||||||||||||||||||||
| 50 | |||||||||||||||||||||||
| 51 | 22 | ▶ | return unless my $cleanup = $ctl->[3]; | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 52 | 11 | ▶ | return $cleanup->($ctl, $ctl->[2], $is_done || 0); | ||||||||||||||||||||
|
Condition100%2/2
$is_done || 0
MC/DC100%1/1
$is_done || 0
$is_done
Truth table100%2/2
A
A= $is_done
| |||||||||||||||||||||||
| 53 | } | ||||||||||||||||||||||
| 54 | |||||||||||||||||||||||
| 55 | 4 | 1; # End of Async::Hooks::Ctl | |||||||||||||||||||||
| 56 | |||||||||||||||||||||||
| 57 | |||||||||||||||||||||||
| 58 | __END__ | ||||||||||||||||||||||