CogBase/Connection.pm

filter: Statementstmt 72.7% 32 / 44 Branchbran 41.6% 5 / 12 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 81.8% 9 / 11 Podpod 0.0% 0 / 6 totaltotal 63.0% 46 / 73 CC 9 SCAR 14.6
CC
9
Cov
66%
fetch
12.0
connection
5.7
fetchSchemaNode
2.7
CRAP 4.3
« CogBase/Factory.pm ↑ Summary CogBase/Connection/FileSystem.pm »
1 package CogBase::Connection;
2 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use CogBase::Base -base;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use CogBase::Factory;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use CogBase::Index;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 1 field 'db_location';
9 1 field factory => -init =>
10 'CogBase::Factory->New(connection => $self)';
11 1 field index => -init =>
12 'CogBase::Index->New(connection => $self)';
13  
14 1 ▶sub connection {
Subroutine connection: called CC=5 SCAR=17.5
Pod undocumented
15 1 my ($class, $location) = @_;
16 1 ▶ my $connection_class =
Branch: 2 branches
BranchTrueFalseTotal
$location =~ m[^https?://] ? : 0 1 1
-d $location ? : 1 0 1
17 $location =~ m!^https?://!
18 ? 'CogBase::Connection::HTTP'
19 : -d $location
20 ? 'CogBase::Connection::FileSystem'
21 : die "'$location' is an invalid CogBase location";
22 1 ▶ unless ($connection_class->can('New')) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($connection_class->can("New")) 1 0 1
23 1 ▶ eval "require $connection_class; 1"
Branch: 1 branch
BranchTrueFalseTotal
eval "require $connection_class; 1" or die $@ 1 0 1
24 or die $@;
25 }
26 1 return $connection_class->New(db_location => $location);
27 }
28  
29 2 ▶sub node {
Subroutine node: called CC=1 SCAR=0.0
Pod undocumented
30 2 my ($self, $type) = @_;
31 2 return $self->factory->new_node($type);
32 }
33  
34 0 ▶sub fetch {
Subroutine fetch: not called CC=3 SCAR=24.8
Pod undocumented
35 0 my ($self, @nodes) = @_;
36 0 my @result;
37 0 for my $node (@nodes) {
38 0 ▶ $node = CogBase::Node->New(Id => $node)
Branch: 1 branch
BranchTrueFalseTotal
unless ref $node 0 0 0
39 unless ref $node;
40 0 $self->fetch_node($node);
41 0 push @result, $node;
42 }
43 0 return @result;
44 }
45  
46 1 ▶sub store {
Subroutine store: called CC=2 SCAR=6.9
Pod undocumented
47 1 my ($self, @nodes) = @_;
48 1 for my $node (@nodes) {
49 1 $self->store_node($node);
50 }
51 1 return;
52 }
53  
54 0 ▶sub disconnect {
Subroutine disconnect: not called CC=1 SCAR=6.9
Pod undocumented
55 0 my $self = shift;
56 0 bless $self, ref($self) . '::disconnected';
57 }
58  
59 1 ▶sub fetchSchemaNode {
Subroutine fetchSchemaNode: called CC=2 SCAR=10.1
Pod undocumented
60 1 my ($self, $type) = @_;
61 1 ▶ my ($id) = $self->query("!Schema")
Branch: 1 branch
BranchTrueFalseTotal
my($id) = $self->query("!Schema") or return 0 1 1
62 or return;
63 0 my $node = CogBase::Node->New(
64 Id => $id,
65 Type => 'Schema',
66 );
67 0 $self->fetch($node);
68 0 return $node;
69 }
70  
71 1 1;
« CogBase/Factory.pm ↑ Summary CogBase/Connection/FileSystem.pm »