blib/lib/DataTables.pm

filter: Statementstmt 64.9% 137 / 211 Branchbran 39.4% 30 / 76 Conditioncond 32.2% 10 / 31 MC/DCmcdc 0.0% 0 / 18 Subroutinesub 84.6% 22 / 26 Podpod 90.9% 10 / 11 totaltotal 56.0% 209 / 373 CC 52 SCAR 28.5
CC
52
Cov
56%
_columns_arr
47.8
_generate_where_clause
36.7
_add_where_clause
20.0
CRAP 17.3
↑ Summary
1 package DataTables;
2
3 2 ▶use 5.008008;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6
7 2 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 2 ▶use CGI::Simple;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 2 ▶use DBI;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 2 ▶use JSON::XS;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 2 ▶use SQL::Abstract::Limit;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 2 ▶use JQuery::DataTables::Request;
Subroutine BEGIN: called CC=1 SCAR=0.0
13
14 2 our $VERSION = '0.08';
15
16 # Preloaded methods go here.
17
18 1 ▶sub new {
Subroutine new: called CC=2 SCAR=7.4
Pod documented
19 1 my $invocant = shift;
20 1 ▶ my $class = ref($invocant) || $invocant;
Condition33%1/3
ref $invocant || $invocant
l!l&&r!l&&!r
010
MC/DC0%0/2
ref $invocant || $invocant
ref $invocant $invocant
Truth table33%1/3
A || B
A= ref $invocantB= $invocant
ABresult
1X1
011
000
21 1 my $self = {
22 tables => undef,
23 columns => undef,
24 dbh => undef,
25 query => CGI::Simple->new,
26 data_output_format => 'column-id', # or: key-value
27 patterns => {},
28 join_clause => '',
29 where_clause => '',
30 @_, # Override previous attributes
31 };
32 1 return bless $self, $class;
33 }
34
35
36
37
38 6 ▶sub tables {
Subroutine tables: called CC=3 SCAR=11.0
Pod documented
39 6 my $self = shift;
40
41 6 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 1 5 6
42 1 my $a_ref = shift;
43 1 ▶ croak "tables must be an array ref" unless UNIVERSAL::isa($a_ref,'ARRAY');
Branch: 1 branch
BranchTrueFalseTotal
unless UNIVERSAL::isa($a_ref, "ARRAY") 0 1 1
44 1 $self->{tables} = $a_ref;
45 }
46 6 return $self->{tables};
47 }
48
49
50
51
52 10 ▶sub columns {
Subroutine columns: called CC=4 SCAR=14.3
Pod documented
53 10 my $self = shift;
54
55 10 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 1 9 10
56 1 my $ref = shift;
57 1 ▶ croak "columns_a must be an array or hash ref" unless UNIVERSAL::isa($ref,'ARRAY') or UNIVERSAL::isa($ref,'HASH');
Branch: 1 branch
BranchTrueFalseTotal
unless UNIVERSAL::isa($ref, "ARRAY") or UNIVERSAL::isa($ref, "HASH") 0 1 1
Condition33%1/3
UNIVERSAL::isa($ref, "ARRAY") or UNIVERSAL::isa($ref, "HASH")
l!l&&r!l&&!r
100
MC/DC0%0/2
UNIVERSAL::isa($ref, "ARRAY") or UNIVERSAL::isa($ref, "HASH")
UNIVERSAL::isa($ref, "ARRAY") UNIVERSAL::isa($ref, "HASH")
Truth table33%1/3
A or B
A= UNIVERSAL::isa($ref, "ARRAY")B= UNIVERSAL::isa($ref, "HASH")
ABresult
1X1
011
000
58 1 $self->{columns} = $ref;
59 }
60 10 return $self->{columns};
61 }
62
63
64
65
66 0 ▶sub dbh {
Subroutine dbh: not called CC=3 SCAR=24.8
Pod documented
67 0 my $self = shift;
68
69 0 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 0 0
70 0 my $ref = shift;
71 0 ▶ croak "dbh must be a DBI object" unless UNIVERSAL::can($ref,'prepare');
Branch: 1 branch
BranchTrueFalseTotal
unless UNIVERSAL::can($ref, "prepare") 0 0 0
72 0 $self->{dbh} = $ref;
73 }
74 0 return $self->{dbh};
75 }
76
77
78
79
80 3 ▶sub data_output_format {
Subroutine data_output_format: called CC=4 SCAR=21.1
Pod documented
81 3 my $self = shift;
82 3 my $new_val = shift;
83
84 3 ▶ if ($new_val) {
Branch: 1 branch
BranchTrueFalseTotal
if ($new_val) 0 3 3
85 0 ▶ if( $new_val ne 'column-id' and $new_val ne 'key-value' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($new_val ne 'column-id' and $new_val ne 'key-value') { } 0 0 0
Condition0%0/3
$new_val ne "column-id" and $new_val ne "key-value"
!ll&&!rl&&r
000
MC/DC0%0/2
$new_val ne "column-id" and $new_val ne "key-value"
$new_val ne "column-id" $new_val ne "key-value"
Truth table0%0/3
A and B
A= $new_val ne "column-id"B= $new_val ne "key-value"
ABresult
0X0
100
111
86 0 croak "data_output_format must be one of: column-id, key-value; you sent: $new_val";
87 }else{
88 0 $self->{data_output_format} = $new_val;
89 }
90 }
91 3 return $self->{data_output_format};
92 }
93
94
95
96
97 1 ▶sub patterns {
Subroutine patterns: called CC=3 SCAR=16.0
Pod documented
98 1 my $self = shift;
99
100 1 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 1 1
101 0 my $h_ref = shift;
102 0 ▶ croak "patterns must be a hash ref" unless UNIVERSAL::isa($h_ref,'HASH');
Branch: 1 branch
BranchTrueFalseTotal
unless UNIVERSAL::isa($h_ref, "HASH") 0 0 0
103 0 $self->{patterns} = $h_ref;
104 }
105 1 return $self->{patterns};
106 }
107
108
109
110
111 1 ▶sub join_clause {
Subroutine join_clause: called CC=2 SCAR=7.6
Pod documented
112 1 my $self = shift;
113
114 1 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 1 1
115 0 $self->{join_clause} = shift;
116 }
117 1 return $self->{join_clause};
118 }
119
120
121
122
123 1 ▶sub where_clause {
Subroutine where_clause: called CC=2 SCAR=7.6
Pod documented
124 1 my $self = shift;
125
126 1 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 1 1
127 0 $self->{where_clause} = shift;
128 }
129 1 return $self->{where_clause};
130 }
131
132
133
134
135 3 ▶sub _columns_arr {
Subroutine _columns_arr: called CC=9 SCAR=38.7
136 3 my $self = shift;
137 3 my $aColumns;
138 my $regular_columns;
139 3 my $as_hash;
140 3 my $tables_hash;
141
142 3 ▶ if(UNIVERSAL::isa($self->columns,'HASH')) {
Branch: 2 branches
BranchTrueFalseTotal
if (UNIVERSAL::isa($self->columns, 'HASH')) { } 0 3 3
elsif (UNIVERSAL::isa($self->columns, 'ARRAY')) { } 3 0 3
143 0 my $columns = $self->columns;
144
145 0 for my $key (sort {$a <=> $b} keys %{$columns}) { #here we sort by key so columns show in the same order as they on the page
146 0 my $as_exists = undef;
147
148 #if two keys, we assume user passed in AS as a key. We could check for as below in loop, but that limits users from having a column named AS
149 0 ▶ if(scalar(keys %{$columns->{$key}} == 2) and exists $columns->{$key}->{'AS'}) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar(keys %{$$columns{$key};} == 2) and exists $columns->{$key}{"AS"}) 0 0 0
Condition0%0/3
scalar(keys %{$$columns{$key};} == 2) and exists $columns->{$key}{"AS"}
!ll&&!rl&&r
000
MC/DC0%0/2
scalar(keys %{$$columns{$key};} == 2) and exists $columns->{$key}{"AS"}
scalar(keys %{$$columns{$key};} == 2) exists $columns->{$key}{"AS"}
Truth table0%0/3
A and B
A= scalar(keys %{$$columns{$key};} == 2)B= exists $columns->{$key}{"AS"}
ABresult
0X0
100
111
150 0 $as_exists = $columns->{$key}->{'AS'};
151 0 delete $columns->{$key}->{'AS'};
152 }
153
154 0 ▶ while(my ($column,$table) = each %{$columns->{$key}}) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %{$$columns{$key};}) 0 0 0
155 0 my $column_name = "$table.$column";
156 0 push @{$aColumns}, $column_name;
157
158 0 ▶ if($as_exists) {
Branch: 1 branch
BranchTrueFalseTotal
if ($as_exists) 0 0 0
159 0 ▶ $as_hash->{$column_name} = $as_exists if $as_exists; #add 'AS' value for this column if one exists
Branch: 1 branch
BranchTrueFalseTotal
if $as_exists 0 0 0
160 0 $column = $as_exists; # we want to change the column name to what it will be selected as out of database so we can do correct pattern matching
161 }
162
163 0 $tables_hash->{$table} = 1;
164 0 push @{$regular_columns}, $column;
165 }
166 }
167
168 0 my @tables = keys %$tables_hash;
169 0 $self->tables(\@tables);
170 }
171 elsif(UNIVERSAL::isa($self->columns,'ARRAY')) {
172 3 $aColumns = $self->columns;
173 3 $regular_columns = $aColumns;
174 }
175 else {
176 0 croak "columns must be a hash or an array ref";
177 }
178
179 3 return ($aColumns,$regular_columns,$as_hash);
180 }
181
182
183
184
185 0 ▶sub print_json {
Subroutine print_json: not called CC=1 SCAR=6.9
Pod documented
186 0 my $self = shift;
187 0 my $json = $self->json;
188
189 0 print "Content-type: application/json\n\n";
190 0 print $json;
191 }
192
193
194
195
196 1 ▶sub table_data {
Subroutine table_data: called CC=14 SCAR=28.3
Pod undocumented
197 1 my $self = shift;
198
199 1 my %all_query_parameters = $self->_get_query_parameters();
200
201 # may croak if client_params isn't recognized as containing DataTables parameters
202 1 my $dt_req = $self->_create_datatables_request( \%all_query_parameters );
203
204 # DB HANDLE
205 1 my $dbh = $self->{dbh};
206 1 ▶ croak "Database handle not defined" unless defined $dbh;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $dbh 0 1 1
207
208 #columns to use
209 1 my ($aColumns,$regular_columns,undef) = $self->_columns_arr;
210
211 # check table name(s)
212 1 ▶ croak "Tables must be provided for the FROM clause" unless $self->tables;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->tables 0 1 1
213
214 #filtering
215 1 my $where_href = $self->_generate_where_clause($dt_req);
216
217 #ordering
218 1 my @order = $self->_generate_order_clause($dt_req);
219
220 #paging
221 1 ▶ my $limit = $dt_req->length || 10;
Condition50%1/2
$dt_req->length || 10
l!l
10
MC/DC0%0/1
$dt_req->length || 10
$dt_req->length
Truth table50%1/2
A
A= $dt_req->length
Aresult
11
00
222 1 ▶ my $offset = $dt_req->start || 0;
Condition50%1/2
$dt_req->start || 0
l!l
10
MC/DC0%0/1
$dt_req->start || 0
$dt_req->start
Truth table50%1/2
A
A= $dt_req->start
Aresult
11
00
223
224 #join
225 1 ▶ if($self->join_clause ne '') {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->join_clause ne "") 0 1 1
226 0 $where_href = $self->_add_where_clause($where_href, $self->join_clause);
227 }
228
229 #SQL queries
230 1 my $sql = SQL::Abstract::Limit->new( limit_dialect => $dbh );
231
232 1 my ($sQuery, @bind) = $sql->select($self->tables, $aColumns, $where_href, \@order, $limit, $offset );
233 #die("SQL: " . $sQuery);
234
235 #get columns out of db with query we created
236 1 my $result_sth = $dbh->prepare($sQuery);
237 1 ▶ $result_sth->execute(@bind) or croak "error in mysql query: $!\n$sQuery";
Branch: 1 branch
BranchTrueFalseTotal
$result_sth->execute(@bind) or croak("error in mysql query: $!\n$sQuery") 1 0 1
238
239 # Data set length after filtering
240 1 my ($sQuery_cnt_filtered, @bind_cnt_filtered) = $sql->select($self->tables, 'COUNT(*)', $where_href );
241
242 1 my $sth_cnt_filtered = $dbh->prepare($sQuery_cnt_filtered);
243 1 ▶ $sth_cnt_filtered->execute(@bind_cnt_filtered) or croak "mysql error: $!";
Branch: 1 branch
BranchTrueFalseTotal
$sth_cnt_filtered->execute(@bind_cnt_filtered) or croak("mysql error: $!") 1 0 1
244
245 1 my @aResultFilterTotal = $sth_cnt_filtered->fetchrow_array();
246 1 my $iFilteredTotal = $aResultFilterTotal[0];
247
248
249 1 my $num_tables = scalar(@{$self->tables});
250
251 1 my ($sQuery_cnt_total, @bind_cnt_total) = $sql->select($self->tables, 'COUNT(*)');
252 1 my $sth_cnt_total = $dbh->prepare($sQuery_cnt_total);
253 1 ▶ $sth_cnt_total->execute() or croak "error in query: $!\n$sQuery";
Branch: 1 branch
BranchTrueFalseTotal
$sth_cnt_total->execute or croak("error in query: $!\n$sQuery") 1 0 1
254
255 1 my @aResultTotal = $sth_cnt_total->fetchrow_array;
256 1 my $iTotal = $aResultTotal[0];
257
258 # output hash
259 1 my %output = ();
260 1 my $sEcho = $dt_req->draw;
261 1 my $version = $dt_req->version( \%all_query_parameters );
262
263 1 my $data_key_name = 'aaData'; # defaults to v1.9
264
265 1 ▶ if( $version eq '1.10' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($version eq '1.10') { } 0 1 1
266 # new interface
267
268 0 $data_key_name = 'data';
269 0 %output = (
270 "draw" => int($sEcho),
271 "recordsTotal" => int($iTotal),
272 "recordsFiltered" => int($iFilteredTotal),
273 $data_key_name => [],
274 );
275
276 }else{
277 # old interface
278
279 1 $data_key_name = 'aaData';
280 1 %output = (
281 "sEcho" => int($sEcho),
282 "iTotalRecords" => int($iTotal),
283 "iTotalDisplayRecords" => int($iFilteredTotal),
284 $data_key_name => [],
285 );
286
287 }
288
289 1 my $count = 0;
290 1 my $patterns = $self->patterns;
291
292 1 ▶ while(my @aRow = $result_sth->fetchrow_array) {
Branch: 1 branch
BranchTrueFalseTotal
if (my(@aRow) = $result_sth->fetchrow_array) 3 1 4
293 3 my @row = ();
294 3 ▶ for (my $i = 0; $i < @$aColumns; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < @$aColumns) 15 3 18
295 15 my $pat_name = $regular_columns->[$i]; #get out the name that would be used in the pattern
296 15 my $val = $aRow[$i];
297
298 # apply user specified pattern for this column if one exists
299 15 ▶ if(exists $patterns->{$pat_name}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $patterns->{$pat_name}) 0 15 15
300 0 my $pattern = $patterns->{$pat_name};
301 0 $pattern =~ s/\[\%\s$pat_name\s\%\]/$val/g;
302 0 $val = $pattern;
303 }
304
305 15 push @row, $val;
306 }
307
308 3 ▶ if( $self->data_output_format eq 'column-id' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->data_output_format eq 'column-id') { } 3 0 3
309 3 @{$output{$data_key_name}}[$count] = [@row];
310 }else{
311 0 my %row = map { $aColumns->[$_] => $row[$_] } 0 .. $#row;
312 0 push @{$output{$data_key_name}}, \%row;
313 }
314
315 3 $count++;
316 }
317
318 1 return \%output;
319 } # /table_data
320
321
322
323
324 0 ▶sub json {
Subroutine json: not called CC=1 SCAR=6.9
Pod documented
325 0 my $self = shift;
326
327 0 my $output_href = $self->table_data;
328
329 0 return encode_json $output_href;
330 } # /json
331
332
333
334
335 1 ▶sub _create_datatables_request {
Subroutine _create_datatables_request: called CC=1 SCAR=0.0
336 1 my $self = shift;
337 1 my $query_params = shift;
338 1 return JQuery::DataTables::Request->new( client_params => $query_params );
339 }
340
341
342
343
344 1 ▶sub _generate_where_clause {
Subroutine _generate_where_clause: called CC=12 SCAR=36.0
345 1 my $self = shift;
346 1 my $dt_req = shift;
347
348 1 my ($aColumns,undef,undef) = $self->_columns_arr;
349
350 1 my $where_href = {};
351
352 1 ▶ if( $dt_req->search && defined $dt_req->search->{value} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($dt_req->search and defined $dt_req->search->{"value"}) 0 1 1
Condition33%1/3
$dt_req->search and defined $dt_req->search->{"value"}
!ll&&!rl&&r
100
MC/DC0%0/2
$dt_req->search and defined $dt_req->search->{"value"}
$dt_req->search defined $dt_req->search->{"value"}
Truth table33%1/3
A and B
A= $dt_req->searchB= defined $dt_req->search->{"value"}
ABresult
0X0
100
111
353 0 my $search_string = $dt_req->search->{value}; # the global search value
354
355 # XXX: maybe use $dt_req->columns()?
356 0 ▶ for( my $i = 0; $i < @$aColumns; $i++ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < @$aColumns) 0 0 0
357 # Iterate over each column and check if it is searchable.
358 # If so, add a constraint to the where clause restricting the given
359 # column. In the query, the column is identified by it's index, we
360 # need to translates the index to the column name.
361 0 ▶ if ( defined $dt_req->column($i) and $dt_req->column($i)->{searchable} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $dt_req->column($i) and $dt_req->column($i)->{"searchable"}) 0 0 0
Condition0%0/3
defined $dt_req->column($i) and $dt_req->column($i)->{"searchable"}
!ll&&!rl&&r
000
MC/DC0%0/2
defined $dt_req->column($i) and $dt_req->column($i)->{"searchable"}
defined $dt_req->column($i) $dt_req->column($i)->{"searchable"}
Truth table0%0/3
A and B
A= defined $dt_req->column($i)B= $dt_req->column($i)->{"searchable"}
ABresult
0X0
100
111
362 # XXX: maybe use $dt_req->column($i)->{name}?
363 0 my $column = $aColumns->[$i];
364 0 push @{$where_href->{'-or'}}, { $column => {-like => '%'.$search_string.'%' } };
365 }
366 }
367 }
368
369 # XXX: merge with previous loop
370 #individual column filtering
371 1 ▶ for (my $i = 0; $i < @$aColumns; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < @$aColumns) 5 1 6
372 5 ▶ if( defined $dt_req->column($i) and $dt_req->column($i)->{searchable}
Branch: 1 branch
BranchTrueFalseTotal
if (defined $dt_req->column($i) and $dt_req->column($i)->{"searchable"} and ($dt_req->column($i)->{"search"}{"value"} and $dt_req->column($i)->{"search"}{"value"} ne "")) 0 5 5
Condition55%5/9
defined $dt_req->column($i) and $dt_req->column($i)->{"searchable"} and ($dt_req->column($i)->{"search"}{"value"} and $dt_req->column($i)->{"search"}{"value"} ne "")
!ll&&!rl&&r
230
defined $dt_req->column($i) and $dt_req->column($i)->{"searchable"}
!ll&&!rl&&r
203
$dt_req->column($i)->{"search"}{"value"} and $dt_req->column($i)->{"search"}{"value"} ne ""
!ll&&!rl&&r
300
MC/DC0%0/4
defined $dt_req->column($i) and $dt_req->column($i)->{"searchable"} and ($dt_req->column($i)->{"search"}{"value"} and $dt_req->column($i)->{"search"}{"value"} ne "")
defined $dt_req->column($i) $dt_req->column($i)->{"searchable"} $dt_req->column($i)->{"search"}{"value"} $dt_req->column($i)->{"search"}{"value"} ne ""
Truth table40%2/5
A and B and C and D
A= defined $dt_req->column($i)B= $dt_req->column($i)->{"searchable"}C= $dt_req->column($i)->{"search"}{"value"}D= $dt_req->column($i)->{"search"}{"value"} ne ""
ABCDresult
0XXX0
10XX0
110X0
11100
11111
373 and ($dt_req->column($i)->{search}->{value} and $dt_req->column($i)->{search}->{value} ne '') ) {
374 0 my $individual_column_search = $dt_req->column($i)->{search}->{value};
375 0 $where_href->{$aColumns->[$i]} = {-like => '%'.$individual_column_search.'%'};
376 }
377 }
378
379 # add user where if given
380 1 ▶ if( $self->where_clause ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->where_clause) 0 1 1
381 0 $where_href = $self->_add_where_clause($where_href, $self->where_clause);
382 }
383
384 1 return $where_href;
385 } # /_generate_where_clause
386
387
388
389
390 #
391 # convert
392 # \%where = {key => value, -or => \@ }
393 # to
394 # \%where = {-and => [{key => value, -or => \@ }, $plus]}
395 #
396 # $plus can be a hashref for SQL::Abstract.
397 # $plus can also be scalarref (deprecated).
398 #
399
400 0 ▶sub _add_where_clause {
Subroutine _add_where_clause: not called CC=4 SCAR=30.0
401 0 my $self = shift;
402 0 ▶ my $existing_clauses_href = shift or croak('Missing where clause');
Branch: 1 branch
BranchTrueFalseTotal
my $existing_clauses_href = shift() or croak("Missing where clause") 0 0 0
403 0 my $new_clause = shift;
404
405 0 ▶ return $existing_clauses_href unless $new_clause;
Branch: 1 branch
BranchTrueFalseTotal
unless $new_clause 0 0 0
406
407 0 ▶ if( UNIVERSAL::isa($new_clause, 'HASH') ) {
Branch: 1 branch
BranchTrueFalseTotal
if (UNIVERSAL::isa($new_clause, "HASH")) 0 0 0
408 return {
409 0 -and => [
410 $existing_clauses_href,
411 $new_clause,
412 ],
413 };
414 }
415
416 # Add arbitrary WHERE clause. This might be dangerous.
417 return {
418 0 -and => [
419 $existing_clauses_href,
420 \$new_clause
421 ],
422 };
423 } # /_add_where_clause
424
425
426
427
428 1 ▶sub _generate_order_clause {
Subroutine _generate_order_clause: called CC=2 SCAR=7.8
429 1 my $self = shift;
430 1 my $dt_req = shift;
431
432 1 my ($aColumns,undef,undef) = $self->_columns_arr;
433
434 1 my @order = ();
435
436 1 foreach my $order_instruction ( @{$dt_req->orders()} ) {
437
438 # build direction, must be '-asc' or '-desc' (cf. SQL::Abstract)
439 # we only get 'asc' or 'desc', so they have to be prefixed with '-'
440 0 my $sortable_column_nr = $order_instruction->{column};
441 0 my $direction = '-' . $order_instruction->{dir};
442
443 # We only get the column index (starting from 0), so we have to
444 # translate the index into a column name.
445 0 my $column_name = $aColumns->[$sortable_column_nr];
446 0 push @order, { $direction => $column_name };
447
448 }
449
450 1 return @order;
451 } # /_generate_order_clause
452
453
454
455
456 1 ▶sub _get_query_parameters {
Subroutine _get_query_parameters: called CC=1 SCAR=0.0
457 1 my $self = shift;
458
459 # CGI OBJECT
460 1 my $q = $self->{query};
461
462 # TODO: available from Perl 5.20.0: get multiple key-value pairs in 1 request, e.g. my %new_hash = %hash{qw/a b/};
463 # XXX: encapsulate to make testing easier (re-use the encapsulated method in tests instead of custom code)
464 1 my %all_query_parameters = $q->Vars;
465
466 1 return %all_query_parameters;
467 } # /_get_query_parameters
468
469 2 1; # /DataTables
470
471 __END__
↑ Summary