blib/lib/Math/Matlab/Pool.pm

filter: Statementstmt 58.4% 31 / 53 Branchbran 19.2% 5 / 26 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 72.7% 8 / 11 Podpod 100% 5 / 5 totaltotal 49.0% 49 / 100 CC 14 SCAR 35.8
CC
14
Cov
44%
next_index
90.0
execute
6.0
new
5.2
CRAP 35.7
« blib/lib/Math/Matlab/Local.pm ↑ Summary blib/lib/Math/Matlab/Server.pm »
1 package Math::Matlab::Pool;
2  
3 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use vars qw($VERSION $MEMBERS $SYNC_FILE);
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 1 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 $VERSION = sprintf "%d.%03d", q$Revision: 1.4 $ =~ /: (\d+)\.(\d+)/;
8 }
9  
10 1 ▶use Math::Matlab;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 1 ▶use base qw( Math::Matlab );
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 1 ▶use Fcntl qw(:DEFAULT :flock);
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 ##----- assign defaults, unless already set externally -----
16 1 ▶$MEMBERS = [] unless defined $MEMBERS;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $Math::Matlab::Pool::MEMBERS 0 1 1
17 1 ▶$SYNC_FILE = '/tmp/MatlabPool.lock' unless defined $SYNC_FILE;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $Math::Matlab::Pool::SYNC_FILE 0 1 1
18  
19 ##----- Public Class Methods -----
20 1 ▶sub new {
Subroutine new: called CC=5 SCAR=16.4
Pod documented
21 1 my ($class, $href) = @_;
22 my $self = {
23 members => defined($href->{members}) ? $href->{members} : $MEMBERS,
24 1 ▶ sync_file => defined($href->{sync_file}) ? $href->{sync_file} : $SYNC_FILE,
Branch: 2 branches
BranchTrueFalseTotal
defined $href->{'members'} ? : 0 1 1
defined $href->{'sync_file'} ? : 0 1 1
25 err_msg => '',
26 result => ''
27 };
28  
29 1 bless $self, $class;
30  
31 ## create objects from config as necessary
32 1 foreach my $i ( 0..$#{$self->members} ) {
33 3 my $member = $self->members->[$i];
34 3 ▶ next unless ref $member eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $member eq "HASH" 0 3 3
35 3 my $class = $member->{class};
36 3 $self->members->[$i] = $class->new( $member->{args} );
37 }
38  
39 1 return $self;
40 }
41  
42 ##----- Public Object Methods -----
43 0 ▶sub execute {
Subroutine execute: not called CC=2 SCAR=17.9
Pod documented
44 0 my ($self, $code, $rel_mwd) = @_;
45  
46 0 my $matlab = $self->members->[ $self->next_index ];
47
48 0 ▶ if ($matlab->execute($code, $rel_mwd)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($matlab->execute($code, $rel_mwd)) { } 0 0 0
49 0 $self->{'result'} = $matlab->fetch_raw_result;
50 0 return 1;
51 } else {
52 0 $self->err_msg( $matlab->err_msg );
53 0 return 0;
54 }
55 }
56  
57 0 ▶sub next_index {
Subroutine next_index: not called CC=9 SCAR=45.0
Pod documented
58 0 my ($self) = @_;
59
60 ## the following code from p. 247 of Perl Cookbook
61 0 ▶ sysopen(FH, $self->sync_file, O_RDWR|O_CREAT)
Branch: 1 branch
BranchTrueFalseTotal
sysopen FH, $self->sync_file, 66 or die "can't open syncfile: $!" 0 0 0
62 or die "can't open syncfile: $!";
63 0 ▶ flock(FH, LOCK_EX) or die "can't lock syncfile: $!";
Branch: 1 branch
BranchTrueFalseTotal
flock FH, 2 or die "can't lock syncfile: $!" 0 0 0
64 ## now we have the lock, let's do our stuff
65 0 ▶ my $num = <FH> || $#{$self->members};
Condition0%0/3
readline FH || $#{$self->members;}
l!l&&r!l&&!r
000
MC/DC0%0/2
readline FH || $#{$self->members;}
readline FH $#{$self->members;}
Truth table0%0/3
A || B
A= readline FHB= $#{$self->members;}
ABresult
1X1
011
000
66 0 ▶ seek(FH, 0, 0) or die "can't rewind syncfile: $!";
Branch: 1 branch
BranchTrueFalseTotal
seek FH, 0, 0 or die "can't rewind syncfile: $!" 0 0 0
67 0 ▶ truncate(FH, 0) or die "can't truncate syncfile: $!";
Branch: 1 branch
BranchTrueFalseTotal
truncate FH, 0 or die "can't truncate syncfile: $!" 0 0 0
68 0 $num++;
69 0 ▶ $num = 0 if $num > $#{$self->members};
Branch: 1 branch
BranchTrueFalseTotal
if $num > $#{$self->members;} 0 0 0
70 0 ▶ print FH $num, "\n" or die "can't write syncfile: $!";
Branch: 1 branch
BranchTrueFalseTotal
print FH $num, "\n" or die "can't write syncfile: $!" 0 0 0
71 0 ▶ close(FH) or die "can't close syncfile: $!";
Branch: 1 branch
BranchTrueFalseTotal
close FH or die "can't close syncfile: $!" 0 0 0
72  
73 0 return $num;
74 }
75  
76 7 ▶sub members { my $self = shift; return $self->_getset('members', @_); }
Subroutine members: called CC=1 SCAR=0.0
Pod documented
77 0 ▶sub sync_file { my $self = shift; return $self->_getset('sync_file', @_); }
Subroutine sync_file: not called CC=1 SCAR=6.9
Pod documented
78  
79 1 1;
80 __END__
« blib/lib/Math/Matlab/Local.pm ↑ Summary blib/lib/Math/Matlab/Server.pm »