File Coverage

blib/lib/RDF/Query/Algebra/Offset.pm
Criterion Covered Total %
statement 54 63 85.7
branch 1 2 50.0
condition 1 2 50.0
subroutine 18 22 81.8
pod 12 12 100.0
total 86 101 85.1


line stmt bran cond sub pod time code
1             # RDF::Query::Algebra::Offset
2             # -----------------------------------------------------------------------------
3              
4             =head1 NAME
5              
6             RDF::Query::Algebra::Offset - Algebra class for offseting query results
7              
8             =head1 VERSION
9              
10             This document describes RDF::Query::Algebra::Offset version 2.915_01.
11              
12             =cut
13              
14             package RDF::Query::Algebra::Offset;
15              
16 36     36   182 use strict;
  36         72  
  36         904  
17 36     36   182 use warnings;
  36         65  
  36         941  
18 36     36   175 no warnings 'redefine';
  36         67  
  36         1198  
19 36     36   177 use base qw(RDF::Query::Algebra);
  36         69  
  36         2539  
20              
21 36     36   220 use Data::Dumper;
  36         72  
  36         1664  
22 36     36   177 use Set::Scalar;
  36         77  
  36         1337  
23 36     36   176 use Scalar::Util qw(blessed);
  36         69  
  36         1747  
24 36     36   181 use Carp qw(carp croak confess);
  36         66  
  36         1977  
25 36     36   198 use RDF::Trine::Iterator qw(sgrep);
  36         64  
  36         2356  
26              
27             ######################################################################
28              
29             our ($VERSION);
30             BEGIN {
31 36     36   18152 $VERSION = '2.915_01';
32             }
33              
34             ######################################################################
35              
36             =head1 METHODS
37              
38             Beyond the methods documented below, this class inherits methods from the
39             L<RDF::Query::Algebra> class.
40              
41             =over 4
42              
43             =cut
44              
45             =item C<< new ( $pattern, $offset ) >>
46              
47             Returns a new Sort structure.
48              
49             =cut
50              
51             sub new {
52 4     4 1 9 my $class = shift;
53 4         10 my $pattern = shift;
54 4         8 my $offset = shift;
55 4         16 return bless( [ $pattern, $offset ], $class );
56             }
57              
58             =item C<< construct_args >>
59              
60             Returns a list of arguments that, passed to this class' constructor,
61             will produce a clone of this algebra pattern.
62              
63             =cut
64              
65             sub construct_args {
66 4     4 1 7 my $self = shift;
67 4         11 my $pattern = $self->pattern;
68 4         13 my $offset = $self->offset;
69 4         16 return ($pattern, $offset);
70             }
71              
72             =item C<< pattern >>
73              
74             Returns the pattern to be sorted.
75              
76             =cut
77              
78             sub pattern {
79 13     13 1 21 my $self = shift;
80 13 50       32 if (@_) {
81 0         0 $self->[0] = shift;
82             }
83 13         56 return $self->[0];
84             }
85              
86             =item C<< offset >>
87              
88             Returns the offset number of the pattern.
89              
90             =cut
91              
92             sub offset {
93 12     12 1 19 my $self = shift;
94 12         53 return $self->[1];
95             }
96              
97             =item C<< sse >>
98              
99             Returns the SSE string for this algebra expression.
100              
101             =cut
102              
103             sub sse {
104 3     3 1 7 my $self = shift;
105 3         22 my $context = shift;
106 3   50     15 my $prefix = shift || '';
107 3         7 my $indent = $context->{indent};
108            
109 3         15 return sprintf(
110             "(offset %s\n${prefix}${indent}%s)",
111             $self->offset,
112             $self->pattern->sse( $context, "${prefix}${indent}" ),
113             );
114             }
115              
116             =item C<< as_sparql >>
117              
118             Returns the SPARQL string for this algebra expression.
119              
120             =cut
121              
122             sub as_sparql {
123 1     1 1 2 my $self = shift;
124 1         2 my $context = shift;
125 1         2 my $indent = shift;
126            
127 1         8 my $string = sprintf(
128             "%s\nOFFSET %d",
129             $self->pattern->as_sparql( $context, $indent ),
130             $self->offset,
131             );
132 1         6 return $string;
133             }
134              
135             =item C<< as_hash >>
136              
137             Returns the query as a nested set of plain data structures (no objects).
138              
139             =cut
140              
141             sub as_hash {
142 0     0 1 0 my $self = shift;
143 0         0 my $context = shift;
144             return {
145 0         0 type => lc($self->type),
146             pattern => $self->pattern->as_hash,
147             offset => $self->offset,
148             };
149             }
150              
151             =item C<< type >>
152              
153             Returns the type of this algebra expression.
154              
155             =cut
156              
157             sub type {
158 0     0 1 0 return 'LIMIT';
159             }
160              
161             =item C<< referenced_variables >>
162              
163             Returns a list of the variable names used in this algebra expression.
164              
165             =cut
166              
167             sub referenced_variables {
168 1     1 1 2 my $self = shift;
169 1         5 return RDF::Query::_uniq($self->pattern->referenced_variables);
170             }
171              
172             =item C<< potentially_bound >>
173              
174             Returns a list of the variable names used in this algebra expression that will
175             bind values during execution.
176              
177             =cut
178              
179             sub potentially_bound {
180 0     0 1 0 my $self = shift;
181 0         0 return $self->pattern->potentially_bound;
182             }
183              
184             =item C<< definite_variables >>
185              
186             Returns a list of the variable names that will be bound after evaluating this algebra expression.
187              
188             =cut
189              
190             sub definite_variables {
191 0     0 1 0 my $self = shift;
192 0         0 return $self->pattern->definite_variables;
193             }
194              
195             =item C<< is_solution_modifier >>
196              
197             Returns true if this node is a solution modifier.
198              
199             =cut
200              
201             sub is_solution_modifier {
202 3     3 1 14 return 1;
203             }
204              
205              
206              
207             1;
208              
209             __END__
210              
211             =back
212              
213             =head1 AUTHOR
214              
215             Gregory Todd Williams <gwilliams@cpan.org>
216              
217             =cut