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 SCAR 36.2
CC
25
Cov
73%
new
15.1
BEGIN
7.0
_read
6.5
CRAP 37.4
« 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 18 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 18 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 18 ▶no warnings qw( uninitialized once );
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 18 our $VERSION = '1.889';
15  
16 ## no critic (BuiltinFunctions::ProhibitStringyEval)
17 ## no critic (TestingAndDebugging::ProhibitNoStrict)
18  
19 18 ▶use if $^O eq 'MSWin32', 'threads';
Subroutine BEGIN: called CC=1 SCAR=0.0
20 18 ▶use if $^O eq 'MSWin32', 'threads::shared';
Subroutine BEGIN: called CC=1 SCAR=0.0
21  
22 18 ▶use Carp ();
Subroutine BEGIN: called CC=1 SCAR=0.0
23  
24 18 $Carp::Internal{ (__PACKAGE__) }++;
25  
26 18 my ( $freeze, $thaw );
27  
28 BEGIN {
29 18 ▶ if ( $] ge '5.008008' && ! $INC{'PDL.pm'} ) {
Subroutine BEGIN: called CC=6 SCAR=19.4
Branch: 1 branch
BranchTrueFalseTotal
if ($] ge "5.008008" and not $INC{"PDL.pm"}) 18 0 18
Condition33%1/3
$] ge "5.008008" and not $INC{"PDL.pm"}
!ll&&!rl&&r
0018
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 18 local $@;
31 18 ▶ 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 18 ▶ if ( ! $@ ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($@) 18 0 18
33 18 my $encoder_ver = int( Sereal::Encoder->VERSION() );
34 18 my $decoder_ver = int( Sereal::Decoder->VERSION() );
35 18 ▶ if ( $encoder_ver - $decoder_ver == 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($encoder_ver - $decoder_ver == 0) 18 0 18
36 18 $freeze = \&Sereal::Encoder::encode_sereal;
37 18 $thaw = \&Sereal::Decoder::decode_sereal;
38 }
39 }
40 }
41  
42 18 ▶ if ( ! defined $freeze ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $freeze) 0 18 18
43 0 require Storable;
44 0 $freeze = \&Storable::freeze;
45 0 $thaw = \&Storable::thaw;
46 }
47 }
48  
49 18 ▶use MCE::Util ();
Subroutine BEGIN: called CC=1 SCAR=0.0
50  
51 18 ▶my $tid = $INC{'threads.pm'} ? threads->tid() : 0;
Branch: 1 branch
BranchTrueFalseTotal
$INC{'threads.pm'} ? : 0 18 18
52  
53 sub new {
54 29 ▶ my ( $class, %argv ) = @_;
Subroutine new: called CC=11 SCAR=27.2
Pod documented
55 29 ▶ my $impl = defined( $argv{impl} ) ? ucfirst( lc $argv{impl} ) : 'Mutex';
Branch: 1 branch
BranchTrueFalseTotal
defined $argv{'impl'} ? : 29 0 29
56  
57 # Replace 'fast' with 'Fast' in the implementation value.
58 29 $impl =~ s/fast/Fast/;
59  
60 29 ▶ $impl = 'Threads' if ( $impl eq 'Mutex' && $^O eq 'MSWin32' );
Branch: 1 branch
BranchTrueFalseTotal
if $impl eq "Mutex" and $^O eq "MSWin32" 0 29 29
Condition66%2/3
$impl eq "Mutex" and $^O eq "MSWin32"
!ll&&!rl&&r
15140
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 29 ▶ $impl = 'ThreadsFast' if ( $impl eq 'MutexFast' && $^O eq 'MSWin32' );
Branch: 1 branch
BranchTrueFalseTotal
if $impl eq "MutexFast" and $^O eq "MSWin32" 0 29 29
Condition66%2/3
$impl eq "MutexFast" and $^O eq "MSWin32"
!ll&&!rl&&r
16130
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 29 ▶ $impl = 'Mutex' if ( $impl eq 'Threads' && $^O eq 'cygwin' );
Branch: 1 branch
BranchTrueFalseTotal
if $impl eq "Threads" and $^O eq "cygwin" 0 29 29
Condition33%1/3
$impl eq "Threads" and $^O eq "cygwin"
!ll&&!rl&&r
2900
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 29 ▶ $impl = 'MutexFast' if ( $impl eq 'ThreadsFast' && $^O eq 'cygwin' );
Branch: 1 branch
BranchTrueFalseTotal
if $impl eq "ThreadsFast" and $^O eq "cygwin" 0 29 29
Condition33%1/3
$impl eq "ThreadsFast" and $^O eq "cygwin"
!ll&&!rl&&r
2900
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 29 ▶ 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}': $@") 0 29 29
66 Carp::croak("Could not load Channel implementation '$impl': $@");
67  
68 29 my $pkg = 'MCE::Channel::'.$impl;
69 18 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
70  
71 29 $pkg->new(%argv);
72 }
73  
74 sub CLONE {
75 0 ▶ $tid = threads->tid if $INC{'threads.pm'};
Subroutine CLONE: not called CC=2 SCAR=17.9
Branch: 1 branch
BranchTrueFalseTotal
if $INC{"threads.pm"} 0 0 0
76 }
77  
78 sub DESTROY {
79 19 ▶ my ( $pid, $self ) = ( $tid ? $$ .'.'. $tid : $$, @_ );
Subroutine DESTROY: called CC=4 SCAR=14.0
Branch: 1 branch
BranchTrueFalseTotal
$tid ? : 0 19 19
80  
81 19 ▶ if ( $self->{'init_pid'} && $self->{'init_pid'} eq $pid ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"init_pid"} and $self->{"init_pid"} eq $pid) 16 3 19
Condition66%2/3
$self->{"init_pid"} and $self->{"init_pid"} eq $pid
!ll&&!rl&&r
0316
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 16 MCE::Util::_destroy_socks($self, qw(c_sock c2_sock p_sock p2_sock));
83 16 delete($self->{c_mutex}), delete($self->{p_mutex});
84 }
85  
86 19 return;
87 }
88  
89 sub impl {
90 6 ▶ $_[0]->{'impl'} || 'Not defined';
Subroutine impl: called CC=2 SCAR=7.6
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
$_[0]{"impl"} or "Not defined" 0 6 6
91 }
92  
93 15 ▶sub _get_freeze { $freeze; }
Subroutine _get_freeze: called CC=1 SCAR=0.0
94 15 ▶sub _get_thaw { $thaw; }
Subroutine _get_thaw: called CC=1 SCAR=0.0
95  
96 sub _ended {
97 12 ▶ warn "WARNING: ($_[0]) called on a channel that has been 'end'ed\n";
Subroutine _ended: called CC=1 SCAR=0.0
98  
99 12 return;
100 }
101  
102 sub _read {
103 120 ▶ my $bytes = MCE::Util::_sysread( $_[0], $_[1], my $len = $_[2] );
Subroutine _read: called CC=4 SCAR=18.7
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 sub _pid {
115 29 ▶ $tid ? $$ .'.'. $tid : $$;
Subroutine _pid: called CC=2 SCAR=7.6
Branch: 1 branch
BranchTrueFalseTotal
$tid ? : 0 29 29
116 }
117  
118 18 1;
119  
120 __END__
« MCE/Subs.pm ↑ Summary MCE/Mutex.pm »