Planar/Data.pm

filter: Statementstmt 100% 104 / 104 Branchbran 90.0% 36 / 40 Conditioncond 88.8% 8 / 9 MC/DCmcdc 60.0% 3 / 5 Subroutinesub 100% 31 / 31 Podpod 100% 14 / 14 totaltotal 96.5% 196 / 203 SCAR 31.8
CC
24
Cov
97%
_iterate
8.0
list_databases
6.2
new
6.0
CRAP 24.0
« Planar.pm ↑ Summary Planar/Schema/Result/DifferenceSet.pm »
1 package Math::DifferenceSet::Planar::Data;
2  
3 6 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 6 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 6 ▶use Carp qw(croak);
Subroutine BEGIN: called CC=1 SCAR=0.0
6 6 ▶use File::Spec;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 6 ▶use File::Share qw(dist_dir);
Subroutine BEGIN: called CC=1 SCAR=0.0
8 6 ▶use DBD::SQLite::Constants qw(SQLITE_OPEN_READONLY);
Subroutine BEGIN: called CC=1 SCAR=0.0
9 6 ▶use Math::DifferenceSet::Planar::Schema;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 # Math::DifferenceSet::Planar::Data=ARRAY(...)
12  
13 # .......... index .......... # .......... value ..........
14 6 ▶use constant _F_DATA => 0; # difference set result set object
Subroutine BEGIN: called CC=1 SCAR=0.0
15 6 ▶use constant _F_SPACES => 1; # PDS space result set object or undef
Subroutine BEGIN: called CC=1 SCAR=0.0
16 6 ▶use constant _F_PATH => 2; # database path name
Subroutine BEGIN: called CC=1 SCAR=0.0
17 6 ▶use constant _NFIELDS => 3;
Subroutine BEGIN: called CC=1 SCAR=0.0
18  
19 6 our $VERSION = '0.018';
20 6 our @CARP_NOT = qw(Math::DifferenceSet::Planar);
21  
22 6 our $DATABASE_DIR = dist_dir('Math-DifferenceSet-Planar');
23  
24 # ----- private subroutines -----
25  
26 sub _iterate {
27 16 ▶ my ($domain, $min, $max, @columns) = @_;
Subroutine _iterate: called CC=8 SCAR=20.8
28 16 my @sel = ();
29 16 my $dir = 'ASC';
30 16 ▶ if (defined($min) && defined($max) && $min > $max) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $min and defined $max and $min > $max) 3 13 16
Condition100%6/6
defined $min and defined $max and $min > $max
!ll&&!rl&&r
943
defined $min and defined $max
!ll&&!rl&&r
637
MC/DC100%3/3
defined $min and defined $max and $min > $max
defined $min defined $max $min > $max
Truth table100%4/4
A and B and C
A= defined $minB= defined $maxC= $min > $max
ABCresult
0XX0
10X0
1100
1111
31 3 ($min, $max, $dir) = ($max, $min, 'DESC');
32 }
33 16 ▶ push @sel, '>=' => $min if defined $min;
Branch: 1 branch
BranchTrueFalseTotal
if defined $min 10 6 16
34 16 ▶ push @sel, '<=' => $max if defined $max;
Branch: 1 branch
BranchTrueFalseTotal
if defined $max 10 6 16
35 16 ▶ my $results = $domain->search(
Branch: 2 branches
BranchTrueFalseTotal
@sel ? : 13 3 16
@columns ? : 5 11 16
36 @sel? { order_ => { @sel } }: undef,
37 {
38 @columns? ( columns => \@columns ): (),
39 order_by => "order_ $dir",
40 }
41 );
42 16 ▶ return sub { $results->next };
Subroutine __ANON__: called CC=1 SCAR=0.0
43 }
44  
45 # ----- private accessor methods -----
46  
47 79 ▶sub _data { $_[0]->[_F_DATA] }
Subroutine _data: called CC=1 SCAR=0.0
48 37 ▶sub _spaces { $_[0]->[_F_SPACES] }
Subroutine _spaces: called CC=1 SCAR=0.0
49 1 ▶sub _path { $_[0]->[_F_PATH] }
Subroutine _path: called CC=1 SCAR=0.0
50  
51 # ----- class methods -----
52  
53 sub list_databases {
54 7 ▶ opendir my $dh, $DATABASE_DIR or return ();
Subroutine list_databases: called CC=6 SCAR=18.3
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
opendir my $dh, $Math::DifferenceSet::Planar::Data::DATABASE_DIR or return () 0 7 7
55 my @files =
56 map {
57 11 ▶ my $is_standard = /^pds[_\W]/i? 1: 0;
Branch: 1 branch
BranchTrueFalseTotal
/^pds[_\W]/i ? : 9 2 11
58 11 my $path = File::Spec->rel2abs($_, $DATABASE_DIR);
59 11 ▶ (-f $path)? [$_, $is_standard, -s _]: ()
Branch: 1 branch
BranchTrueFalseTotal
-f $path ? : 11 0 11
60 }
61 7 grep { /\.db\z/i } readdir $dh;
62 7 closedir $dh;
63 return
64 11 map { $_->[0] }
65 sort {
66 7 ▶ $b->[1] <=> $a->[1] || $b->[2] <=> $a->[2] ||
Branch: 1 branch
BranchTrueFalseTotal
$Math::DifferenceSet::Planar::Data::b->[1] <=> $Math::DifferenceSet::Planar::Data::a->[1] or $Math::DifferenceSet::Planar::Data::b->[2] <=> $Math::DifferenceSet::Planar::Data::a->[2] or $Math::DifferenceSet::Planar::Data::a->[0] cmp $Math::DifferenceSet::Planar::Data::b->[0] 0 6 6
Condition66%2/3
$Math::DifferenceSet::Planar::Data::b->[1] <=> $Math::DifferenceSet::Planar::Data::a->[1] or $Math::DifferenceSet::Planar::Data::b->[2] <=> $Math::DifferenceSet::Planar::Data::a->[2]
l!l&&r!l&&!r
420
MC/DC0%0/2
$Math::DifferenceSet::Planar::Data::b->[1] <=> $Math::DifferenceSet::Planar::Data::a->[1] or $Math::DifferenceSet::Planar::Data::b->[2] <=> $Math::DifferenceSet::Planar::Data::a->[2]
$Math::DifferenceSet::Planar::Data::b->[1] <=> $Math::DifferenceSet::Planar::Data::a->[1] $Math::DifferenceSet::Planar::Data::b->[2] <=> $Math::DifferenceSet::Planar::Data::a->[2]
Truth table66%2/3
A or B
A= $Math::DifferenceSet::Planar::Data::b->[1] <=> $Math::DifferenceSet::Planar::Data::a->[1]B= $Math::DifferenceSet::Planar::Data::b->[2] <=> $Math::DifferenceSet::Planar::Data::a->[2]
ABresult
1X1
011
000
67 $a->[0] cmp $b->[0]
68 }
69 @files;
70 }
71  
72 sub new {
73 11 ▶ my $class = shift;
Subroutine new: called CC=6 SCAR=17.9
Pod documented
74 11 ▶ my ($filename) = @_? @_: $class->list_databases
Branch: 2 branches
BranchTrueFalseTotal
my($filename) = @_ ? @_ : $class->list_databases or croak("bad database: empty share directory: $Math::DifferenceSet::Planar::Data::DATABASE_DIR") 0 11 11
@_ ? : 6 5 11
75 or croak "bad database: empty share directory: $DATABASE_DIR";
76 11 my $path = File::Spec->rel2abs($filename, $DATABASE_DIR);
77 11 ▶ -e $path or croak "bad database: file does not exist: $path";
Branch: 1 branch
BranchTrueFalseTotal
-e $path or croak("bad database: file does not exist: $path") 2 9 11
78 9 my $schema =
79 Math::DifferenceSet::Planar::Schema->connect(
80 "dbi:SQLite:$path", q[], q[],
81 { sqlite_open_flags => SQLITE_OPEN_READONLY },
82 );
83 9 my $data = $schema->resultset('DifferenceSet');
84 9 my $count = eval { $data->search->count };
85 9 ▶ croak "bad database: query failed: $@" if !defined $count;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $count 1 8 9
86 8 my $spaces = $schema->resultset('DifferenceSetSpace');
87 8 ▶ undef $spaces if !eval { $spaces->search->count };
Branch: 1 branch
BranchTrueFalseTotal
unless eval { do { $spaces->search->count } } 1 7 8
88 8 return bless [$data, $spaces, $path], $class;
89 }
90  
91 # ----- object methods -----
92  
93 sub get {
94 45 ▶ my ($this, $order, @columns) = @_;
Subroutine get: called CC=2 SCAR=6.9
Pod documented
95 45 ▶ return $this->_data->search(
Branch: 1 branch
BranchTrueFalseTotal
@columns ? : 6 39 45
96 { order_ => $order },
97 @columns ? { columns => \@columns } : ()
98 )->single;
99 }
100  
101 sub get_space {
102 16 ▶ my ($this, $order) = @_;
Subroutine get_space: called CC=2 SCAR=6.9
Pod documented
103 16 my $spaces = $this->_spaces;
104 16 ▶ return undef if !defined $spaces;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $spaces 1 15 16
105 15 return $spaces->search({ order_ => $order })->single;
106 }
107  
108 sub iterate {
109 6 ▶ my ($this, $min, $max) = @_;
Subroutine iterate: called CC=1 SCAR=0.0
Pod documented
110 6 return _iterate($this->_data, $min, $max);
111 }
112  
113 sub iterate_properties {
114 5 ▶ my ($this, $min, $max) = @_;
Subroutine iterate_properties: called CC=1 SCAR=0.0
Pod documented
115 5 my @columns = qw(order_ base exponent modulus n_planes);
116 5 return _iterate($this->_data, $min, $max, @columns);
117 }
118  
119 sub iterate_spaces {
120 6 ▶ my ($this, $min, $max) = @_;
Subroutine iterate_spaces: called CC=2 SCAR=6.9
Pod documented
121 6 my $spaces = $this->_spaces;
122 6 ▶ return sub {} if !defined $spaces;
Subroutine __ANON__: called CC=1 SCAR=0.0
Branch: 1 branch
BranchTrueFalseTotal
unless defined $spaces 1 5 6
123 5 return _iterate($spaces, $min, $max);
124 }
125  
126 4 ▶sub min_order { $_[0]->_data->get_column('order_')->min }
Subroutine min_order: called CC=1 SCAR=0.0
Pod documented
127 14 ▶sub max_order { $_[0]->_data->get_column('order_')->max }
Subroutine max_order: called CC=1 SCAR=0.0
Pod documented
128 5 ▶sub count { $_[0]->_data->search->count }
Subroutine count: called CC=1 SCAR=0.0
Pod documented
129 1 ▶sub path { $_[0]->_path }
Subroutine path: called CC=1 SCAR=0.0
Pod documented
130  
131 sub sp_min_order {
132 3 ▶ my ($this) = @_;
Subroutine sp_min_order: called CC=2 SCAR=6.9
Pod documented
133 3 my $spaces = $this->_spaces;
134 3 ▶ return undef if !defined $spaces;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $spaces 1 2 3
135 2 return $spaces->get_column('order_')->min;
136 }
137  
138 sub sp_max_order {
139 9 ▶ my ($this) = @_;
Subroutine sp_max_order: called CC=2 SCAR=6.9
Pod documented
140 9 my $spaces = $this->_spaces;
141 9 ▶ return 0 if !defined $spaces;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $spaces 1 8 9
142 8 return $spaces->get_column('order_')->max;
143 }
144  
145 sub sp_count {
146 3 ▶ my ($this) = @_;
Subroutine sp_count: called CC=2 SCAR=6.9
Pod documented
147 3 my $spaces = $this->_spaces;
148 3 ▶ return 0 if !defined $spaces;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $spaces 1 2 3
149 2 return $spaces->search->count;
150 }
151  
152 6 1;
153  
154 __END__
« Planar.pm ↑ Summary Planar/Schema/Result/DifferenceSet.pm »