line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Hub::Parse::DataInjector; |
2
|
1
|
|
|
1
|
|
5
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
34
|
|
3
|
1
|
|
|
1
|
|
5
|
use Hub qw/:lib/; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
7
|
|
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
push our @ISA, qw(Hub::Parse::Parser); |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
our %EVALUATORS; |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
sub get_evaluator { |
10
|
0
|
0
|
|
0
|
1
|
|
my $evaluator = defined $EVALUATORS{$_[1]} |
11
|
|
|
|
|
|
|
? $EVALUATORS{$_[1]} |
12
|
|
|
|
|
|
|
: &Hub::Parse::Parser::get_evaluator(@_); |
13
|
|
|
|
|
|
|
# Avoid undefined parser directive warnings |
14
|
0
|
0
|
|
0
|
|
|
return defined $evaluator ? $evaluator : sub {}; |
|
0
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
} |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
$EVALUATORS{'define'} = sub { |
18
|
|
|
|
|
|
|
my ($self, $params, $result) = @_; |
19
|
|
|
|
|
|
|
# return if $$self{'priority'} eq 'content'; |
20
|
|
|
|
|
|
|
my ($outer_str, $fields, $pos, $text, $parents, $valdata) = @$params; |
21
|
|
|
|
|
|
|
my ($opts, %directive) = Hub::opts($fields); |
22
|
|
|
|
|
|
|
my $varname = $directive{'define'}; |
23
|
|
|
|
|
|
|
my ($end_p, $block) = |
24
|
|
|
|
|
|
|
$self->_get_block($$pos + length($outer_str), $text, 'define'); |
25
|
|
|
|
|
|
|
$$result{'width'} = $end_p - $$pos; |
26
|
|
|
|
|
|
|
my $data = defined $varname |
27
|
|
|
|
|
|
|
? Hub::getv($self->{'data'}, $varname) |
28
|
|
|
|
|
|
|
: $self->{'data'}; |
29
|
|
|
|
|
|
|
if (defined $data) { |
30
|
|
|
|
|
|
|
my $type = ref($data) |
31
|
|
|
|
|
|
|
? isa($data, 'HASH') |
32
|
|
|
|
|
|
|
? 'HASH' |
33
|
|
|
|
|
|
|
: isa($data, 'ARRAY') |
34
|
|
|
|
|
|
|
? 'ARRAY' |
35
|
|
|
|
|
|
|
: ref($data) |
36
|
|
|
|
|
|
|
: 'TEXT'; |
37
|
|
|
|
|
|
|
$$result{'value'} = "$$self{'var_begin'}define"; |
38
|
|
|
|
|
|
|
$$result{'value'} .= " '$varname' as '$type'" if (defined $varname); |
39
|
|
|
|
|
|
|
$$result{'value'} .= "$$self{'var_end'}\n"; |
40
|
|
|
|
|
|
|
$$result{'value'} .= ref($data) ? Hub::hprint($data) : $data; |
41
|
|
|
|
|
|
|
$$result{'value'} .= $self->_end_define(); |
42
|
|
|
|
|
|
|
} else { |
43
|
|
|
|
|
|
|
$$result{'value'} = ''; |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
$$result{'goto'} = $$pos + length($$result{'value'}); |
46
|
|
|
|
|
|
|
}; |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
$EVALUATORS{'end'} = sub { |
49
|
|
|
|
|
|
|
my ($self, $params, $result) = @_; |
50
|
|
|
|
|
|
|
# return if $$self{'priority'} eq 'content'; |
51
|
|
|
|
|
|
|
my ($outer_str, $fields, $pos, $text, $parents, $valdata) = @$params; |
52
|
|
|
|
|
|
|
my ($opts, %directive) = Hub::opts($fields); |
53
|
|
|
|
|
|
|
$result->{'value'} = '' if $directive{'end'} eq 'define'; |
54
|
|
|
|
|
|
|
}; |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
sub get_value { |
57
|
0
|
|
|
0
|
1
|
|
return undef; |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
sub populate { |
61
|
0
|
|
|
0
|
1
|
|
my ($self,$opts) = Hub::objopts(\@_); |
62
|
0
|
|
|
|
|
|
$self->{'data'} = shift; |
63
|
0
|
|
|
|
|
|
$self->SUPER::populate(); |
64
|
|
|
|
|
|
|
}#populate |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
sub _end_define { |
67
|
0
|
|
|
0
|
|
|
return "$_[0]->{'var_begin'}end 'define'$_[0]->{'var_end'}"; |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
1; |