line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Mojolicious::Plugin::Vparam::Vsort; |
2
|
73
|
|
|
73
|
|
3203255
|
use Mojo::Base -strict; |
|
73
|
|
|
|
|
161780
|
|
|
73
|
|
|
|
|
422
|
|
3
|
73
|
|
|
73
|
|
7862
|
use Mojolicious::Plugin::Vparam::Common; |
|
73
|
|
|
|
|
142
|
|
|
73
|
|
|
|
|
23141
|
|
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
sub register { |
6
|
75
|
|
|
75
|
0
|
242
|
my ($class, $self, $app, $conf) = @_; |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
# Same as vparams but add standart table sort parameters for: |
9
|
|
|
|
|
|
|
# ORDER BY, LIMIT, OFFSET |
10
|
|
|
|
|
|
|
$app->helper(vsort => sub{ |
11
|
12
|
|
|
12
|
|
30403
|
my ($self, %attr) = @_; |
12
|
|
|
|
|
|
|
|
13
|
12
|
|
|
|
|
24
|
my $sort = delete $attr{'-sort'}; |
14
|
12
|
100
|
100
|
|
|
60
|
die 'Key "-sort" must be ArrayRef' |
15
|
|
|
|
|
|
|
if defined($sort) and 'ARRAY' ne ref $sort; |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
$attr{ $conf->{vsort_page} } = { |
18
|
|
|
|
|
|
|
type => 'int', |
19
|
|
|
|
|
|
|
default => 1, |
20
|
11
|
100
|
|
|
|
50
|
} if defined $conf->{vsort_page}; |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
$attr{ $conf->{vsort_rws} } = { |
23
|
|
|
|
|
|
|
type => 'int', |
24
|
|
|
|
|
|
|
default => $conf->{rows}, |
25
|
11
|
100
|
|
|
|
34
|
} if defined $conf->{vsort_rws}; |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
$attr{ $conf->{vsort_oby} } = { |
28
|
|
|
|
|
|
|
type => 'int', |
29
|
|
|
|
|
|
|
default => 0, |
30
|
10
|
50
|
66
|
|
|
41
|
post => sub { $sort->[ $_[1] ] or ($_[1] + 1) or 1 }, |
31
|
11
|
100
|
|
|
|
63
|
} if defined $conf->{vsort_oby}; |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
$attr{ $conf->{vsort_ods} } = { |
34
|
|
|
|
|
|
|
type => 'str', |
35
|
|
|
|
|
|
|
default => $conf->{ods}, |
36
|
10
|
|
|
|
|
25
|
post => sub { uc $_[1] }, |
37
|
|
|
|
|
|
|
regexp => qr{^(?:asc|desc)$}i, |
38
|
11
|
100
|
|
|
|
75
|
} if defined $conf->{vsort_ods}; |
39
|
|
|
|
|
|
|
|
40
|
11
|
|
|
|
|
63
|
my $result = $self->vparams( %attr ); |
41
|
11
|
100
|
|
|
|
121
|
return wantarray ? %$result : $result; |
42
|
75
|
|
|
|
|
596
|
}); |
43
|
|
|
|
|
|
|
|
44
|
75
|
|
|
|
|
1768
|
return; |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
1; |