| 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
Condition100%6/6
defined $min and defined $max and $min > $max
defined $min and defined $max
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
| |||||||||||||||||||||||||||||||||||||||||||
| 31 | 3 | ($min, $max, $dir) = ($max, $min, 'DESC'); | |||||||||||||||||||||||||||||||||||||||||
| 32 | } | ||||||||||||||||||||||||||||||||||||||||||
| 33 | 16 | ▶ | push @sel, '>=' => $min if defined $min; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 34 | 16 | ▶ | push @sel, '<=' => $max if defined $max; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 35 | 16 | ▶ | my $results = $domain->search( | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 55 | my @files = | ||||||||||||||||||||||||||||||||||||||||||
| 56 | map { | ||||||||||||||||||||||||||||||||||||||||||
| 57 | 11 | ▶ | my $is_standard = /^pds[_\W]/i? 1: 0; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 58 | 11 | my $path = File::Spec->rel2abs($_, $DATABASE_DIR); | |||||||||||||||||||||||||||||||||||||||||
| 59 | 11 | ▶ | (-f $path)? [$_, $is_standard, -s _]: () | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 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
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]
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]
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 86 | 8 | my $spaces = $schema->resultset('DifferenceSetSpace'); | |||||||||||||||||||||||||||||||||||||||||
| 87 | 8 | ▶ | undef $spaces if !eval { $spaces->search->count }; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 149 | 2 | return $spaces->search->count; | |||||||||||||||||||||||||||||||||||||||||
| 150 | } | ||||||||||||||||||||||||||||||||||||||||||
| 151 | |||||||||||||||||||||||||||||||||||||||||||
| 152 | 6 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 153 | |||||||||||||||||||||||||||||||||||||||||||
| 154 | __END__ | ||||||||||||||||||||||||||||||||||||||||||