line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Catmandu::Fix::template; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
58343
|
use Moo; |
|
1
|
|
|
|
|
9137
|
|
|
1
|
|
|
|
|
4
|
|
4
|
1
|
|
|
1
|
|
1563
|
use Template; |
|
1
|
|
|
|
|
17868
|
|
|
1
|
|
|
|
|
31
|
|
5
|
1
|
|
|
1
|
|
401
|
use Catmandu; |
|
1
|
|
|
|
|
241651
|
|
|
1
|
|
|
|
|
4
|
|
6
|
1
|
|
|
1
|
|
567
|
use Catmandu::Fix::Has; |
|
1
|
|
|
|
|
858
|
|
|
1
|
|
|
|
|
6
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
with 'Catmandu::Fix::Base'; |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
has path => (fix_arg => 1); |
11
|
|
|
|
|
|
|
has value => (fix_arg => 1); |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
sub emit { |
14
|
1
|
|
|
1
|
0
|
3361
|
my ($self, $fixer) = @_; |
15
|
|
|
|
|
|
|
|
16
|
1
|
|
|
|
|
9
|
my $path = $fixer->split_path($self->path); |
17
|
1
|
|
|
|
|
37
|
my $value = $fixer->emit_value($self->value); |
18
|
1
|
|
|
|
|
48
|
my $tt = $fixer->capture(Template->new); |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
$fixer->emit_create_path( |
21
|
|
|
|
|
|
|
$fixer->var, |
22
|
|
|
|
|
|
|
$path, |
23
|
|
|
|
|
|
|
sub { |
24
|
1
|
|
|
1
|
|
78
|
my $var = shift; |
25
|
1
|
|
|
|
|
16
|
my $root = $fixer->var; |
26
|
1
|
|
|
|
|
9
|
my $output = $fixer->generate_var; |
27
|
1
|
|
|
|
|
12
|
my $perl = $fixer->emit_declare_vars($output, '""'); |
28
|
1
|
|
|
|
|
22
|
$perl .= "${tt}->process(\\${value},${root},\\${output});"; |
29
|
1
|
|
|
|
|
3
|
$perl .= "${var} = ${output};"; |
30
|
1
|
|
|
|
|
3
|
$perl; |
31
|
|
|
|
|
|
|
} |
32
|
1
|
|
|
|
|
18703
|
); |
33
|
|
|
|
|
|
|
} |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
=head1 NAME |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
Catmandu::Fix::template - add a value to the record based on a template |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
=head1 SYNOPSIS |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
# Your record contains: |
42
|
|
|
|
|
|
|
# |
43
|
|
|
|
|
|
|
# name: John |
44
|
|
|
|
|
|
|
# age: 44 |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
template(message,"Mr [%name%] is [%age%] years old") |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
# Result: |
49
|
|
|
|
|
|
|
# |
50
|
|
|
|
|
|
|
# name: John |
51
|
|
|
|
|
|
|
# age: 44 |
52
|
|
|
|
|
|
|
# message: Mr John is 44 years old |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
=head1 SEE ALSO |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
L<Catmandu::Fix>, L<Template> |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
=cut |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
1; |