DiaColloDB/Client/file.pm

filter: Statementstmt 23.9% 11 / 46 Branchbran 0.0% 0 / 26 Conditioncond 0.0% 0 / 16 MC/DCmcdc 0.0% 0 / 9 Subroutinesub 30.0% 3 / 10 Podpod 100% 7 / 7 totaltotal 18.4% 21 / 114 CC 20 SCAR 35.5
CC
20
Cov
12%
open_file
90.0
opened
12.0
dbinfo
12.0
CRAP 34.7
« DiaColloDB/Upgrade/v0_09_multimap.pm ↑ Summary DiaColloDB/Client/http.pm »
1 ## -*- Mode: CPerl -*-
2 ## File: DiaColloDB::Client::file.pm
3 ## Author: Bryan Jurish <moocow@cpan.org>
4 ## Description: collocation db: client: local dbdir
5  
6 package DiaColloDB::Client::file;
7 2 ▶use DiaColloDB::Client;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 2 ▶use URI;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 ##==============================================================================
12 ## Globals & Constants
13  
14 2 our @ISA = qw(DiaColloDB::Client);
15  
16 ##==============================================================================
17 ## Constructors etc.
18  
19 ## $cli = CLASS_OR_OBJECT->new(%args)
20 ## $cli = CLASS_OR_OBJECT->new($url, %args)
21 ## + %args, object structure:
22 ## (
23 ## ##-- DiaColloDB::Client: options
24 ## url => $url, ##-- local url; query form is used as db parameters ##-- CONTINUE HERE: adjust dstar web params to auto-set ddcServer!
25 ## ##
26 ## ##-- DiaColloDB::Client::file
27 ## db => $db, ##-- underlying DiaColloDB object
28 ## )
29  
30 ##==============================================================================
31 ## I/O: open/close
32  
33 ## $cli_or_undef = $cli->open_file($file_url,%opts)
34 ## $cli_or_undef = $cli->open_file()
35 ## + opens a local file url
36 ## + may re-bless() $cli into an appropriate package
37 ## + OVERRIDE in subclasses supporting file urls
38 0 ▶sub open_file {
Subroutine open_file: not called CC=9 SCAR=45.0
Pod documented
39 0 my ($cli,$url,%opts) = @_;
40 0 ▶ $cli = $cli->new() if (!ref($cli));
Branch: 1 branch
BranchTrueFalseTotal
unless ref $cli 0 0 0
41 0 ▶ $cli->close() if ($cli->opened);
Branch: 1 branch
BranchTrueFalseTotal
if $cli->opened 0 0 0
42 0 ▶ $cli->{url} = $url = ($url // $cli->{url});
Condition0%0/3
$url // $cli->{"url"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$url // $cli->{"url"}
$url $cli->{"url"}
Truth table0%0/3
A // B
A= $urlB= $cli->{"url"}
ABresult
1X1
011
000
43 0 my $uri = URI->new($url);
44 0 ▶ my $path = ($uri->authority//'') . ($uri->path//'');
Condition0%0/4
$uri->authority // ""
l!l
00
$uri->path // ""
l!l
00
MC/DC0%0/1
$uri->authority // ""
$uri->authority
MC/DC0%0/1
$uri->path // ""
$uri->path
Truth table0%0/2
A
A= $uri->authority
Aresult
11
00
Truth table0%0/2
A
A= $uri->path
Aresult
11
00
45 0 my %dbopts = ($cli->dbOptions, $uri->query_form());
46  
47 ##-- check whether the path looks like an rc-file; if so, try to open it as one
48 0 ▶ return $cli->open_rcfile($cli->{url},%opts)
Branch: 1 branch
BranchTrueFalseTotal
unless -d $path or -e "$path/header.json" 0 0 0
Condition0%0/3
-d $path or -e "$path/header.json"
l!l&&r!l&&!r
000
MC/DC0%0/2
-d $path or -e "$path/header.json"
-d $path -e "$path/header.json"
Truth table0%0/3
A or B
A= -d $pathB= -e "$path/header.json"
ABresult
1X1
011
000
49 if (!-d $path && !-e "$path/header.json");
50  
51 0 ▶ $cli->{db} = DiaColloDB->new(%dbopts,dbdir=>$path)
Branch: 1 branch
BranchTrueFalseTotal
$cli->{"db"} = "DiaColloDB"->new(%dbopts, "dbdir", $path) or $cli->logconfess("open_file() failed to open DB directory ${path}: $!") 0 0 0
52 or $cli->logconfess("open_file() failed to open DB directory $path: $!");
53 0 return $cli;
54 }
55  
56 ## $cli_or_undef = $cli->close()
57 ## + default just returns $cli
58 0 ▶sub close {
Subroutine close: not called CC=2 SCAR=17.9
Pod documented
59 0 my $cli = shift;
60 0 ▶ $cli->{db}->close() if ($cli->{db});
Branch: 1 branch
BranchTrueFalseTotal
if $cli->{"db"} 0 0 0
61 0 delete @$cli{qw(db)};
62 0 return $cli;
63 }
64  
65 ## $bool = $cli->opened()
66 ## + default just checks for $cli->{url}
67 0 ▶sub opened {
Subroutine opened: not called CC=3 SCAR=24.8
Pod documented
68 0 ▶ return ref($_[0]) && $_[0]{db} && $_[0]{db}->opened();
Condition0%0/6
ref $_[0] && $_[0]{'db'} && $_[0]{'db'}->opened
!ll&&!rl&&r
000
ref $_[0] and $_[0]{"db"}
!ll&&!rl&&r
000
MC/DC0%0/3
ref $_[0] && $_[0]{'db'} && $_[0]{'db'}->opened
ref $_[0] $_[0]{"db"} $_[0]{'db'}->opened
Truth table0%0/4
A and B && C
A= ref $_[0]B= $_[0]{"db"}C= $_[0]{'db'}->opened
ABCresult
0XX0
10X0
1100
1111
69 }
70  
71 ##==============================================================================
72 ## db-info
73  
74 ## \%info = $cli->dbinfo()
75 0 ▶sub dbinfo {
Subroutine dbinfo: not called CC=3 SCAR=24.8
Pod documented
76 0 my $cli = shift;
77 0 ▶ $cli->logconfess($cli->{error}="profile(): no db opened!") if (!$cli->opened);
Branch: 1 branch
BranchTrueFalseTotal
unless $cli->opened 0 0 0
78 0 delete $cli->{error};
79 0 ▶ $cli->{error} = $cli->{db}{error} if (!defined(my $info = $cli->{db}->dbinfo(@_)));
Branch: 1 branch
BranchTrueFalseTotal
unless defined(my $info = $cli->{"db"}->dbinfo(@_)) 0 0 0
80 0 return $info;
81 }
82  
83 ##==============================================================================
84 ## Profiling
85  
86 ##--------------------------------------------------------------
87 ## Profiling: Generic
88  
89 ## $mprf = $cli->profile($relation, %opts)
90 ## + get a relation profile for selected items as a DiaColloDB::Profile::Multi object
91 ## + %opts: as for DiaColloDB::profile()
92 0 ▶sub profile {
Subroutine profile: not called CC=3 SCAR=24.8
Pod documented
93 0 my $cli = shift;
94 0 ▶ $cli->logconfess($cli->{error}="profile(): no db opened!") if (!$cli->opened);
Branch: 1 branch
BranchTrueFalseTotal
unless $cli->opened 0 0 0
95 0 delete $cli->{error};
96 0 ▶ $cli->{error} = $cli->{db}{error} if (!defined(my $mp = $cli->{db}->profile(@_)));
Branch: 1 branch
BranchTrueFalseTotal
unless defined(my $mp = $cli->{"db"}->profile(@_)) 0 0 0
97 0 return $mp;
98 }
99  
100 ##--------------------------------------------------------------
101 ## Profiling: extend (pass-2 for multi-clients)
102  
103 ## $mprf = $cli->extend($relation, %opts)
104 ## + get an extension-profile for selected items as a DiaColloDB::Profile::Multi object
105 ## + %opts: as for DiaColloDB::extend()
106 ## + sets $cli->{error} on error
107 0 ▶sub extend {
Subroutine extend: not called CC=3 SCAR=24.8
Pod documented
108 0 my $cli = shift;
109 0 ▶ $cli->logconfess($cli->{error}="extend(): no db opened!") if (!$cli->opened);
Branch: 1 branch
BranchTrueFalseTotal
unless $cli->opened 0 0 0
110 0 delete $cli->{error};
111 0 ▶ $cli->{error} = $cli->{db}{error} if (!defined(my $mp = $cli->{db}->extend(@_)));
Branch: 1 branch
BranchTrueFalseTotal
unless defined(my $mp = $cli->{"db"}->extend(@_)) 0 0 0
112 0 return $mp;
113 }
114  
115  
116 ##--------------------------------------------------------------
117 ## Profiling: Comparison (diff)
118  
119 ## $mprf = $cli->compare($relation, %opts)
120 ## + get a relation comparison profile for selected items as a DiaColloDB::Profile::MultiDiff object
121 ## + %opts: as for DiaColloDB::compare()
122 0 ▶sub compare {
Subroutine compare: not called CC=3 SCAR=24.8
Pod documented
123 0 my $cli = shift;
124 0 ▶ $cli->logconfess($cli->{error}="compare(): no db opened!") if (!$cli->opened);
Branch: 1 branch
BranchTrueFalseTotal
unless $cli->opened 0 0 0
125 0 delete $cli->{error};
126 0 ▶ $cli->{error} = $cli->{db}{error} if (!defined(my $mp = $cli->{db}->compare(@_)));
Branch: 1 branch
BranchTrueFalseTotal
unless defined(my $mp = $cli->{"db"}->compare(@_)) 0 0 0
127 0 return $mp;
128 }
129  
130 ##==============================================================================
131 ## Footer
132 2 1;
133  
134 __END__
« DiaColloDB/Upgrade/v0_09_multimap.pm ↑ Summary DiaColloDB/Client/http.pm »