| 1 | package JQuery::DataTables::Request; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||
| 3 | 4 | ▶ | use 5.012; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 4 | 4 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 5 | 4 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||||||||||
| 7 | 4 | our $VERSION = '0.109'; # VERSION | |||||||||||||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||||||||||||
| 9 | 4 | ▶ | use Carp; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||||||||||||
| 11 | 4 | ▶ | use base 'Class::Accessor'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||||||||||||
| 13 | =head1 NAME | ||||||||||||||||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||||||||||||||||
| 15 | JQuery::DataTables::Request - represents a DataTables server-side request | ||||||||||||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||||||||||||
| 17 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||||||||||||||||
| 19 | my $dt_req = JQuery::DataTables::Request->new( $client_parameters ); | ||||||||||||||||||||||||||||||||||||||||||
| 20 | if ( $dt_req->column(0)->{searchable} ) { | ||||||||||||||||||||||||||||||||||||||||||
| 21 | # do something | ||||||||||||||||||||||||||||||||||||||||||
| 22 | } | ||||||||||||||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||||||||||||||
| 24 | $dt_req->search->{value}; # the global search value | ||||||||||||||||||||||||||||||||||||||||||
| 25 | if ($dt_req->search->{regex}) { | ||||||||||||||||||||||||||||||||||||||||||
| 26 | # global search is set to regex | ||||||||||||||||||||||||||||||||||||||||||
| 27 | } | ||||||||||||||||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||||||||||||||||
| 29 | # find the column definition with the name 'col_name' | ||||||||||||||||||||||||||||||||||||||||||
| 30 | my $cols = $dt_req->find_columns( by_name => 'col_name' ); | ||||||||||||||||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||||||||||||||||
| 32 | $dt_req->draw; #sEcho or draw parameter | ||||||||||||||||||||||||||||||||||||||||||
| 33 | $dt_req->start; #iDisplayStart or start parameter | ||||||||||||||||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||||||||||||||||
| 35 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||||||||||||||||
| 37 | This module represents a DataTables server-side request originating from the DataTables | ||||||||||||||||||||||||||||||||||||||||||
| 38 | client side JS library. There are two major versions of DataTables(v1.9 and v1.10) that send | ||||||||||||||||||||||||||||||||||||||||||
| 39 | differently named parameters server-side for processing. This module only provides an API | ||||||||||||||||||||||||||||||||||||||||||
| 40 | that corresponds to the v1.10 parameters but maps the v1.9 parameters to the corresponding v1.10 | ||||||||||||||||||||||||||||||||||||||||||
| 41 | parameters. | ||||||||||||||||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||||||||||||||||
| 43 | The DataTable parameters are documented at the following locations: | ||||||||||||||||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||||||||||||||||
| 45 | =over | ||||||||||||||||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||||||||||||||||
| 47 | =item L<Version 1.10 server-side parameters|http://www.datatables.net/manual/server-side> | ||||||||||||||||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||||||||||||||||
| 49 | =item L<Version 1.9 server-side parameters|http://legacy.datatables.net/usage/server-side> | ||||||||||||||||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||||||||||||||||
| 51 | =back | ||||||||||||||||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||||||||||||||||
| 53 | Each column parameter is represented as a HashRef like so: | ||||||||||||||||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||||||||||||||||
| 55 | { | ||||||||||||||||||||||||||||||||||||||||||
| 56 | name => 'col_name', | ||||||||||||||||||||||||||||||||||||||||||
| 57 | data => 'col_name', | ||||||||||||||||||||||||||||||||||||||||||
| 58 | orderable => 1, | ||||||||||||||||||||||||||||||||||||||||||
| 59 | searchable => 1, | ||||||||||||||||||||||||||||||||||||||||||
| 60 | search => { | ||||||||||||||||||||||||||||||||||||||||||
| 61 | value => 'search string', | ||||||||||||||||||||||||||||||||||||||||||
| 62 | regex => 0, | ||||||||||||||||||||||||||||||||||||||||||
| 63 | } | ||||||||||||||||||||||||||||||||||||||||||
| 64 | } | ||||||||||||||||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||||||||||||||||
| 66 | e.g. | ||||||||||||||||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||||||||||||||||
| 68 | $dt_req->column(0)->{search}{value} | ||||||||||||||||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||||||||||||||||
| 70 | Order parameters look like this: | ||||||||||||||||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||||||||||||||||
| 72 | { | ||||||||||||||||||||||||||||||||||||||||||
| 73 | dir => 'asc', | ||||||||||||||||||||||||||||||||||||||||||
| 74 | column => 1 | ||||||||||||||||||||||||||||||||||||||||||
| 75 | } | ||||||||||||||||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||||||||||||||||
| 77 | e.g. | ||||||||||||||||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||||||||||||||||
| 79 | $dt_req->order(0)->{dir} | ||||||||||||||||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||||||||||||||||
| 81 | The order and column accessors are indexed the same way as your column parameters so | ||||||||||||||||||||||||||||||||||||||||||
| 82 | C<< $req->column(0) >> returns the column in the client_params C<[columns][0]> column. | ||||||||||||||||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||||||||||||||||
| 84 | C<order> is similar in that C<< $req->order(0) >> returns the C<order[0]> parameter data. | ||||||||||||||||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||||||||||||||||
| 86 | =head1 METHODS | ||||||||||||||||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||||||||||||||||
| 88 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||||||||||||||||
| 90 | # V1.10 accessors | ||||||||||||||||||||||||||||||||||||||||||
| 91 | 4 | __PACKAGE__->mk_accessors(qw( | |||||||||||||||||||||||||||||||||||||||||
| 92 | draw | ||||||||||||||||||||||||||||||||||||||||||
| 93 | start | ||||||||||||||||||||||||||||||||||||||||||
| 94 | length | ||||||||||||||||||||||||||||||||||||||||||
| 95 | search | ||||||||||||||||||||||||||||||||||||||||||
| 96 | _version | ||||||||||||||||||||||||||||||||||||||||||
| 97 | _order | ||||||||||||||||||||||||||||||||||||||||||
| 98 | _columns | ||||||||||||||||||||||||||||||||||||||||||
| 99 | ) | ||||||||||||||||||||||||||||||||||||||||||
| 100 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||||||||||||||||
| 102 | =head2 new | ||||||||||||||||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||||||||||||||||
| 104 | Creates a new JQuery::DataTables::Request object. | ||||||||||||||||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||||||||||||||||
| 106 | my $dt_request = JQuery::DataTables::Request->new( client_params => $c->parameters ); | ||||||||||||||||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||||||||||||||||
| 108 | Accepts the following parameters | ||||||||||||||||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||||||||||||||||
| 110 | =over | ||||||||||||||||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||||||||||||||||
| 112 | =item client_params | ||||||||||||||||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||||||||||||||||
| 114 | This is a HashRef that should contain your DataTables parameters as provided by the DataTables | ||||||||||||||||||||||||||||||||||||||||||
| 115 | JS library. Any parameters provided that are not recognized as DataTables request are silently ignored. | ||||||||||||||||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||||||||||||||||
| 117 | =back | ||||||||||||||||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||||||||||||||||
| 119 | new will confess/croak on the following scenarios: | ||||||||||||||||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||||||||||||||||
| 121 | =over | ||||||||||||||||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||||||||||||||||
| 123 | =item client_params is not provided | ||||||||||||||||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||||||||||||||||
| 125 | =item client_params is not a HashRef | ||||||||||||||||||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||||||||||||||||
| 127 | =item client_params isn't recognized as containing DataTables parameters | ||||||||||||||||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||||||||||||||||
| 129 | =back | ||||||||||||||||||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||||||||||||||||
| 131 | You should catch these if you are worried about it. | ||||||||||||||||||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||||||||||||||||
| 133 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||||||||||||||||
| 135 | # client_params should be hashref | ||||||||||||||||||||||||||||||||||||||||||
| 136 | 6 | ▶ | sub new { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=7 SCAR=19.6
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 137 | 6 | my ($class, %options) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 138 | |||||||||||||||||||||||||||||||||||||||||||
| 139 | confess 'No DataTables parameters provided in the constructor - see client_params option' | ||||||||||||||||||||||||||||||||||||||||||
| 140 | 6 | ▶ | unless defined($options{'client_params'}); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 141 | |||||||||||||||||||||||||||||||||||||||||||
| 142 | confess 'client_params must be a HashRef' | ||||||||||||||||||||||||||||||||||||||||||
| 143 | 6 | ▶ | unless ref($options{'client_params'}) eq 'HASH'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 144 | |||||||||||||||||||||||||||||||||||||||||||
| 145 | 6 | my $obj = bless {}, __PACKAGE__; | |||||||||||||||||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||||||||||||||||
| 147 | 6 | my $version = $obj->version( $options{client_params} ); | |||||||||||||||||||||||||||||||||||||||||
| 148 | 6 | ▶ | if (defined $version && $version eq '1.10') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition100%3/3
defined $version and $version eq "1.10"
MC/DC100%2/2
defined $version and $version eq "1.10"
defined $version
$version eq "1.10"
Truth table100%3/3
A and B
A= defined $versionB= $version eq "1.10"
| |||||||||||||||||||||||||||||||||||||||||||
| 149 | 3 | $obj->_process_v1_10_params( $options{'client_params'} ); | |||||||||||||||||||||||||||||||||||||||||
| 150 | ▶ | } elsif (defined $version && $version eq '1.9') { | |||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
defined $version and $version eq "1.9"
MC/DC50%1/2
defined $version and $version eq "1.9"
defined $version
$version eq "1.9"
Truth table66%2/3
A and B
A= defined $versionB= $version eq "1.9"
| |||||||||||||||||||||||||||||||||||||||||||
| 151 | 2 | $obj->_process_v1_9_params( $options{'client_params'} ); | |||||||||||||||||||||||||||||||||||||||||
| 152 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 153 | 1 | confess 'client_params provided do not contain DataTables server-side parameters (i.e. this is not DataTables request data)'; | |||||||||||||||||||||||||||||||||||||||||
| 154 | } | ||||||||||||||||||||||||||||||||||||||||||
| 155 | 5 | $obj->_version( $version ); | |||||||||||||||||||||||||||||||||||||||||
| 156 | 5 | return $obj; | |||||||||||||||||||||||||||||||||||||||||
| 157 | } | ||||||||||||||||||||||||||||||||||||||||||
| 158 | |||||||||||||||||||||||||||||||||||||||||||
| 159 | =head2 column | ||||||||||||||||||||||||||||||||||||||||||
| 160 | |||||||||||||||||||||||||||||||||||||||||||
| 161 | my \%column = $request->column(0); | ||||||||||||||||||||||||||||||||||||||||||
| 162 | |||||||||||||||||||||||||||||||||||||||||||
| 163 | Returns a single column definition of the requested index | ||||||||||||||||||||||||||||||||||||||||||
| 164 | |||||||||||||||||||||||||||||||||||||||||||
| 165 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 166 | |||||||||||||||||||||||||||||||||||||||||||
| 167 | 6 | ▶ | sub column { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
column: called CC=2 SCAR=7.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 168 | 6 | my ($self,$idx_arr) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 169 | 6 | ▶ | return if !defined($idx_arr); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 170 | 6 | return $self->_columns->[$idx_arr]; | |||||||||||||||||||||||||||||||||||||||||
| 171 | } | ||||||||||||||||||||||||||||||||||||||||||
| 172 | |||||||||||||||||||||||||||||||||||||||||||
| 173 | =head2 columns | ||||||||||||||||||||||||||||||||||||||||||
| 174 | |||||||||||||||||||||||||||||||||||||||||||
| 175 | my \@columns = $request->columns([0,1]); | ||||||||||||||||||||||||||||||||||||||||||
| 176 | |||||||||||||||||||||||||||||||||||||||||||
| 177 | Returns column definitions for the requested indexes. Can accept either an | ||||||||||||||||||||||||||||||||||||||||||
| 178 | arrayref of scalars or a single column scalar. If no column index is provided | ||||||||||||||||||||||||||||||||||||||||||
| 179 | all columns are returned. | ||||||||||||||||||||||||||||||||||||||||||
| 180 | |||||||||||||||||||||||||||||||||||||||||||
| 181 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 182 | |||||||||||||||||||||||||||||||||||||||||||
| 183 | 9 | ▶ | sub columns { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
columns: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 184 | 9 | my ($self, $idx_arr) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 185 | 9 | my $col_ref = $self->_columns; | |||||||||||||||||||||||||||||||||||||||||
| 186 | 9 | ▶ | return $col_ref if !defined($idx_arr); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 187 | |||||||||||||||||||||||||||||||||||||||||||
| 188 | 3 | ▶ | $idx_arr = [ $idx_arr ] if ref($idx_arr) ne 'ARRAY'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 189 | |||||||||||||||||||||||||||||||||||||||||||
| 190 | 3 | my $ret_arr; | |||||||||||||||||||||||||||||||||||||||||
| 191 | 3 | foreach my $idx ( sort @$idx_arr ) { | |||||||||||||||||||||||||||||||||||||||||
| 192 | 5 | push(@$ret_arr, $col_ref->[$idx]); | |||||||||||||||||||||||||||||||||||||||||
| 193 | } | ||||||||||||||||||||||||||||||||||||||||||
| 194 | 3 | return $ret_arr; | |||||||||||||||||||||||||||||||||||||||||
| 195 | } | ||||||||||||||||||||||||||||||||||||||||||
| 196 | |||||||||||||||||||||||||||||||||||||||||||
| 197 | =head2 columns_hashref | ||||||||||||||||||||||||||||||||||||||||||
| 198 | |||||||||||||||||||||||||||||||||||||||||||
| 199 | Get all column definitions as a Hashref, with the column index as the key | ||||||||||||||||||||||||||||||||||||||||||
| 200 | |||||||||||||||||||||||||||||||||||||||||||
| 201 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 202 | |||||||||||||||||||||||||||||||||||||||||||
| 203 | 1 | ▶ | sub columns_hashref { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
columns_hashref: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 204 | 1 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 205 | 1 | my %col_hash; | |||||||||||||||||||||||||||||||||||||||||
| 206 | 1 | @col_hash{ 0 .. $#{$self->_columns} } = @{$self->_columns}; | |||||||||||||||||||||||||||||||||||||||||
| 207 | 1 | return \%col_hash; | |||||||||||||||||||||||||||||||||||||||||
| 208 | } | ||||||||||||||||||||||||||||||||||||||||||
| 209 | |||||||||||||||||||||||||||||||||||||||||||
| 210 | =head2 find_columns | ||||||||||||||||||||||||||||||||||||||||||
| 211 | |||||||||||||||||||||||||||||||||||||||||||
| 212 | $request->find_columns( %options ) | ||||||||||||||||||||||||||||||||||||||||||
| 213 | |||||||||||||||||||||||||||||||||||||||||||
| 214 | where C<%options> hash accepts the following parameters: | ||||||||||||||||||||||||||||||||||||||||||
| 215 | |||||||||||||||||||||||||||||||||||||||||||
| 216 | =over | ||||||||||||||||||||||||||||||||||||||||||
| 217 | |||||||||||||||||||||||||||||||||||||||||||
| 218 | =item by_name | ||||||||||||||||||||||||||||||||||||||||||
| 219 | |||||||||||||||||||||||||||||||||||||||||||
| 220 | by_name accepts a scalar or arrayref of values and returns an arrayref of | ||||||||||||||||||||||||||||||||||||||||||
| 221 | column definitions | ||||||||||||||||||||||||||||||||||||||||||
| 222 | |||||||||||||||||||||||||||||||||||||||||||
| 223 | my \@columns = $request->find_columns( by_name => ['col_name','col_name2'] ); | ||||||||||||||||||||||||||||||||||||||||||
| 224 | |||||||||||||||||||||||||||||||||||||||||||
| 225 | Searchs the columns C<data> and/or C<name> parameter. | ||||||||||||||||||||||||||||||||||||||||||
| 226 | |||||||||||||||||||||||||||||||||||||||||||
| 227 | =item search_field | ||||||||||||||||||||||||||||||||||||||||||
| 228 | |||||||||||||||||||||||||||||||||||||||||||
| 229 | my \@columns = $request->find_columns( by_name => 'something', search_field => 'name' ); | ||||||||||||||||||||||||||||||||||||||||||
| 230 | |||||||||||||||||||||||||||||||||||||||||||
| 231 | Set to either C<name> or C<data> to search those respective fields when | ||||||||||||||||||||||||||||||||||||||||||
| 232 | doing a C<by_name> seach. If no search_field is specified, C<by_name> searches | ||||||||||||||||||||||||||||||||||||||||||
| 233 | that match either field will be returned (i.e. defaults to search both fields) | ||||||||||||||||||||||||||||||||||||||||||
| 234 | |||||||||||||||||||||||||||||||||||||||||||
| 235 | =item by_idx | ||||||||||||||||||||||||||||||||||||||||||
| 236 | |||||||||||||||||||||||||||||||||||||||||||
| 237 | my \@columns = $request->find_columns( by_idx => $col_idx ) | ||||||||||||||||||||||||||||||||||||||||||
| 238 | |||||||||||||||||||||||||||||||||||||||||||
| 239 | This is just a passthrough to C<< $request->columns( $col_idx ); >> | ||||||||||||||||||||||||||||||||||||||||||
| 240 | |||||||||||||||||||||||||||||||||||||||||||
| 241 | =back | ||||||||||||||||||||||||||||||||||||||||||
| 242 | |||||||||||||||||||||||||||||||||||||||||||
| 243 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 244 | |||||||||||||||||||||||||||||||||||||||||||
| 245 | 3 | ▶ | sub find_columns { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
find_columns: called CC=11 SCAR=27.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 246 | 3 | my ($self, %options) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 247 | 3 | ▶ | return unless %options; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 248 | |||||||||||||||||||||||||||||||||||||||||||
| 249 | 3 | ▶ | if (defined($options{by_idx})) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 250 | 1 | return $self->columns($options{by_idx}); | |||||||||||||||||||||||||||||||||||||||||
| 251 | } | ||||||||||||||||||||||||||||||||||||||||||
| 252 | |||||||||||||||||||||||||||||||||||||||||||
| 253 | 2 | ▶ | if (my $searches = $options{by_name}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 254 | 2 | my $ret_cols; | |||||||||||||||||||||||||||||||||||||||||
| 255 | 2 | my $key = $options{search_field}; | |||||||||||||||||||||||||||||||||||||||||
| 256 | 2 | ▶ | $searches = [ $searches ] if ref($searches) ne 'ARRAY'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 257 | 2 | my $col_ref = $self->_columns; | |||||||||||||||||||||||||||||||||||||||||
| 258 | |||||||||||||||||||||||||||||||||||||||||||
| 259 | 2 | foreach my $search_val ( @$searches ) { | |||||||||||||||||||||||||||||||||||||||||
| 260 | 2 | foreach my $col ( @$col_ref ) { | |||||||||||||||||||||||||||||||||||||||||
| 261 | 2 | ▶ | if ( defined $key ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 262 | 0 | ▶ | if ( $col->{$key} eq $search_val ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 263 | 0 | push(@$ret_cols, $col); | |||||||||||||||||||||||||||||||||||||||||
| 264 | } | ||||||||||||||||||||||||||||||||||||||||||
| 265 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 266 | 2 | ▶ | if ( $col->{name} eq $search_val || $col->{data} eq $search_val ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$col->{"name"} eq $search_val or $col->{"data"} eq $search_val
MC/DC0%0/2
$col->{"name"} eq $search_val or $col->{"data"} eq $search_val
$col->{"name"} eq $search_val
$col->{"data"} eq $search_val
Truth table33%1/3
A or B
A= $col->{"name"} eq $search_valB= $col->{"data"} eq $search_val
| |||||||||||||||||||||||||||||||||||||||||||
| 267 | 2 | push(@$ret_cols, $col); | |||||||||||||||||||||||||||||||||||||||||
| 268 | } | ||||||||||||||||||||||||||||||||||||||||||
| 269 | } | ||||||||||||||||||||||||||||||||||||||||||
| 270 | } | ||||||||||||||||||||||||||||||||||||||||||
| 271 | } | ||||||||||||||||||||||||||||||||||||||||||
| 272 | 2 | return $ret_cols; | |||||||||||||||||||||||||||||||||||||||||
| 273 | } | ||||||||||||||||||||||||||||||||||||||||||
| 274 | } | ||||||||||||||||||||||||||||||||||||||||||
| 275 | |||||||||||||||||||||||||||||||||||||||||||
| 276 | =head2 order | ||||||||||||||||||||||||||||||||||||||||||
| 277 | |||||||||||||||||||||||||||||||||||||||||||
| 278 | $req->order(0)->{dir} | ||||||||||||||||||||||||||||||||||||||||||
| 279 | |||||||||||||||||||||||||||||||||||||||||||
| 280 | Returns the order data at provided index. | ||||||||||||||||||||||||||||||||||||||||||
| 281 | |||||||||||||||||||||||||||||||||||||||||||
| 282 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 283 | |||||||||||||||||||||||||||||||||||||||||||
| 284 | sub order | ||||||||||||||||||||||||||||||||||||||||||
| 285 | 5 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
order: called CC=2 SCAR=7.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 286 | 5 | my ($self,$idx) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 287 | 5 | ▶ | return unless defined($idx); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 288 | 5 | return $self->_order->[$idx]; | |||||||||||||||||||||||||||||||||||||||||
| 289 | } | ||||||||||||||||||||||||||||||||||||||||||
| 290 | |||||||||||||||||||||||||||||||||||||||||||
| 291 | =head2 orders | ||||||||||||||||||||||||||||||||||||||||||
| 292 | |||||||||||||||||||||||||||||||||||||||||||
| 293 | $req->orders([0,1]); | ||||||||||||||||||||||||||||||||||||||||||
| 294 | |||||||||||||||||||||||||||||||||||||||||||
| 295 | Returns an arrayref of the order data records at the provided indexes. Accepts an arrayref or scalar. | ||||||||||||||||||||||||||||||||||||||||||
| 296 | C<< ->orders([0,1]) >> will get C<orders[0]> and C<orders[1]> data. | ||||||||||||||||||||||||||||||||||||||||||
| 297 | |||||||||||||||||||||||||||||||||||||||||||
| 298 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 299 | |||||||||||||||||||||||||||||||||||||||||||
| 300 | sub orders | ||||||||||||||||||||||||||||||||||||||||||
| 301 | 2 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
orders: called CC=4 SCAR=21.7
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 302 | 2 | my ($self,$ar_idx) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 303 | 2 | my $ord_ref = $self->_order; | |||||||||||||||||||||||||||||||||||||||||
| 304 | 2 | ▶ | return $ord_ref unless defined($ar_idx); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 305 | |||||||||||||||||||||||||||||||||||||||||||
| 306 | 0 | ▶ | $ar_idx = [ $ar_idx ] unless ref($ar_idx) eq 'ARRAY'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 307 | |||||||||||||||||||||||||||||||||||||||||||
| 308 | 0 | my $ret_arr; | |||||||||||||||||||||||||||||||||||||||||
| 309 | 0 | foreach my $idx ( @$ar_idx ) { | |||||||||||||||||||||||||||||||||||||||||
| 310 | 0 | push(@$ret_arr, $ord_ref->[$idx]); | |||||||||||||||||||||||||||||||||||||||||
| 311 | } | ||||||||||||||||||||||||||||||||||||||||||
| 312 | |||||||||||||||||||||||||||||||||||||||||||
| 313 | 0 | return $ret_arr; | |||||||||||||||||||||||||||||||||||||||||
| 314 | } | ||||||||||||||||||||||||||||||||||||||||||
| 315 | |||||||||||||||||||||||||||||||||||||||||||
| 316 | =head2 version | ||||||||||||||||||||||||||||||||||||||||||
| 317 | |||||||||||||||||||||||||||||||||||||||||||
| 318 | my $version = $request->version( \%client_params? ) | ||||||||||||||||||||||||||||||||||||||||||
| 319 | |||||||||||||||||||||||||||||||||||||||||||
| 320 | Returns the version of DataTables we need to support based on the parameters sent. | ||||||||||||||||||||||||||||||||||||||||||
| 321 | v1.9 version of DataTables sends different named parameters than v1.10. Returns a string | ||||||||||||||||||||||||||||||||||||||||||
| 322 | of '1.9' if we think we have a 1.9 request, '1.10' if we think it is a 1.10 request or C<undef> | ||||||||||||||||||||||||||||||||||||||||||
| 323 | if we dont' think it is a DataTables request at all. | ||||||||||||||||||||||||||||||||||||||||||
| 324 | |||||||||||||||||||||||||||||||||||||||||||
| 325 | This can be invoked as a class method as well as an instance method. | ||||||||||||||||||||||||||||||||||||||||||
| 326 | |||||||||||||||||||||||||||||||||||||||||||
| 327 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 328 | |||||||||||||||||||||||||||||||||||||||||||
| 329 | sub version | ||||||||||||||||||||||||||||||||||||||||||
| 330 | 13 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
version: called CC=10 SCAR=23.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 331 | 13 | my ($self,$client_params) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 332 | |||||||||||||||||||||||||||||||||||||||||||
| 333 | 13 | ▶ | if (!ref($self) && !defined($client_params)) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
ref $self or defined $client_params
MC/DC100%2/2
ref $self or defined $client_params
ref $self
defined $client_params
Truth table100%3/3
A or B
A= ref $selfB= defined $client_params
| |||||||||||||||||||||||||||||||||||||||||||
| 334 | 1 | return; | |||||||||||||||||||||||||||||||||||||||||
| 335 | } | ||||||||||||||||||||||||||||||||||||||||||
| 336 | |||||||||||||||||||||||||||||||||||||||||||
| 337 | 12 | ▶ | return $self->_version unless $client_params; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 338 | 10 | my $ref = $client_params; | |||||||||||||||||||||||||||||||||||||||||
| 339 | |||||||||||||||||||||||||||||||||||||||||||
| 340 | # v1.10 parameters | ||||||||||||||||||||||||||||||||||||||||||
| 341 | 10 | ▶ | if (defined $ref->{draw} && defined $ref->{start} && defined $ref->{'length'}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition83%5/6
defined $ref->{"draw"} and defined $ref->{"start"} and defined $ref->{"length"}
defined $ref->{"draw"} and defined $ref->{"start"}
MC/DC66%2/3
defined $ref->{"draw"} and defined $ref->{"start"} and defined $ref->{"length"}
defined $ref->{"draw"}
defined $ref->{"start"}
defined $ref->{"length"}
Truth table75%3/4
A and B and C
A= defined $ref->{"draw"}B= defined $ref->{"start"}C= defined $ref->{"length"}
| |||||||||||||||||||||||||||||||||||||||||||
| 342 | 4 | return '1.10'; | |||||||||||||||||||||||||||||||||||||||||
| 343 | } | ||||||||||||||||||||||||||||||||||||||||||
| 344 | |||||||||||||||||||||||||||||||||||||||||||
| 345 | # v1.9 parameters | ||||||||||||||||||||||||||||||||||||||||||
| 346 | 6 | ▶ | if (defined $ref->{sEcho} && defined $ref->{iDisplayStart} && defined $ref->{iDisplayLength}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%4/6
defined $ref->{"sEcho"} and defined $ref->{"iDisplayStart"} and defined $ref->{"iDisplayLength"}
defined $ref->{"sEcho"} and defined $ref->{"iDisplayStart"}
MC/DC33%1/3
defined $ref->{"sEcho"} and defined $ref->{"iDisplayStart"} and defined $ref->{"iDisplayLength"}
defined $ref->{"sEcho"}
defined $ref->{"iDisplayStart"}
defined $ref->{"iDisplayLength"}
Truth table50%2/4
A and B and C
A= defined $ref->{"sEcho"}B= defined $ref->{"iDisplayStart"}C= defined $ref->{"iDisplayLength"}
| |||||||||||||||||||||||||||||||||||||||||||
| 347 | 3 | return '1.9'; | |||||||||||||||||||||||||||||||||||||||||
| 348 | } | ||||||||||||||||||||||||||||||||||||||||||
| 349 | |||||||||||||||||||||||||||||||||||||||||||
| 350 | 3 | return; | |||||||||||||||||||||||||||||||||||||||||
| 351 | } | ||||||||||||||||||||||||||||||||||||||||||
| 352 | |||||||||||||||||||||||||||||||||||||||||||
| 353 | =head1 PRIVATE METHODS | ||||||||||||||||||||||||||||||||||||||||||
| 354 | |||||||||||||||||||||||||||||||||||||||||||
| 355 | |||||||||||||||||||||||||||||||||||||||||||
| 356 | =head2 _process_v1_9_params | ||||||||||||||||||||||||||||||||||||||||||
| 357 | |||||||||||||||||||||||||||||||||||||||||||
| 358 | Processes v1.9 parameters, mapping them to 1.10 parameters | ||||||||||||||||||||||||||||||||||||||||||
| 359 | |||||||||||||||||||||||||||||||||||||||||||
| 360 | $self->_process_v1_9_params( \%client_params ) | ||||||||||||||||||||||||||||||||||||||||||
| 361 | |||||||||||||||||||||||||||||||||||||||||||
| 362 | where C<\%client_params> is a HashRef containing the v1.9 parameters that DataTables | ||||||||||||||||||||||||||||||||||||||||||
| 363 | client library sends the server in server-side mode. | ||||||||||||||||||||||||||||||||||||||||||
| 364 | |||||||||||||||||||||||||||||||||||||||||||
| 365 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 366 | |||||||||||||||||||||||||||||||||||||||||||
| 367 | # maps 1.9 to 1.10 variables | ||||||||||||||||||||||||||||||||||||||||||
| 368 | # only thing not mapped is iColumns | ||||||||||||||||||||||||||||||||||||||||||
| 369 | 4 | my $vmap = { | |||||||||||||||||||||||||||||||||||||||||
| 370 | top => { | ||||||||||||||||||||||||||||||||||||||||||
| 371 | 'iDisplayStart' => 'start', | ||||||||||||||||||||||||||||||||||||||||||
| 372 | 'iDisplayLength' => 'length', | ||||||||||||||||||||||||||||||||||||||||||
| 373 | 'sEcho' => 'draw', | ||||||||||||||||||||||||||||||||||||||||||
| 374 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 375 | col_and_order => { | ||||||||||||||||||||||||||||||||||||||||||
| 376 | 'bSearchable' => ['columns', 'searchable', undef], | ||||||||||||||||||||||||||||||||||||||||||
| 377 | 'sSearch' => ['columns', 'search', 'value'], | ||||||||||||||||||||||||||||||||||||||||||
| 378 | 'bRegex' => ['columns', 'search', 'regex'], | ||||||||||||||||||||||||||||||||||||||||||
| 379 | 'bSortable' => ['columns', 'orderable', undef], | ||||||||||||||||||||||||||||||||||||||||||
| 380 | 'mDataProp' => ['columns', 'data', undef], | ||||||||||||||||||||||||||||||||||||||||||
| 381 | 'iSortCol' => ['order', 'column', undef], | ||||||||||||||||||||||||||||||||||||||||||
| 382 | 'sSortDir' => ['order', 'dir', undef] | ||||||||||||||||||||||||||||||||||||||||||
| 383 | } | ||||||||||||||||||||||||||||||||||||||||||
| 384 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 385 | |||||||||||||||||||||||||||||||||||||||||||
| 386 | 2 | ▶ | sub _process_v1_9_params { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_process_v1_9_params: called CC=14 SCAR=26.4
| |||||||||||||||||||||||||||||||||||||||||||
| 387 | 2 | my ($self, $client_params) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 388 | 2 | my $columns; | |||||||||||||||||||||||||||||||||||||||||
| 389 | my $order; | ||||||||||||||||||||||||||||||||||||||||||
| 390 | 2 | my $search; | |||||||||||||||||||||||||||||||||||||||||
| 391 | |||||||||||||||||||||||||||||||||||||||||||
| 392 | 2 | ▶ | while ( my ($name,$val) = each %$client_params ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 393 | # handle top level parameters | ||||||||||||||||||||||||||||||||||||||||||
| 394 | 28 | ▶ | if ( grep { $_ eq $name && $val =~ m/^[0-9]+$/ } keys %{$vmap->{top}} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 4 branches
Condition66%2/3
$_ eq $name && $val =~ /^[0-9]+$/u
MC/DC50%1/2
$_ eq $name && $val =~ /^[0-9]+$/u
$_ eq $name
$val =~ /^[0-9]+$/u
Truth table66%2/3
A && B
A= $_ eq $nameB= $val =~ /^[0-9]+$/u
| |||||||||||||||||||||||||||||||||||||||||||
| 395 | 6 | my $acc = $vmap->{top}->{$name}; | |||||||||||||||||||||||||||||||||||||||||
| 396 | 6 | $self->$acc( $val ); | |||||||||||||||||||||||||||||||||||||||||
| 397 | } elsif ($name eq 'sSearch') { | ||||||||||||||||||||||||||||||||||||||||||
| 398 | 2 | $search->{value} = $val; | |||||||||||||||||||||||||||||||||||||||||
| 399 | } elsif ($name eq 'bRegex') { | ||||||||||||||||||||||||||||||||||||||||||
| 400 | 2 | ▶ | $search->{regex} = $val eq 'true' ? 1 : 0; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 401 | } elsif ($name =~ m/^(?<param>bSearchable|sSearch|bRegex|bSortable|iSortCol|sSortDir|mDataProp)_(?<idx>\d+)$/) { | ||||||||||||||||||||||||||||||||||||||||||
| 402 | 14 | my $map = $vmap->{col_and_order}->{$+{param}}; | |||||||||||||||||||||||||||||||||||||||||
| 403 | my ($param,$idx,$sub_param1,$sub_param2,$new_val) = | ||||||||||||||||||||||||||||||||||||||||||
| 404 | 14 | $self->_validate_and_convert( $map->[0], $+{idx}, $map->[1], $map->[2], $val); | |||||||||||||||||||||||||||||||||||||||||
| 405 | |||||||||||||||||||||||||||||||||||||||||||
| 406 | 14 | ▶ | if ($map->[0] eq 'columns') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 407 | 10 | ▶ | if (defined($sub_param2)) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 408 | 4 | $columns->{$idx}{$sub_param1}{$sub_param2} = $new_val; | |||||||||||||||||||||||||||||||||||||||||
| 409 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 410 | 6 | $columns->{$idx}{$sub_param1} = $new_val; | |||||||||||||||||||||||||||||||||||||||||
| 411 | # copy name => data for v1.9 so that find_columns works as expected | ||||||||||||||||||||||||||||||||||||||||||
| 412 | # not really sure how to do this, Data::Alias? alias it eventually | ||||||||||||||||||||||||||||||||||||||||||
| 413 | # right now just copy | ||||||||||||||||||||||||||||||||||||||||||
| 414 | 6 | ▶ | if ($sub_param1 eq 'data') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 415 | 2 | $columns->{$idx}{'name'} = $new_val; | |||||||||||||||||||||||||||||||||||||||||
| 416 | } | ||||||||||||||||||||||||||||||||||||||||||
| 417 | } | ||||||||||||||||||||||||||||||||||||||||||
| 418 | } elsif ($map->[0] eq 'order') { | ||||||||||||||||||||||||||||||||||||||||||
| 419 | 4 | $order->{$idx}{$sub_param1} = $new_val; | |||||||||||||||||||||||||||||||||||||||||
| 420 | } | ||||||||||||||||||||||||||||||||||||||||||
| 421 | } | ||||||||||||||||||||||||||||||||||||||||||
| 422 | } | ||||||||||||||||||||||||||||||||||||||||||
| 423 | |||||||||||||||||||||||||||||||||||||||||||
| 424 | 2 | my @col_arr; | |||||||||||||||||||||||||||||||||||||||||
| 425 | 2 | push(@col_arr, $columns->{$_}) for ( sort keys %$columns ); | |||||||||||||||||||||||||||||||||||||||||
| 426 | |||||||||||||||||||||||||||||||||||||||||||
| 427 | 2 | my @order_arr; | |||||||||||||||||||||||||||||||||||||||||
| 428 | 2 | push(@order_arr, $order->{$_}) for ( sort keys %$order ); | |||||||||||||||||||||||||||||||||||||||||
| 429 | |||||||||||||||||||||||||||||||||||||||||||
| 430 | 2 | $self->_columns( \@col_arr ); | |||||||||||||||||||||||||||||||||||||||||
| 431 | 2 | $self->_order( \@order_arr ); | |||||||||||||||||||||||||||||||||||||||||
| 432 | 2 | $self->search( $search ); | |||||||||||||||||||||||||||||||||||||||||
| 433 | } | ||||||||||||||||||||||||||||||||||||||||||
| 434 | |||||||||||||||||||||||||||||||||||||||||||
| 435 | =head2 _process_v1_10_params | ||||||||||||||||||||||||||||||||||||||||||
| 436 | |||||||||||||||||||||||||||||||||||||||||||
| 437 | $self->_process_v1_10_params( \%client_params ); | ||||||||||||||||||||||||||||||||||||||||||
| 438 | |||||||||||||||||||||||||||||||||||||||||||
| 439 | where C<\%client_params> is a HashRef containing the v1.10 parameters that DataTables | ||||||||||||||||||||||||||||||||||||||||||
| 440 | client library sends the server in server-side mode. | ||||||||||||||||||||||||||||||||||||||||||
| 441 | |||||||||||||||||||||||||||||||||||||||||||
| 442 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 443 | |||||||||||||||||||||||||||||||||||||||||||
| 444 | 3 | ▶ | sub _process_v1_10_params { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_process_v1_10_params: called CC=13 SCAR=25.7
| |||||||||||||||||||||||||||||||||||||||||||
| 445 | 3 | my ($self, $client_params) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 446 | |||||||||||||||||||||||||||||||||||||||||||
| 447 | 3 | my $columns; | |||||||||||||||||||||||||||||||||||||||||
| 448 | my $order; | ||||||||||||||||||||||||||||||||||||||||||
| 449 | 3 | my $search; | |||||||||||||||||||||||||||||||||||||||||
| 450 | 3 | ▶ | while ( my ($name,$val) = each %$client_params ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 451 | 47 | ▶ | $self->$name( $val ) if ( grep { $_ eq $name && $val =~ m/^[0-9]+$/ } qw(draw start length) ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$_ eq $name && $val =~ /^[0-9]+$/u
MC/DC50%1/2
$_ eq $name && $val =~ /^[0-9]+$/u
$_ eq $name
$val =~ /^[0-9]+$/u
Truth table66%2/3
A && B
A= $_ eq $nameB= $val =~ /^[0-9]+$/u
| |||||||||||||||||||||||||||||||||||||||||||
| 452 | |||||||||||||||||||||||||||||||||||||||||||
| 453 | 47 | ▶ | if ($name =~ m/^(?<param>columns|order)\[(?<idx>[0-9]+)\]\[(?<sub_param1>[^]]+)\](\[(?<sub_param2>[^]]+)\])?$/) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 454 | my ($param,$idx,$sub_param1,$sub_param2,$new_val) = | ||||||||||||||||||||||||||||||||||||||||||
| 455 | 32 | $self->_validate_and_convert($+{param}, $+{idx}+0, $+{sub_param1}, $+{sub_param2}, $val); | |||||||||||||||||||||||||||||||||||||||||
| 456 | |||||||||||||||||||||||||||||||||||||||||||
| 457 | 32 | ▶ | if ($param eq 'columns') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 458 | 24 | ▶ | if (defined($sub_param2)) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 459 | 8 | $columns->{$idx}{$sub_param1}{$sub_param2} = $new_val; | |||||||||||||||||||||||||||||||||||||||||
| 460 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 461 | 16 | $columns->{$idx}{$sub_param1} = $new_val; | |||||||||||||||||||||||||||||||||||||||||
| 462 | } | ||||||||||||||||||||||||||||||||||||||||||
| 463 | } elsif ($param eq 'order') { | ||||||||||||||||||||||||||||||||||||||||||
| 464 | 8 | $order->{$idx}{$sub_param1} = $new_val; | |||||||||||||||||||||||||||||||||||||||||
| 465 | } | ||||||||||||||||||||||||||||||||||||||||||
| 466 | } elsif ($name =~ m/^search\[(?<search_param>regex|value)\]$/) { | ||||||||||||||||||||||||||||||||||||||||||
| 467 | 6 | my $sp = $+{search_param}; | |||||||||||||||||||||||||||||||||||||||||
| 468 | 6 | ▶ | if ($sp eq 'regex') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 469 | 3 | ▶ | $search->{$sp} = $val eq 'true' ? 1 : 0; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 470 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 471 | 3 | $search->{$sp} = $val; | |||||||||||||||||||||||||||||||||||||||||
| 472 | } | ||||||||||||||||||||||||||||||||||||||||||
| 473 | } | ||||||||||||||||||||||||||||||||||||||||||
| 474 | } | ||||||||||||||||||||||||||||||||||||||||||
| 475 | |||||||||||||||||||||||||||||||||||||||||||
| 476 | 3 | my @col_arr; | |||||||||||||||||||||||||||||||||||||||||
| 477 | 3 | push(@col_arr, $columns->{$_}) for ( sort keys %$columns ); | |||||||||||||||||||||||||||||||||||||||||
| 478 | |||||||||||||||||||||||||||||||||||||||||||
| 479 | 3 | my @order_arr; | |||||||||||||||||||||||||||||||||||||||||
| 480 | 3 | push(@order_arr, $order->{$_}) for ( sort keys %$order ); | |||||||||||||||||||||||||||||||||||||||||
| 481 | |||||||||||||||||||||||||||||||||||||||||||
| 482 | 3 | $self->_columns( \@col_arr ); | |||||||||||||||||||||||||||||||||||||||||
| 483 | 3 | $self->_order( \@order_arr ); | |||||||||||||||||||||||||||||||||||||||||
| 484 | 3 | $self->search( $search ); | |||||||||||||||||||||||||||||||||||||||||
| 485 | 3 | return $self; | |||||||||||||||||||||||||||||||||||||||||
| 486 | } | ||||||||||||||||||||||||||||||||||||||||||
| 487 | |||||||||||||||||||||||||||||||||||||||||||
| 488 | =head2 _validate_and_convert | ||||||||||||||||||||||||||||||||||||||||||
| 489 | |||||||||||||||||||||||||||||||||||||||||||
| 490 | Validates parameters are set properly and does boolean conversion | ||||||||||||||||||||||||||||||||||||||||||
| 491 | |||||||||||||||||||||||||||||||||||||||||||
| 492 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 493 | |||||||||||||||||||||||||||||||||||||||||||
| 494 | #XXX: make this not a mess | ||||||||||||||||||||||||||||||||||||||||||
| 495 | sub _validate_and_convert | ||||||||||||||||||||||||||||||||||||||||||
| 496 | 46 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_validate_and_convert: called CC=12 SCAR=25.0
| |||||||||||||||||||||||||||||||||||||||||||
| 497 | 46 | my ($self,$param,$idx,$sub1,$sub2,$val) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 498 | 46 | ▶ | if ($param eq 'columns') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 499 | 34 | ▶ | if ($sub1 eq 'orderable' || $sub1 eq 'searchable') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition100%3/3
$sub1 eq "orderable" or $sub1 eq "searchable"
MC/DC100%2/2
$sub1 eq "orderable" or $sub1 eq "searchable"
$sub1 eq "orderable"
$sub1 eq "searchable"
Truth table100%3/3
A or B
A= $sub1 eq "orderable"B= $sub1 eq "searchable"
| |||||||||||||||||||||||||||||||||||||||||||
| 500 | 12 | ▶ | $val = lc $val eq 'true' ? 1 : 0; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 501 | ▶ | } elsif ( $sub1 eq 'search' && $sub2 eq 'regex' ) { | |||||||||||||||||||||||||||||||||||||||||
|
Condition100%3/3
$sub1 eq "search" and $sub2 eq "regex"
MC/DC100%2/2
$sub1 eq "search" and $sub2 eq "regex"
$sub1 eq "search"
$sub2 eq "regex"
Truth table100%3/3
A and B
A= $sub1 eq "search"B= $sub2 eq "regex"
| |||||||||||||||||||||||||||||||||||||||||||
| 502 | 6 | ▶ | $val = lc $val eq 'true' ? 1 : 0; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 503 | } | ||||||||||||||||||||||||||||||||||||||||||
| 504 | } elsif ($param eq 'order') { | ||||||||||||||||||||||||||||||||||||||||||
| 505 | 12 | ▶ | if ($sub1 eq 'dir' && lc $val ne 'asc' && lc $val ne 'desc') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition83%5/6
$sub1 eq "dir" and lc $val ne "asc" and lc $val ne "desc"
$sub1 eq "dir" and lc $val ne "asc"
MC/DC0%0/3
$sub1 eq "dir" and lc $val ne "asc" and lc $val ne "desc"
$sub1 eq "dir"
lc $val ne "asc"
lc $val ne "desc"
Truth table75%3/4
A and B and C
A= $sub1 eq "dir"B= lc $val ne "asc"C= lc $val ne "desc"
| |||||||||||||||||||||||||||||||||||||||||||
| 506 | #warn 'Unknown order[dir] value provided. Must be asc or desc, defaulting to asc'; | ||||||||||||||||||||||||||||||||||||||||||
| 507 | 0 | $val = 'asc'; | |||||||||||||||||||||||||||||||||||||||||
| 508 | } | ||||||||||||||||||||||||||||||||||||||||||
| 509 | } | ||||||||||||||||||||||||||||||||||||||||||
| 510 | 46 | return ($param,$idx,$sub1,$sub2,$val); | |||||||||||||||||||||||||||||||||||||||||
| 511 | } | ||||||||||||||||||||||||||||||||||||||||||
| 512 | |||||||||||||||||||||||||||||||||||||||||||
| 513 | =head1 AUTHOR | ||||||||||||||||||||||||||||||||||||||||||
| 514 | |||||||||||||||||||||||||||||||||||||||||||
| 515 | Mike Wisener E<lt>xmikew_cpan_orgE<gt> | ||||||||||||||||||||||||||||||||||||||||||
| 516 | |||||||||||||||||||||||||||||||||||||||||||
| 517 | =head1 COPYRIGHT AND LICENSE | ||||||||||||||||||||||||||||||||||||||||||
| 518 | |||||||||||||||||||||||||||||||||||||||||||
| 519 | Copyright E<copy> 2014 by Mike Wisener | ||||||||||||||||||||||||||||||||||||||||||
| 520 | |||||||||||||||||||||||||||||||||||||||||||
| 521 | This library is free software; you can redistribute it and/or modify | ||||||||||||||||||||||||||||||||||||||||||
| 522 | it under the same terms as Perl itself. | ||||||||||||||||||||||||||||||||||||||||||
| 523 | |||||||||||||||||||||||||||||||||||||||||||
| 524 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 525 | |||||||||||||||||||||||||||||||||||||||||||
| 526 | 4 | 1; | |||||||||||||||||||||||||||||||||||||||||