MCE/Channel.pm

filter: Statementstmt 92.1% 70 / 76 Branchbran 47.2% 17 / 36 Conditioncond 47.6% 10 / 21 MC/DCmcdc 7.1% 1 / 14 Subroutinesub 95.0% 19 / 20 Podpod 100% 2 / 2 totaltotal 70.4% 119 / 169 CC 25 SCAR 18.7
CC
25
Cov
73%
new
15.1
BEGIN
7.0
_read
6.5
CRAP 6.5
« MCE/Subs.pm ↑ Summary MCE/Mutex.pm »
1 ###############################################################################
2 ## ----------------------------------------------------------------------------
3 ## Queue-like and two-way communication capability.
4 ##
5 ###############################################################################
6  
7 package MCE::Channel;
8  
9 15 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 15 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 15 ▶no warnings qw( uninitialized once );
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 15 our $VERSION = '1.904';
15  
16 ## no critic (BuiltinFunctions::ProhibitStringyEval)
17 ## no critic (TestingAndDebugging::ProhibitNoStrict)
18  
19 15 ▶use if $^O eq 'MSWin32', 'threads';
Subroutine BEGIN: called CC=1 SCAR=0.0
20 15 ▶use if $^O eq 'MSWin32', 'threads::shared';
Subroutine BEGIN: called CC=1 SCAR=0.0
21  
22 15 ▶use Carp ();
Subroutine BEGIN: called CC=1 SCAR=0.0
23  
24 15 $Carp::Internal{ (__PACKAGE__) }++;
25  
26 15 my ( $freeze, $thaw );
27  
28 15 ▶BEGIN {
Subroutine BEGIN: called CC=6 SCAR=19.4
29 15 ▶ if ( $] ge '5.008008' && ! $INC{'PDL.pm'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($] ge "5.008008" and not $INC{"PDL.pm"}) 15 0 15
Condition33%1/3
$] ge "5.008008" and not $INC{"PDL.pm"}
!ll&&!rl&&r
0015
MC/DC0%0/2
$] ge "5.008008" and not $INC{"PDL.pm"}
$] ge "5.008008" not $INC{"PDL.pm"}
Truth table33%1/3
A and not(B)
A= $] ge "5.008008"B= not $INC{"PDL.pm"}
ABresult
0X0
100
111
30 15 local $@;
31 15 ▶ eval 'use Sereal::Encoder 3.015; use Sereal::Decoder 3.015;';
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
32 15 ▶ if ( ! $@ ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($@) 15 0 15
33 15 my $encoder_ver = int( Sereal::Encoder->VERSION() );
34 15 my $decoder_ver = int( Sereal::Decoder->VERSION() );
35 15 ▶ if ( $encoder_ver - $decoder_ver == 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($encoder_ver - $decoder_ver == 0) 15 0 15
36 15 $freeze = \&Sereal::Encoder::encode_sereal;
37 15 $thaw = \&Sereal::Decoder::decode_sereal;
38 }
39 }
40 }
41  
42 15 ▶ if ( ! defined $freeze ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $freeze) 0 15 15
43 0 require Storable;
44 0 $freeze = \&Storable::freeze;
45 0 $thaw = \&Storable::thaw;
46 }
47 }
48  
49 15 ▶use MCE::Util ();
Subroutine BEGIN: called CC=1 SCAR=0.0
50  
51 15 ▶my $tid = $INC{'threads.pm'} ? threads->tid() : 0;
Branch: 1 branch
BranchTrueFalseTotal
$INC{'threads.pm'} ? : 0 15 15
52  
53 23 ▶sub new {
Subroutine new: called CC=11 SCAR=27.2
Pod documented
54 23 my ( $class, %argv ) = @_;
55 23 ▶ my $impl = defined( $argv{impl} ) ? ucfirst( lc $argv{impl} ) : 'Mutex';
Branch: 1 branch
BranchTrueFalseTotal
defined $argv{'impl'} ? : 23 0 23
56  
57 # Replace 'fast' with 'Fast' in the implementation value.
58 23 $impl =~ s/fast/Fast/;
59  
60 23 ▶ $impl = 'Threads' if ( $impl eq 'Mutex' && $^O eq 'MSWin32' );
Branch: 1 branch
BranchTrueFalseTotal
if $impl eq "Mutex" and $^O eq "MSWin32" 0 23 23
Condition66%2/3
$impl eq "Mutex" and $^O eq "MSWin32"
!ll&&!rl&&r
12110
MC/DC0%0/2
$impl eq "Mutex" and $^O eq "MSWin32"
$impl eq "Mutex" $^O eq "MSWin32"
Truth table66%2/3
A and B
A= $impl eq "Mutex"B= $^O eq "MSWin32"
ABresult
0X0
100
111
61 23 ▶ $impl = 'ThreadsFast' if ( $impl eq 'MutexFast' && $^O eq 'MSWin32' );
Branch: 1 branch
BranchTrueFalseTotal
if $impl eq "MutexFast" and $^O eq "MSWin32" 0 23 23
Condition66%2/3
$impl eq "MutexFast" and $^O eq "MSWin32"
!ll&&!rl&&r
13100
MC/DC0%0/2
$impl eq "MutexFast" and $^O eq "MSWin32"
$impl eq "MutexFast" $^O eq "MSWin32"
Truth table66%2/3
A and B
A= $impl eq "MutexFast"B= $^O eq "MSWin32"
ABresult
0X0
100
111
62 23 ▶ $impl = 'Mutex' if ( $impl eq 'Threads' && $^O eq 'cygwin' );
Branch: 1 branch
BranchTrueFalseTotal
if $impl eq "Threads" and $^O eq "cygwin" 0 23 23
Condition33%1/3
$impl eq "Threads" and $^O eq "cygwin"
!ll&&!rl&&r
2300
MC/DC0%0/2
$impl eq "Threads" and $^O eq "cygwin"
$impl eq "Threads" $^O eq "cygwin"
Truth table33%1/3
A and B
A= $impl eq "Threads"B= $^O eq "cygwin"
ABresult
0X0
100
111
63 23 ▶ $impl = 'MutexFast' if ( $impl eq 'ThreadsFast' && $^O eq 'cygwin' );
Branch: 1 branch
BranchTrueFalseTotal
if $impl eq "ThreadsFast" and $^O eq "cygwin" 0 23 23
Condition33%1/3
$impl eq "ThreadsFast" and $^O eq "cygwin"
!ll&&!rl&&r
2300
MC/DC0%0/2
$impl eq "ThreadsFast" and $^O eq "cygwin"
$impl eq "ThreadsFast" $^O eq "cygwin"
Truth table33%1/3
A and B
A= $impl eq "ThreadsFast"B= $^O eq "cygwin"
ABresult
0X0
100
111
64  
65 23 ▶ eval "require MCE::Channel::$impl; 1;" ||
Branch: 1 branch
BranchTrueFalseTotal
eval "require MCE::Channel::$impl; 1;" or Carp::croak("Could not load Channel implementation '${impl}': $@") 23 0 23
66 Carp::croak("Could not load Channel implementation '$impl': $@");
67  
68 23 my $pkg = 'MCE::Channel::'.$impl;
69 15 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
70  
71 23 $pkg->new(%argv);
72 }
73  
74 0 ▶sub CLONE {
Subroutine CLONE: not called CC=2 SCAR=17.9
75 0 ▶ $tid = threads->tid if $INC{'threads.pm'};
Branch: 1 branch
BranchTrueFalseTotal
if $INC{"threads.pm"} 0 0 0
76 }
77  
78 16 ▶sub DESTROY {
Subroutine DESTROY: called CC=4 SCAR=14.0
79 16 ▶ my ( $pid, $self ) = ( $tid ? $$ .'.'. $tid : $$, @_ );
Branch: 1 branch
BranchTrueFalseTotal
$tid ? : 0 16 16
80  
81 16 ▶ if ( $self->{'init_pid'} && $self->{'init_pid'} eq $pid ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"init_pid"} and $self->{"init_pid"} eq $pid) 13 3 16
Condition66%2/3
$self->{"init_pid"} and $self->{"init_pid"} eq $pid
!ll&&!rl&&r
0313
MC/DC50%1/2
$self->{"init_pid"} and $self->{"init_pid"} eq $pid
$self->{"init_pid"} $self->{"init_pid"} eq $pid
Truth table66%2/3
A and B
A= $self->{"init_pid"}B= $self->{"init_pid"} eq $pid
ABresult
0X0
100
111
82 13 MCE::Util::_destroy_socks($self, qw(c_sock c2_sock p_sock p2_sock));
83 13 delete($self->{c_mutex}), delete($self->{p_mutex});
84 }
85  
86 16 return;
87 }
88  
89 6 ▶sub impl {
Subroutine impl: called CC=2 SCAR=7.6
Pod documented
90 6 ▶ $_[0]->{'impl'} || 'Not defined';
Branch: 1 branch
BranchTrueFalseTotal
$_[0]{"impl"} or "Not defined" 6 0 6
91 }
92  
93 12 ▶sub _get_freeze { $freeze; }
Subroutine _get_freeze: called CC=1 SCAR=0.0
94 12 ▶sub _get_thaw { $thaw; }
Subroutine _get_thaw: called CC=1 SCAR=0.0
95  
96 12 ▶sub _ended {
Subroutine _ended: called CC=1 SCAR=0.0
97 12 warn "WARNING: ($_[0]) called on a channel that has been 'end'ed\n";
98  
99 12 return;
100 }
101  
102 120 ▶sub _read {
Subroutine _read: called CC=4 SCAR=18.7
103 120 my $bytes = MCE::Util::_sysread( $_[0], $_[1], my $len = $_[2] );
104 120 my $read = $bytes;
105  
106 120 ▶ while ( $bytes && $read != $len ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($bytes and $read != $len) 0 120 120
Condition33%1/3
$bytes and $read != $len
!ll&&!rl&&r
01200
MC/DC0%0/2
$bytes and $read != $len
$bytes $read != $len
Truth table33%1/3
A and B
A= $bytesB= $read != $len
ABresult
0X0
100
111
107 0 $bytes = MCE::Util::_sysread( $_[0], $_[1], $len - $read, length($_[1]) );
108 0 ▶ $read += $bytes if $bytes;
Branch: 1 branch
BranchTrueFalseTotal
if $bytes 0 0 0
109 }
110  
111 120 return;
112 }
113  
114 23 ▶sub _pid {
Subroutine _pid: called CC=2 SCAR=7.6
115 23 ▶ $tid ? $$ .'.'. $tid : $$;
Branch: 1 branch
BranchTrueFalseTotal
$tid ? : 0 23 23
116 }
117  
118 15 1;
119  
120 __END__
« MCE/Subs.pm ↑ Summary MCE/Mutex.pm »