AtteanX/Query/Cache/Retriever.pm

filter: Statementstmt 37.3% 25 / 67 Branchbran 0.0% 0 / 22 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 87.5% 7 / 8 Podpod 0.0% 0 / 1 totaltotal 32.6% 32 / 98 CC 12 SCAR 45.9
CC
12
Cov
28%
fetch
156.0
BEGIN
1.0
BEGIN
1.0
CRAP 98.9
« AtteanX/QueryPlanner/Cache/LDF.pm ↑ Summary AtteanX/Query/Cache/Analyzer.pm »
1 package AtteanX::Query::Cache::Retriever;
2  
3 6 ▶use 5.010001;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 6 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 6 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 6 our $AUTHORITY = 'cpan:KJETILK';
8 6 our $VERSION = '0.002';
9  
10 6 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 6 ▶use Carp qw(croak);
Subroutine BEGIN: called CC=1 SCAR=0.0
12 6 ▶use Attean::RDF;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 6 ▶use Types::Standard qw(InstanceOf);
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 6 has model => (is => 'ro',
16 isa => InstanceOf['AtteanX::Model::SPARQLCache'],
17 required => 1);
18  
19 6 with 'MooX::Log::Any';
20  
21  
22 0 ▶sub fetch {
Subroutine fetch: not called CC=12 SCAR=50.5
Pod undocumented
23 0 my ($self, $triple) = @_;
24 0 $triple = $triple->canonicalize;
25 0 my $key = $triple->tuples_string;
26 0 my @vars = $triple->values_consuming_role('Attean::API::Variable');
27 0 my $use_hash = (scalar @vars) - 1;
28 0 ▶ if ($use_hash < 0) {
Branch: 2 branches
BranchTrueFalseTotal
if ($use_hash < 0) { } 0 0 0
elsif ($use_hash > 1) { } 0 0 0
29 0 croak "No variables in triple pattern $key";
30 } elsif ($use_hash > 1) {
31 0 croak "Only triple patterns with one or two variables are supported, got $key";
32 }
33  
34 0 ▶ if ($self->model->isa('AtteanX::Model::SPARQLCache::LDF')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->model->isa('AtteanX::Model::SPARQLCache::LDF')) { } 0 0 0
35 0 my @terms = $triple->values;
36 0 my @termswithvars;
37 0 my %tmp = $triple->mapping;
38 0 ▶ while (my ($pos, $term) = each (%tmp)) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %tmp) 0 0 0
39 0 ▶ if ($term->does('Attean::API::Variable')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($term->does("Attean::API::Variable")) 0 0 0
40 0 push(@termswithvars, $pos);
41 }
42 }
43 0 my $iter = $self->model->ldf_store->get_triples(@terms);
44 0 ▶ if ($use_hash) { # Now, decide if we insert an array or a hash into the cache.
Branch: 1 branch
BranchTrueFalseTotal
if ($use_hash) { } 0 0 0
45 0 @termswithvars = reverse sort @termswithvars; # Will ensure s, p, o order
46 0 my $data;
47 0 ▶ while (my $res = $iter->next) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $res = $iter->next) 0 0 0
48 0 push(@{$data->{$res->value($termswithvars[0])->ntriples_string}}, $res->value($termswithvars[1])->ntriples_string);
49 }
50 0 return $data;
51 } else {
52 0 my @data;
53 0 ▶ while (my $res = $iter->next) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $res = $iter->next) 0 0 0
54 0 push(@data, $res->value($termswithvars[0])->ntriples_string);
55 }
56 0 return \@data;
57 }
58 } else {
59 0 my $sparql = 'SELECT ' . join(' ', map { $_->ntriples_string } @vars) .
60 " WHERE {\n\t" . $triple->as_sparql . '. }';
61 0 $self->log->debug("Running SPARQL query\n$sparql");
62 0 my $iter = $self->model->get_sparql($sparql);
63 0 ▶ if ($use_hash) { # Now, decide if we insert an array or a hash into the cache.
Branch: 1 branch
BranchTrueFalseTotal
if ($use_hash) { } 0 0 0
64 0 my $data;
65 0 ▶ while (my $res = $iter->next) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $res = $iter->next) 0 0 0
66 0 push(@{$data->{$res->value($vars[0]->value)->ntriples_string}}, $res->value($vars[1]->value)->ntriples_string);
67 }
68 0 return $data;
69 } else {
70 0 my @data;
71 0 ▶ while (my $res = $iter->next) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $res = $iter->next) 0 0 0
72 0 my ($value) = $res->values;
73 0 push(@data, $value->ntriples_string);
74 }
75 0 return \@data;
76 }
77 }
78 }
79  
80  
81  
82 6 1;
« AtteanX/QueryPlanner/Cache/LDF.pm ↑ Summary AtteanX/Query/Cache/Analyzer.pm »