Store.pm

filter: Statementstmt 78.0% 39 / 50 Branchbran 65.3% 17 / 26 Conditioncond 33.3% 2 / 6 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 57.1% 8 / 14 Podpod 100% 8 / 8 totaltotal 68.5% 74 / 108 CC 17 SCAR 20.4
CC
17
Cov
71%
readconfigfile
13.9
new
7.0
access
6.0
CRAP 7.7
« Record.pm ↑ Summary Field.pm »
1 package PICA::Store;
2 {
3 4 $PICA::Store::VERSION = '0.585';
4 }
5 #ABSTRACT: CRUD interface to a L<PICA::Record> storage
6 4 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 4 ▶use Config::Simple;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 4 ▶use PICA::SOAPClient;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 4 ▶use PICA::SQLiteStore;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 4 ▶use Carp qw(croak);
Subroutine BEGIN: called CC=1 SCAR=0.0
12 4 ▶use Cwd qw(cwd abs_path);
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14  
15  
16 1 ▶sub new {
Subroutine new: called CC=5 SCAR=19.4
Pod documented
17 1 my ($class, %params) = (@_);
18  
19 readconfigfile( \%params, $ENV{PICASTORE} )
20 1 ▶ if exists $params{config} or exists $params{conf} ;
Branch: 1 branch
BranchTrueFalseTotal
if exists $params{"config"} or exists $params{"conf"} 1 0 1
Condition33%1/3
exists $params{"config"} or exists $params{"conf"}
l!l&&r!l&&!r
010
MC/DC0%0/2
exists $params{"config"} or exists $params{"conf"}
exists $params{"config"} exists $params{"conf"}
Truth table33%1/3
A or B
A= exists $params{"config"}B= exists $params{"conf"}
ABresult
1X1
011
000
21  
22 1 ▶ return PICA::SOAPClient->new( %params ) if defined $params{webcat};
Branch: 1 branch
BranchTrueFalseTotal
if defined $params{"webcat"} 0 1 1
23 1 ▶ return PICA::SQLiteStore->new( %params ) if defined $params{SQLite};
Branch: 1 branch
BranchTrueFalseTotal
if defined $params{"SQLite"} 1 0 1
24  
25 0 croak('please specify a store type (webcat/SQLite) - possibly in a config file');
26 }
27  
28  
29 0 ▶sub get {
Subroutine get: not called CC=1 SCAR=6.9
Pod documented
30 0 croak('abstract method "get" is not implemented');
31 }
32  
33  
34 0 ▶sub create {
Subroutine create: not called CC=1 SCAR=6.9
Pod documented
35 0 croak('abstract method "create" is not implemented');
36 }
37  
38  
39 0 ▶sub update {
Subroutine update: not called CC=1 SCAR=6.9
Pod documented
40 0 croak('abstract method "update" is not implemented');
41 }
42  
43  
44 0 ▶sub delete {
Subroutine delete: not called CC=1 SCAR=6.9
Pod documented
45 0 croak('abstract method "delete" is not implemented');
46 }
47  
48  
49 0 ▶sub access {
Subroutine access: not called CC=2 SCAR=17.9
Pod documented
50 0 my ($self, %params) = @_;
51  
52 0 for my $key (qw(userkey password dbsid language)) {
53 # do nothing
54 }
55  
56 0 return $self;
57 }
58  
59  
60 0 ▶sub about {
Subroutine about: not called CC=1 SCAR=6.9
Pod documented
61 0 my $self = shift;
62 0 return ref($self);
63 }
64  
65  
66 2 ▶sub readconfigfile {
Subroutine readconfigfile: called CC=12 SCAR=26.3
Pod documented
67 2 my ($params, $defaultfile) = @_;
68  
69 2 ▶ return unless exists $params->{conf} or exists $params->{config};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $params->{"conf"} or exists $params->{"config"} 0 2 2
Condition33%1/3
exists $params->{"conf"} or exists $params->{"config"}
l!l&&r!l&&!r
200
MC/DC0%0/2
exists $params->{"conf"} or exists $params->{"config"}
exists $params->{"conf"} exists $params->{"config"}
Truth table33%1/3
A or B
A= exists $params->{"conf"}B= exists $params->{"config"}
ABresult
1X1
011
000
70  
71 2 ▶ $params->{config} = $params->{conf} unless defined $params->{config};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $params->{"config"} 1 1 2
72  
73 2 ▶ if ( not defined $params->{config} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $params->{"config"}) 1 1 2
74 1 ▶ if ( $defaultfile ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($defaultfile) { } 0 1 1
elsif (-e cwd() . '/pica.conf') { } 1 0 1
75 0 $params->{config} = $defaultfile;
76 } elsif (-e cwd.'/pica.conf' ) {
77 1 $params->{config} = cwd.'/pica.conf' ;
78 }
79 }
80  
81 2 my $cfile = $params->{config};
82 2 ▶ return unless defined $cfile;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $cfile 0 2 2
83  
84 2 my %config;
85  
86 2 ▶ croak("config file not found: $cfile") unless -e $cfile;
Branch: 1 branch
BranchTrueFalseTotal
unless -e $cfile 0 2 2
87 2 ▶ Config::Simple->import_from( $cfile, \%config)
Branch: 1 branch
BranchTrueFalseTotal
"Config::Simple"->import_from($cfile, \%config) or croak("Failed to parse config file $cfile") 2 0 2
88 or croak( "Failed to parse config file $cfile" );
89  
90 2 ▶ while (my ($key, $value) = each %config) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %config) 2 2 4
91 2 $key =~ s/default.//; # remove default namespace
92 # TODO: add support of blocks/namespaces in config file
93 2 ▶ $params->{$key} = $value unless exists $params->{$key};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $params->{$key} 1 1 2
94 }
95 };
96  
97 4 1;
98  
99 __END__
« Record.pm ↑ Summary Field.pm »