line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Catmandu::Fix::Datahub::Util; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
673
|
use strict; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
22
|
|
4
|
|
|
|
|
|
|
|
5
|
1
|
|
|
1
|
|
383
|
use Catmandu::Sane; |
|
1
|
|
|
|
|
109087
|
|
|
1
|
|
|
|
|
8
|
|
6
|
|
|
|
|
|
|
|
7
|
1
|
|
|
1
|
|
210
|
use Exporter qw(import); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
197
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
our @EXPORT_OK = qw(declare_source walk); |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
## |
12
|
|
|
|
|
|
|
# For a source $var, that is a path parameter to a fix, |
13
|
|
|
|
|
|
|
# use walk() to get the value and return the generated |
14
|
|
|
|
|
|
|
# $perl code. |
15
|
|
|
|
|
|
|
# @param $var |
16
|
|
|
|
|
|
|
# @param $declared_var |
17
|
|
|
|
|
|
|
# @return $fixer emit code |
18
|
|
|
|
|
|
|
sub declare_source { |
19
|
0
|
|
|
0
|
0
|
|
my ($fixer, $var, $declared_var) = @_; |
20
|
|
|
|
|
|
|
|
21
|
0
|
|
|
|
|
|
my $perl = ''; |
22
|
|
|
|
|
|
|
|
23
|
0
|
|
|
|
|
|
my $var_path = $fixer->split_path($var); |
24
|
0
|
|
|
|
|
|
my $var_key = pop @$var_path; |
25
|
0
|
|
|
|
|
|
$perl .= walk($fixer, $var_path, $var_key, $declared_var); |
26
|
0
|
|
|
|
|
|
return $perl; |
27
|
|
|
|
|
|
|
} |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
## |
30
|
|
|
|
|
|
|
# Walk through a path ($path) until at |
31
|
|
|
|
|
|
|
# $key. Set $h = $val in the fixer code. |
32
|
|
|
|
|
|
|
# $h must be declared before calling walk() |
33
|
|
|
|
|
|
|
# This has the effect of assigning $val (the value of the leaf |
34
|
|
|
|
|
|
|
# node you're walking to) to $h, so you can use $h in your fix. |
35
|
|
|
|
|
|
|
# @param $path |
36
|
|
|
|
|
|
|
# @param $key |
37
|
|
|
|
|
|
|
# @param $h |
38
|
|
|
|
|
|
|
# @return $fixer emit code |
39
|
|
|
|
|
|
|
sub walk { |
40
|
0
|
|
|
0
|
0
|
|
my ($fixer, $path, $key, $h) = @_; |
41
|
|
|
|
|
|
|
|
42
|
0
|
|
|
|
|
|
my $perl = ''; |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
$perl .= $fixer->emit_walk_path( |
45
|
|
|
|
|
|
|
$fixer->var, |
46
|
|
|
|
|
|
|
$path, |
47
|
|
|
|
|
|
|
sub { |
48
|
0
|
|
|
0
|
|
|
my $var = shift; |
49
|
|
|
|
|
|
|
$fixer->emit_get_key( |
50
|
|
|
|
|
|
|
$var, |
51
|
|
|
|
|
|
|
$key, |
52
|
|
|
|
|
|
|
sub { |
53
|
0
|
|
|
|
|
|
my $val = shift; |
54
|
0
|
|
|
|
|
|
"${h} = ${val};"; |
55
|
|
|
|
|
|
|
} |
56
|
0
|
|
|
|
|
|
); |
57
|
|
|
|
|
|
|
} |
58
|
0
|
|
|
|
|
|
); |
59
|
|
|
|
|
|
|
|
60
|
0
|
|
|
|
|
|
return $perl; |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
1; |
64
|
|
|
|
|
|
|
__END__ |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
=encoding utf-8 |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
=head1 NAME |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
Catmandu::Fix::Datahub::Util - Utility functions for the Datahub project |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
=head1 AUTHOR |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
Pieter De Praetere E<lt>pieter@packed.beE<gt> |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
=head1 COPYRIGHT |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
Copyright 2017- PACKED vzw |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
=head1 LICENSE |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or modify |
83
|
|
|
|
|
|
|
it under the same terms as Perl itself. |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
=head1 SEE ALSO |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
L<Catmandu::Fix::Datahub> |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
=cut |