Planar/Data.pm

filter: Statementstmt 93.2% 125 / 134 Branchbran 83.3% 40 / 48 Conditioncond 72.2% 13 / 18 MC/DCmcdc 50.0% 5 / 10 Subroutinesub 90.2% 37 / 41 Podpod 100% 20 / 20 totaltotal 88.5% 240 / 271 CC 32 SCAR 13.3
CC
32
Cov
89%
_iterate
10.0
new
7.1
list_databases
6.4
CRAP 3.8
« Planar.pm ↑ Summary Planar/Schema/Result/DifferenceSet.pm »
1 package Math::DifferenceSet::Planar::Data;
2  
3 7 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 7 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 7 ▶use Carp qw(croak);
Subroutine BEGIN: called CC=1 SCAR=0.0
6 7 ▶use File::Spec;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 7 ▶use File::Share qw(dist_dir);
Subroutine BEGIN: called CC=1 SCAR=0.0
8 7 ▶use DBD::SQLite::Constants qw(SQLITE_OPEN_READONLY);
Subroutine BEGIN: called CC=1 SCAR=0.0
9 7 ▶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 7 ▶use constant _F_DATA => 0; # difference set result set object
Subroutine BEGIN: called CC=1 SCAR=0.0
15 7 ▶use constant _F_SPACES => 1; # PDS space result set object or undef
Subroutine BEGIN: called CC=1 SCAR=0.0
16 7 ▶use constant _F_VERSION => 2; # PDS space result set object or undef
Subroutine BEGIN: called CC=1 SCAR=0.0
17 7 ▶use constant _F_PATH => 3; # database path name
Subroutine BEGIN: called CC=1 SCAR=0.0
18 7 ▶use constant _NFIELDS => 4;
Subroutine BEGIN: called CC=1 SCAR=0.0
19  
20 7 our $VERSION = '1.003';
21 7 our @CARP_NOT = qw(Math::DifferenceSet::Planar);
22  
23 7 our $DATABASE_DIR = dist_dir('Math-DifferenceSet-Planar');
24  
25 7 ▶use constant _KNOWN => { '<>' => 0 };
Subroutine BEGIN: called CC=1 SCAR=0.0
26  
27 # ----- private subroutines -----
28  
29 9 ▶sub _iterate {
Subroutine _iterate: called CC=10 SCAR=23.0
30 9 my ($domain, $query, $min, $max, @columns) = @_;
31 0 ▶ my @sel = $query? @{$query}: ();
Branch: 1 branch
BranchTrueFalseTotal
$query ? : 0 9 9
32 9 my @osel = ();
33 9 my $dir = 'ASC';
34 9 ▶ if (defined($min) && defined($max) && $min > $max) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $min and defined $max and $min > $max) 1 8 9
Condition100%6/6
defined $min and defined $max and $min > $max
!ll&&!rl&&r
531
defined $min and defined $max
!ll&&!rl&&r
414
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
35 1 ($min, $max, $dir) = ($max, $min, 'DESC');
36 }
37 9 ▶ push @osel, '>=' => $min if defined $min;
Branch: 1 branch
BranchTrueFalseTotal
if defined $min 5 4 9
38 9 ▶ push @osel, '<=' => $max if defined $max;
Branch: 1 branch
BranchTrueFalseTotal
if defined $max 5 4 9
39 9 ▶ push @sel, order_ => { @osel } if @osel;
Branch: 1 branch
BranchTrueFalseTotal
if @osel 6 3 9
40 9 ▶ my $results = $domain->search(
Branch: 2 branches
BranchTrueFalseTotal
@sel ? : 6 3 9
@columns ? : 7 2 9
41 @sel? { @sel }: undef,
42 {
43 @columns? ( columns => \@columns ): (),
44 order_by => "order_ $dir",
45 }
46 );
47 9 ▶ return sub { $results->next };
Subroutine __ANON__: called CC=1 SCAR=0.0
48 }
49  
50 # ----- private accessor methods -----
51  
52 50 ▶sub _data { $_[0]->[_F_DATA] }
Subroutine _data: called CC=1 SCAR=0.0
53 17 ▶sub _spaces { $_[0]->[_F_SPACES] }
Subroutine _spaces: called CC=1 SCAR=0.0
54 2 ▶sub _version { $_[0]->[_F_VERSION] }
Subroutine _version: called CC=1 SCAR=0.0
55 1 ▶sub _path { $_[0]->[_F_PATH] }
Subroutine _path: called CC=1 SCAR=0.0
56  
57 2 ▶sub _get_version_of {
Subroutine _get_version_of: called CC=3 SCAR=11.2
58 2 my ($this, $table_name) = @_;
59 2 my $version = $this->_version;
60 2 ▶ return (0, 0) if !defined $version;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $version 0 2 2
61 2 my $rec = $version->search({ table_name => $table_name })->single;
62 2 ▶ return (0, 0) if !defined $rec;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $rec 0 2 2
63 2 return ($rec->major, $rec->minor);
64 }
65  
66 # ----- class methods -----
67  
68 7 ▶sub list_databases {
Subroutine list_databases: called CC=6 SCAR=18.6
Pod documented
69 7 ▶ opendir my $dh, $DATABASE_DIR or return ();
Branch: 1 branch
BranchTrueFalseTotal
opendir my $dh, $Math::DifferenceSet::Planar::Data::DATABASE_DIR or return () 7 0 7
70 my @files =
71 map {
72 11 ▶ my $is_standard = /^pds[_\W]/i? 1: 0;
Branch: 1 branch
BranchTrueFalseTotal
/^pds[_\W]/i ? : 9 2 11
73 11 my $path = File::Spec->rel2abs($_, $DATABASE_DIR);
74 11 ▶ (-f $path)? [$_, $is_standard, -s _]: ()
Branch: 1 branch
BranchTrueFalseTotal
-f $path ? : 11 0 11
75 }
76 7 grep { /\.db\z/i } readdir $dh;
77 7 closedir $dh;
78 return
79 11 map { $_->[0] }
80 sort {
81 7 ▶ $b->[1] <=> $a->[1] || $b->[2] <=> $a->[2] ||
Condition50%3/6
$Math::DifferenceSet::Planar::Data::b->[1] <=> $Math::DifferenceSet::Planar::Data::a->[1] || $Math::DifferenceSet::Planar::Data::b->[2] <=> $Math::DifferenceSet::Planar::Data::a->[2] || $Math::DifferenceSet::Planar::Data::a->[0] cmp $Math::DifferenceSet::Planar::Data::b->[0]
l!l&&r!l&&!r
600
$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/3
$Math::DifferenceSet::Planar::Data::b->[1] <=> $Math::DifferenceSet::Planar::Data::a->[1] || $Math::DifferenceSet::Planar::Data::b->[2] <=> $Math::DifferenceSet::Planar::Data::a->[2] || $Math::DifferenceSet::Planar::Data::a->[0] cmp $Math::DifferenceSet::Planar::Data::b->[0]
$Math::DifferenceSet::Planar::Data::b->[1] <=> $Math::DifferenceSet::Planar::Data::a->[1] $Math::DifferenceSet::Planar::Data::b->[2] <=> $Math::DifferenceSet::Planar::Data::a->[2] $Math::DifferenceSet::Planar::Data::a->[0] cmp $Math::DifferenceSet::Planar::Data::b->[0]
Truth table50%2/4
A or B || C
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]C= $Math::DifferenceSet::Planar::Data::a->[0] cmp $Math::DifferenceSet::Planar::Data::b->[0]
ABCresult
1XX1
01X1
0011
0000
82 $a->[0] cmp $b->[0]
83 }
84 @files;
85 }
86  
87 9 ▶sub new {
Subroutine new: called CC=7 SCAR=19.5
Pod documented
88 9 my $class = shift;
89 9 ▶ 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") 9 0 9
@_ ? : 3 6 9
90 or croak "bad database: empty share directory: $DATABASE_DIR";
91 9 my $path = File::Spec->rel2abs($filename, $DATABASE_DIR);
92 9 ▶ -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") 8 1 9
93 8 my $schema =
94 Math::DifferenceSet::Planar::Schema->connect(
95 "dbi:SQLite:$path", q[], q[],
96 { sqlite_open_flags => SQLITE_OPEN_READONLY },
97 );
98 8 my $data = $schema->resultset('DifferenceSet');
99 8 my $count = eval { $data->search->count };
100 8 ▶ croak "bad database: query failed: $@" if !defined $count;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $count 0 8 8
101 8 my $spaces = $schema->resultset('DifferenceSetSpace');
102 8 ▶ undef $spaces if !eval { $spaces->search->count };
Branch: 1 branch
BranchTrueFalseTotal
unless eval { do { $spaces->search->count } } 1 7 8
103 8 my $version = $schema->resultset('DatabaseVersion');
104 8 ▶ undef $version if !eval { $version->search->count };
Branch: 1 branch
BranchTrueFalseTotal
unless eval { do { $version->search->count } } 0 8 8
105 8 return bless [$data, $spaces, $version, $path], $class;
106 }
107  
108 # ----- object methods -----
109  
110 24 ▶sub get {
Subroutine get: called CC=2 SCAR=6.9
Pod documented
111 24 my ($this, $order, @columns) = @_;
112 24 ▶ return $this->_data->search(
Branch: 1 branch
BranchTrueFalseTotal
@columns ? : 5 19 24
113 { order_ => $order },
114 @columns ? { columns => \@columns } : ()
115 )->single;
116 }
117  
118 6 ▶sub get_space {
Subroutine get_space: called CC=2 SCAR=6.9
Pod documented
119 6 my ($this, $order) = @_;
120 6 my $spaces = $this->_spaces;
121 6 ▶ return undef if !defined $spaces;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $spaces 1 5 6
122 5 return $spaces->search({ order_ => $order })->single;
123 }
124  
125 1 ▶sub get_version { $_[0]->_get_version_of('difference_set') }
Subroutine get_version: called CC=1 SCAR=0.0
Pod documented
126 1 ▶sub get_space_version { $_[0]->_get_version_of('difference_set_space') }
Subroutine get_space_version: called CC=1 SCAR=0.0
Pod documented
127  
128 1 ▶sub iterate {
Subroutine iterate: called CC=1 SCAR=0.0
Pod documented
129 1 my ($this, $min, $max) = @_;
130 1 return _iterate($this->_data, undef, $min, $max);
131 }
132  
133 7 ▶sub iterate_properties {
Subroutine iterate_properties: called CC=4 SCAR=13.9
Pod documented
134 7 my ($this, $min, $max, @columns) = @_;
135 7 foreach my $col (@columns) {
136 3 ▶ $col = 'order_' if $col eq 'order';
Branch: 1 branch
BranchTrueFalseTotal
if $col eq "order" 1 2 3
137 }
138 @columns =
139 7 ▶ grep {!/delta/}
Branch: 1 branch
BranchTrueFalseTotal
unless @columns 5 2 7
140 Math::DifferenceSet::Planar::Schema::Result::DifferenceSet->columns
141 if !@columns;
142 7 return _iterate($this->_data, undef, $min, $max, @columns);
143 }
144  
145 0 ▶sub iterate_refs {
Subroutine iterate_refs: not called CC=1 SCAR=6.9
Pod documented
146 0 my ($this, $type, $min, $max) = @_;
147 0 return _iterate($this->_data, [$type => { '<>' => 0 }], $min, $max);
148 }
149  
150 2 ▶sub iterate_spaces {
Subroutine iterate_spaces: called CC=2 SCAR=6.9
Pod documented
151 2 my ($this, $min, $max) = @_;
152 2 my $spaces = $this->_spaces;
153 2 ▶ return sub {} if !defined $spaces;
Subroutine __ANON__: called CC=1 SCAR=0.0
Branch: 1 branch
BranchTrueFalseTotal
unless defined $spaces 1 1 2
154 1 return _iterate($spaces, undef, $min, $max);
155 }
156  
157 3 ▶sub min_order { $_[0]->_data->get_column('order_')->min }
Subroutine min_order: called CC=1 SCAR=0.0
Pod documented
158 12 ▶sub max_order { $_[0]->_data->get_column('order_')->max }
Subroutine max_order: called CC=1 SCAR=0.0
Pod documented
159 3 ▶sub count { $_[0]->_data->search->count }
Subroutine count: called CC=1 SCAR=0.0
Pod documented
160 1 ▶sub path { $_[0]->_path }
Subroutine path: called CC=1 SCAR=0.0
Pod documented
161  
162 2 ▶sub sp_min_order {
Subroutine sp_min_order: called CC=2 SCAR=7.0
Pod documented
163 2 my ($this) = @_;
164 2 my $spaces = $this->_spaces;
165 2 ▶ return $spaces && $spaces->get_column('order_')->min;
Condition66%2/3
$spaces && $spaces->get_column('order_')->min
!ll&&!rl&&r
101
MC/DC50%1/2
$spaces && $spaces->get_column('order_')->min
$spaces $spaces->get_column('order_')->min
Truth table66%2/3
A && B
A= $spacesB= $spaces->get_column('order_')->min
ABresult
0X0
100
111
166 }
167  
168 5 ▶sub sp_max_order {
Subroutine sp_max_order: called CC=2 SCAR=7.0
Pod documented
169 5 my ($this) = @_;
170 5 my $spaces = $this->_spaces;
171 5 ▶ return $spaces && $spaces->get_column('order_')->max;
Condition66%2/3
$spaces && $spaces->get_column('order_')->max
!ll&&!rl&&r
104
MC/DC50%1/2
$spaces && $spaces->get_column('order_')->max
$spaces $spaces->get_column('order_')->max
Truth table66%2/3
A && B
A= $spacesB= $spaces->get_column('order_')->max
ABresult
0X0
100
111
172 }
173  
174 2 ▶sub sp_count {
Subroutine sp_count: called CC=2 SCAR=6.9
Pod documented
175 2 my ($this) = @_;
176 2 my $spaces = $this->_spaces;
177 2 ▶ return 0 if !defined $spaces;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $spaces 1 1 2
178 1 return $spaces->search->count;
179 }
180  
181 0 ▶sub ref_min_order {
Subroutine ref_min_order: not called CC=1 SCAR=6.9
Pod documented
182 0 my ($this, $type) = @_;
183 0 return $this->_data->search({$type => _KNOWN})->get_column('order_')->min;
184 }
185  
186 0 ▶sub ref_max_order {
Subroutine ref_max_order: not called CC=1 SCAR=6.9
Pod documented
187 0 my ($this, $type) = @_;
188 0 return $this->_data->search({$type => _KNOWN})->get_column('order_')->max;
189 }
190  
191 0 ▶sub ref_count {
Subroutine ref_count: not called CC=1 SCAR=6.9
Pod documented
192 0 my ($this, $type) = @_;
193 0 return $this->_data->search({$type => _KNOWN})->count;
194 }
195  
196 7 1;
197  
198 __END__
« Planar.pm ↑ Summary Planar/Schema/Result/DifferenceSet.pm »