File Coverage

blib/lib/RDF/Query/Algebra/Limit.pm
Criterion Covered Total %
statement 60 67 89.5
branch 3 4 75.0
condition 2 4 50.0
subroutine 19 22 86.3
pod 12 12 100.0
total 96 109 88.0


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