line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Catmandu::Fix::template; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
65665
|
use Moo; |
|
1
|
|
|
|
|
9527
|
|
|
1
|
|
|
|
|
5
|
|
4
|
1
|
|
|
1
|
|
1575
|
use Template; |
|
1
|
|
|
|
|
18779
|
|
|
1
|
|
|
|
|
57
|
|
5
|
1
|
|
|
1
|
|
415
|
use Catmandu; |
|
1
|
|
|
|
|
278784
|
|
|
1
|
|
|
|
|
5
|
|
6
|
1
|
|
|
1
|
|
524
|
use Catmandu::Fix::Has; |
|
1
|
|
|
|
|
794
|
|
|
1
|
|
|
|
|
9
|
|
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
|
3115
|
my ($self, $fixer) = @_; |
15
|
|
|
|
|
|
|
|
16
|
1
|
|
|
|
|
6
|
my $path = $fixer->split_path($self->path); |
17
|
1
|
|
|
|
|
23
|
my $value = $fixer->emit_value($self->value); |
18
|
1
|
|
|
|
|
28
|
my $tt = $fixer->capture(Template->new); |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
$fixer->emit_create_path( |
21
|
|
|
|
|
|
|
$fixer->var, |
22
|
|
|
|
|
|
|
$path, |
23
|
|
|
|
|
|
|
sub { |
24
|
1
|
|
|
1
|
|
96
|
my $var = shift; |
25
|
1
|
|
|
|
|
15
|
my $root = $fixer->var; |
26
|
1
|
|
|
|
|
9
|
my $output = $fixer->generate_var; |
27
|
1
|
|
|
|
|
36
|
my $perl = $fixer->emit_declare_vars($output, '""'); |
28
|
1
|
|
|
|
|
14
|
$perl .= "${tt}->process(\\${value},${root},\\${output});"; |
29
|
1
|
|
|
|
|
4
|
$perl .= "${var} = ${output};"; |
30
|
1
|
|
|
|
|
3
|
$perl; |
31
|
|
|
|
|
|
|
} |
32
|
1
|
|
|
|
|
15654
|
); |
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; |