line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package DTL::Fast::Filter::Random; |
2
|
2
|
|
|
2
|
|
798
|
use strict; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
47
|
|
3
|
2
|
|
|
2
|
|
9
|
use utf8; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
12
|
|
4
|
2
|
|
|
2
|
|
40
|
use warnings FATAL => 'all'; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
61
|
|
5
|
2
|
|
|
2
|
|
9
|
use parent 'DTL::Fast::Filter'; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
10
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
$DTL::Fast::FILTER_HANDLERS{random} = __PACKAGE__; |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
#@Override |
10
|
|
|
|
|
|
|
sub filter |
11
|
|
|
|
|
|
|
{ |
12
|
2
|
|
|
2
|
0
|
6
|
my ( $self, $filter_manager, $value, $context ) = @_; |
13
|
|
|
|
|
|
|
|
14
|
2
|
50
|
0
|
|
|
9
|
die $self->get_render_error( |
|
|
|
0
|
|
|
|
|
15
|
|
|
|
|
|
|
$context, |
16
|
|
|
|
|
|
|
sprintf("Argument must be an ARRAY ref, not %s (%s)" |
17
|
|
|
|
|
|
|
, $value // 'undef' |
18
|
|
|
|
|
|
|
, ref $value || 'SCALAR' |
19
|
|
|
|
|
|
|
) |
20
|
|
|
|
|
|
|
) if (ref $value ne 'ARRAY'); |
21
|
|
|
|
|
|
|
|
22
|
2
|
|
|
|
|
49
|
return $value->[int(rand scalar @$value)]; |
23
|
|
|
|
|
|
|
} |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
1; |