blib/lib/IO/Async/Internals/FunctionWorker.pm

filter: Statementstmt 78.5% 22 / 28 Branchbran 41.6% 5 / 12 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 4 / 4 Podpod 0.0% 0 / 2 totaltotal 67.3% 31 / 46 CC 7 SCAR 14.1
CC
7
Cov
68%
runloop
4.9
run_worker
4.8
BEGIN
1.0
CRAP 4.1
« Build ↑ Summary blib/lib/IO/Async/Timer/Absolute.pm »
1 # You may distribute under the terms of either the GNU General Public License
2 # or the Artistic License (the same terms as Perl itself)
3 #
4 # (C) Paul Evans, 2011-2024 -- leonerd@leonerd.org.uk
5  
6 package IO::Async::Internals::FunctionWorker 0.805;
7  
8 11 ▶use v5.14;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 11 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 # Called directly by IO::Async::Function::Worker when used in "code" mode,
12 # or by run_worker() below.
13 sub runloop
14 {
15 2 ▶ my ( $code, $arg_channel, $ret_channel ) = @_;
Subroutine runloop: called CC=4 SCAR=16.0
Pod undocumented
16  
17 2 ▶ while( my $args = $arg_channel->recv ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $args = $arg_channel->recv) 2 1 3
18 2 my @ret;
19 2 my $ok = eval { @ret = $code->( @$args ); 1 };
20  
21 1 ▶ if( $ok ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($ok) { } 1 0 1
elsif (ref $@) { } 0 0 0
22 1 $ret_channel->send( [ r => @ret ] );
23 }
24 elsif( ref $@ ) {
25 # Presume that $@ is an ARRAYref of error results
26 0 $ret_channel->send( [ e => @{ $@ } ] );
27 }
28 else {
29 0 chomp( my $e = "$@" );
30 0 $ret_channel->send( [ e => $e, error => ] );
31 }
32 }
33 }
34  
35 # Called by IO::Async::Function::Worker via the module+func arguments to its
36 # IO::Async::Routine superclass when used in "module+func" mode
37 sub run_worker
38 {
39 1 ▶ my ( $arg_channel, $ret_channel ) = @_;
Subroutine run_worker: called CC=4 SCAR=15.8
Pod undocumented
40  
41 # Setup args
42 1 my ( $module, $func, $init_func, @init_args ) = @{ $arg_channel->recv };
43  
44 1 ( my $file = "$module.pm" ) =~ s{::}{/}g;
45 1 require $file;
46  
47 1 ▶ my $code = $module->can( $func ) or
Branch: 1 branch
BranchTrueFalseTotal
my $code = $module->can($func) or die "Module $module does not provide a function called $func\n" 0 1 1
48 die "Module $module does not provide a function called $func\n";
49  
50 1 ▶ if( defined $init_func ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $init_func) 0 1 1
51 0 ▶ my $init = $module->can( $init_func ) or
Branch: 1 branch
BranchTrueFalseTotal
my $init = $module->can($init_func) or die "Module $module does not provide a function called $init_func\n" 0 0 0
52 die "Module $module does not provide a function called $init_func\n";
53  
54 0 $init->( @init_args );
55 }
56  
57 1 runloop( $code, $arg_channel, $ret_channel );
58 }
59  
60 11 0x55AA;
« Build ↑ Summary blib/lib/IO/Async/Timer/Absolute.pm »