line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package DTL::Fast::Filter::Center; |
2
|
4
|
|
|
4
|
|
1370
|
use strict; |
|
4
|
|
|
|
|
9
|
|
|
4
|
|
|
|
|
89
|
|
3
|
4
|
|
|
4
|
|
15
|
use utf8; |
|
4
|
|
|
|
|
10
|
|
|
4
|
|
|
|
|
20
|
|
4
|
4
|
|
|
4
|
|
79
|
use warnings FATAL => 'all'; |
|
4
|
|
|
|
|
6
|
|
|
4
|
|
|
|
|
113
|
|
5
|
4
|
|
|
4
|
|
61
|
use parent 'DTL::Fast::Filter'; |
|
4
|
|
|
|
|
8
|
|
|
4
|
|
|
|
|
21
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
$DTL::Fast::FILTER_HANDLERS{center} = __PACKAGE__; |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
#@Override |
10
|
|
|
|
|
|
|
sub parse_parameters |
11
|
|
|
|
|
|
|
{ |
12
|
8
|
|
|
8
|
0
|
16
|
my $self = shift; |
13
|
|
|
|
|
|
|
die $self->get_parse_error("no width specified for adjusting") |
14
|
8
|
50
|
|
|
|
11
|
if (not scalar @{$self->{parameter}}); |
|
8
|
|
|
|
|
25
|
|
15
|
8
|
|
|
|
|
16
|
$self->{width} = $self->{parameter}->[0]; |
16
|
8
|
|
|
|
|
23
|
return $self; |
17
|
|
|
|
|
|
|
} |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
#@Override |
20
|
|
|
|
|
|
|
sub filter |
21
|
|
|
|
|
|
|
{ |
22
|
8
|
|
|
8
|
0
|
20
|
my ($self, $filter_manager, $value, $context) = @_; |
23
|
|
|
|
|
|
|
|
24
|
8
|
|
|
|
|
29
|
my $width = $self->{width}->render($context); |
25
|
|
|
|
|
|
|
|
26
|
8
|
50
|
|
|
|
43
|
if ($width =~ /^\d+$/) |
27
|
|
|
|
|
|
|
{ |
28
|
8
|
|
|
|
|
23
|
my $adjustment = ($width - length $value); |
29
|
8
|
50
|
|
|
|
22
|
if ($adjustment > 0) |
30
|
|
|
|
|
|
|
{ |
31
|
8
|
|
|
|
|
23
|
$value = $self->adjust($value, $adjustment); |
32
|
|
|
|
|
|
|
} |
33
|
|
|
|
|
|
|
} |
34
|
|
|
|
|
|
|
else |
35
|
|
|
|
|
|
|
{ |
36
|
0
|
|
|
|
|
0
|
die $self->get_render_error("Argument must be a positive number, not '$width'"); |
37
|
|
|
|
|
|
|
} |
38
|
8
|
|
|
|
|
26
|
return $value; |
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
sub adjust |
42
|
|
|
|
|
|
|
{ |
43
|
4
|
|
|
4
|
0
|
8
|
my ($self, $value, $adjustment) = @_; |
44
|
4
|
|
|
|
|
18
|
return (' 'x int($adjustment / 2)).$value; |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
1; |