File Coverage

blib/lib/AtteanX/Query/AccessPlan/PrefetchLDF.pm
Criterion Covered Total %
statement 23 23 100.0
branch n/a
condition n/a
subroutine 8 8 100.0
pod n/a
total 31 31 100.0


line stmt bran cond sub pod time code
1 9     9   118 use 5.010001;
  9         21  
2 9     9   24 use strict;
  9         13  
  9         146  
3 9     9   30 use warnings;
  9         6  
  9         317  
4              
5              
6             package AtteanX::Query::AccessPlan::PrefetchLDF;
7 9     9   33 use Class::Method::Modifiers;
  9         9  
  9         559  
8              
9             our $AUTHORITY = 'cpan:KJETILK';
10             our $VERSION = '0.002';
11              
12 9     9   29 use Moo::Role;
  9         15  
  9         83  
13 9     9   2002 use Carp;
  9         12  
  9         377  
14 9     9   4516 use RDF::LDF;
  9         13321946  
  9         442  
15 9     9   3681 use AtteanX::Plan::LDF::Triple::EnterCache;
  9         18  
  9         1366  
16              
17              
18             around 'access_plans' => sub {
19             my $orig = shift;
20             my @params = @_;
21             my $self = shift;
22             my $model = shift;
23             my $active_graphs = shift;
24             my $pattern = shift;
25              
26             my $max_triples = $ENV{'LDF_MAX_TRIPLES'} || 100000;
27              
28             # First, add any plans coming from the original planner (which will
29             # include queries to the remote SPARQL endpoint
30             my @plans = $orig->(@params);
31              
32             # Add my plans
33             # Cache only below a limit for how many LDF triples we will fetch.
34             if ($model->has_publisher && $model->ldf_store->count_triples_estimate($pattern->values) <= $max_triples) {
35             push(@plans, AtteanX::Plan::LDF::Triple::EnterCache->new(subject => $pattern->subject,
36             predicate => $pattern->predicate,
37             object => $pattern->object,
38             distinct => 0));
39             } else {
40             push(@plans, AtteanX::Plan::LDF::Triple->new(subject => $pattern->subject,
41             predicate => $pattern->predicate,
42             object => $pattern->object,
43             distinct => 0));
44             }
45              
46             return @plans;
47             };
48              
49             1;
50              
51             __END__
52              
53             =pod
54              
55             =head1 NAME
56              
57             AtteanX::Query::AccessPlan::LDF - An access plan for Linked Data Fragments
58              
59             =head1 DESCRIPTION
60              
61             This provides the implementation of a L<Moo::Role> that serves to wrap
62             any C<access_plan> in query planning. An access plan introduces a plan
63             object for a triple or quad pattern, in this case a
64             L<AtteanX::Plan::LDF::Triple> object.
65              
66             =head1 AUTHOR
67              
68             Kjetil Kjernsmo E<lt>kjetilk@cpan.orgE<gt>.
69              
70             =head1 COPYRIGHT AND LICENCE
71              
72             This software is copyright (c) 2016 by Kjetil Kjernsmo
73              
74             This is free software; you can redistribute it and/or modify it under
75             the same terms as the Perl 5 programming language system itself.
76