| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
#================================================================= -*-Perl-*- |
|
2
|
|
|
|
|
|
|
# |
|
3
|
|
|
|
|
|
|
# Template::Namespace::Constants |
|
4
|
|
|
|
|
|
|
# |
|
5
|
|
|
|
|
|
|
# DESCRIPTION |
|
6
|
|
|
|
|
|
|
# Plugin compiler module for performing constant folding at compile time |
|
7
|
|
|
|
|
|
|
# on variables in a particular namespace. |
|
8
|
|
|
|
|
|
|
# |
|
9
|
|
|
|
|
|
|
# AUTHOR |
|
10
|
|
|
|
|
|
|
# Andy Wardley |
|
11
|
|
|
|
|
|
|
# |
|
12
|
|
|
|
|
|
|
# COPYRIGHT |
|
13
|
|
|
|
|
|
|
# Copyright (C) 1996-2007 Andy Wardley. All Rights Reserved. |
|
14
|
|
|
|
|
|
|
# |
|
15
|
|
|
|
|
|
|
# This module is free software; you can redistribute it and/or |
|
16
|
|
|
|
|
|
|
# modify it under the same terms as Perl itself. |
|
17
|
|
|
|
|
|
|
# |
|
18
|
|
|
|
|
|
|
#============================================================================ |
|
19
|
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
package Template::Namespace::Constants; |
|
21
|
|
|
|
|
|
|
|
|
22
|
5
|
|
|
5
|
|
668
|
use strict; |
|
|
5
|
|
|
|
|
12
|
|
|
|
5
|
|
|
|
|
231
|
|
|
23
|
5
|
|
|
5
|
|
31
|
use warnings; |
|
|
5
|
|
|
|
|
12
|
|
|
|
5
|
|
|
|
|
250
|
|
|
24
|
5
|
|
|
5
|
|
33
|
use base 'Template::Base'; |
|
|
5
|
|
|
|
|
11
|
|
|
|
5
|
|
|
|
|
655
|
|
|
25
|
5
|
|
|
5
|
|
34
|
use Template::Config; |
|
|
5
|
|
|
|
|
11
|
|
|
|
5
|
|
|
|
|
137
|
|
|
26
|
5
|
|
|
5
|
|
3281
|
use Template::Directive; |
|
|
5
|
|
|
|
|
15
|
|
|
|
5
|
|
|
|
|
166
|
|
|
27
|
5
|
|
|
5
|
|
131
|
use Template::Exception; |
|
|
5
|
|
|
|
|
11
|
|
|
|
5
|
|
|
|
|
3348
|
|
|
28
|
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
our $VERSION = 1.27; |
|
30
|
|
|
|
|
|
|
our $DEBUG = 0 unless defined $DEBUG; |
|
31
|
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
sub _init { |
|
34
|
8
|
|
|
8
|
|
18
|
my ($self, $config) = @_; |
|
35
|
8
|
|
50
|
|
|
53
|
$self->{ STASH } = Template::Config->stash($config) |
|
36
|
|
|
|
|
|
|
|| return $self->error(Template::Config->error()); |
|
37
|
8
|
|
|
|
|
98
|
return $self; |
|
38
|
|
|
|
|
|
|
} |
|
39
|
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
#------------------------------------------------------------------------ |
|
43
|
|
|
|
|
|
|
# ident(\@ident) foo.bar(baz) |
|
44
|
|
|
|
|
|
|
#------------------------------------------------------------------------ |
|
45
|
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
sub ident { |
|
47
|
36
|
|
|
36
|
1
|
74
|
my ($self, $ident) = @_; |
|
48
|
36
|
|
|
|
|
100
|
my @save = @$ident; |
|
49
|
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
# discard first node indicating constants namespace |
|
51
|
36
|
|
|
|
|
62
|
splice(@$ident, 0, 2); |
|
52
|
|
|
|
|
|
|
|
|
53
|
36
|
|
|
|
|
74
|
my $nelems = @$ident / 2; |
|
54
|
36
|
|
|
|
|
43
|
my ($e, $result); |
|
55
|
36
|
|
|
|
|
66
|
local $" = ', '; |
|
56
|
|
|
|
|
|
|
|
|
57
|
36
|
50
|
|
|
|
90
|
print STDERR "constant ident [ @$ident ] " if $DEBUG; |
|
58
|
|
|
|
|
|
|
|
|
59
|
36
|
|
|
|
|
103
|
foreach $e (0..$nelems-1) { |
|
60
|
|
|
|
|
|
|
# node name must be a constant |
|
61
|
61
|
50
|
|
|
|
339
|
unless ($ident->[$e * 2] =~ s/^'(.+)'$/$1/s) { |
|
62
|
0
|
0
|
|
|
|
0
|
$self->DEBUG(" * deferred (non-constant item: ", $ident->[$e * 2], ")\n") |
|
63
|
|
|
|
|
|
|
if $DEBUG; |
|
64
|
0
|
|
|
|
|
0
|
return Template::Directive->ident(\@save); |
|
65
|
|
|
|
|
|
|
} |
|
66
|
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
# if args is non-zero then it must be eval'ed |
|
68
|
61
|
100
|
|
|
|
206
|
if ($ident->[$e * 2 + 1]) { |
|
69
|
4
|
|
|
|
|
10
|
my $args = $ident->[$e * 2 + 1]; |
|
70
|
4
|
|
|
|
|
268
|
my $comp = eval "$args"; |
|
71
|
4
|
50
|
|
|
|
19
|
if ($@) { |
|
72
|
0
|
0
|
|
|
|
0
|
$self->DEBUG(" * deferred (non-constant args: $args)\n") if $DEBUG; |
|
73
|
0
|
|
|
|
|
0
|
return Template::Directive->ident(\@save); |
|
74
|
|
|
|
|
|
|
} |
|
75
|
4
|
50
|
33
|
|
|
20
|
$self->DEBUG("($args) ") if $comp && $DEBUG; |
|
76
|
4
|
|
|
|
|
19
|
$ident->[$e * 2 + 1] = $comp; |
|
77
|
|
|
|
|
|
|
} |
|
78
|
|
|
|
|
|
|
} |
|
79
|
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
|
|
81
|
36
|
|
|
|
|
725
|
$result = $self->{ STASH }->get($ident); |
|
82
|
|
|
|
|
|
|
|
|
83
|
36
|
100
|
100
|
|
|
217
|
if (! length $result || ref $result) { |
|
84
|
2
|
100
|
|
|
|
9
|
my $reason = length $result ? 'reference' : 'no result'; |
|
85
|
2
|
50
|
|
|
|
7
|
$self->DEBUG(" * deferred ($reason)\n") if $DEBUG; |
|
86
|
2
|
|
|
|
|
14
|
return Template::Directive->ident(\@save); |
|
87
|
|
|
|
|
|
|
} |
|
88
|
|
|
|
|
|
|
|
|
89
|
34
|
|
|
|
|
85
|
$result =~ s/'/\\'/g; |
|
90
|
|
|
|
|
|
|
|
|
91
|
34
|
50
|
|
|
|
70
|
$self->DEBUG(" * resolved => '$result'\n") if $DEBUG; |
|
92
|
|
|
|
|
|
|
|
|
93
|
34
|
|
|
|
|
213
|
return "'$result'"; |
|
94
|
|
|
|
|
|
|
} |
|
95
|
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
1; |
|
97
|
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
__END__ |