| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
#!/usr/bin/perl -w |
|
2
|
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
package Template::Plugin::DataHash; |
|
4
|
|
|
|
|
|
|
|
|
5
|
1
|
|
|
1
|
|
21372
|
use strict; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
48
|
|
|
6
|
|
|
|
|
|
|
|
|
7
|
1
|
|
|
1
|
|
5
|
use vars qw($VERSION @ISA $EXTENSION $DEFAULT_INCLUDE_PATH); |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
104
|
|
|
8
|
|
|
|
|
|
|
$VERSION = '0.04'; |
|
9
|
|
|
|
|
|
|
|
|
10
|
1
|
|
|
1
|
|
781
|
use Template::Plugin; |
|
|
1
|
|
|
|
|
399705
|
|
|
|
1
|
|
|
|
|
985
|
|
|
11
|
|
|
|
|
|
|
@ISA = qw(Template::Plugin); |
|
12
|
|
|
|
|
|
|
$EXTENSION = { |
|
13
|
|
|
|
|
|
|
perl => qr/\.pl$/i, |
|
14
|
|
|
|
|
|
|
split => qr/\.split$/i, |
|
15
|
|
|
|
|
|
|
storable => qr/\.sto$/i, |
|
16
|
|
|
|
|
|
|
xml => qr/\.xml$/i, |
|
17
|
|
|
|
|
|
|
yaml => qr/\.yaml$/i, |
|
18
|
|
|
|
|
|
|
}; |
|
19
|
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
### $EXTENSION is a list of regular expression objects used to determine |
|
21
|
|
|
|
|
|
|
### how to read in the given conf file |
|
22
|
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
### if a INCLUDE_PATH isn't in the Template::Toolkit object, $DEFAULT_INCLUDE_PATH |
|
24
|
|
|
|
|
|
|
### will be used as the INCLUDE_PATH |
|
25
|
|
|
|
|
|
|
$DEFAULT_INCLUDE_PATH = ['/tmp']; |
|
26
|
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
sub new { |
|
28
|
0
|
|
|
0
|
1
|
|
my $type = shift; |
|
29
|
0
|
|
0
|
|
|
|
my $template_object = shift || {}; |
|
30
|
|
|
|
|
|
|
|
|
31
|
0
|
0
|
|
|
|
|
my @PASSED_ARGS = (ref $_[0] eq 'HASH') ? %{$_[0]} : @_; |
|
|
0
|
|
|
|
|
|
|
|
32
|
0
|
|
|
|
|
|
my %DEFAULT_ARGS = ( |
|
33
|
|
|
|
|
|
|
extension => { |
|
34
|
0
|
|
|
|
|
|
%{$EXTENSION}, |
|
35
|
|
|
|
|
|
|
}, |
|
36
|
|
|
|
|
|
|
extension_order => [qw(yaml perl storable xml split)], |
|
37
|
|
|
|
|
|
|
); |
|
38
|
0
|
|
|
|
|
|
my $self = bless \%DEFAULT_ARGS, $type; |
|
39
|
0
|
|
|
|
|
|
$self->merge_in_args(@_); |
|
40
|
0
|
0
|
|
|
|
|
unless($self->{INCLUDE_PATH}) { |
|
41
|
0
|
0
|
|
|
|
|
if($template_object->{CONFIG}{INCLUDE_PATH}) { |
|
42
|
0
|
|
|
|
|
|
$self->{INCLUDE_PATH} = [reverse @{$template_object->{CONFIG}{INCLUDE_PATH}}]; |
|
|
0
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
} else { |
|
44
|
0
|
|
|
|
|
|
$self->{INCLUDE_PATH} = $DEFAULT_INCLUDE_PATH; |
|
45
|
|
|
|
|
|
|
} |
|
46
|
|
|
|
|
|
|
} |
|
47
|
0
|
|
|
|
|
|
return $self; |
|
48
|
|
|
|
|
|
|
} |
|
49
|
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
sub hash { |
|
51
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
|
52
|
0
|
|
|
|
|
|
my $filename = shift; |
|
53
|
0
|
|
0
|
|
|
|
my $dirs = shift || $self->{INCLUDE_PATH}; |
|
54
|
|
|
|
|
|
|
|
|
55
|
0
|
|
|
|
|
|
my $return = {}; |
|
56
|
0
|
|
|
|
|
|
foreach my $dir (to_array($dirs)) { |
|
57
|
0
|
|
|
|
|
|
my $full_path = "$dir/$filename"; |
|
58
|
0
|
0
|
|
|
|
|
next unless(-e $full_path); |
|
59
|
0
|
|
|
|
|
|
my $this_ref; |
|
60
|
0
|
|
|
|
|
|
foreach my $regex (@{$self->{extension_order}}) { |
|
|
0
|
|
|
|
|
|
|
|
61
|
0
|
0
|
|
|
|
|
if($full_path =~ $self->{extension}{$regex}) { |
|
62
|
0
|
|
|
|
|
|
my $method = "load_$regex"; |
|
63
|
0
|
|
|
|
|
|
my $ref = $self->can($method); |
|
64
|
0
|
0
|
|
|
|
|
if($ref) { |
|
|
|
0
|
|
|
|
|
|
|
65
|
0
|
|
|
|
|
|
$this_ref = $self->$ref($full_path); |
|
66
|
|
|
|
|
|
|
} elsif($self->{$method}) { |
|
67
|
0
|
|
|
|
|
|
my $method_ref = ref $self->{$method}; |
|
68
|
0
|
0
|
0
|
|
|
|
if($method_ref && $method_ref eq 'CODE') { |
|
69
|
0
|
|
|
|
|
|
$this_ref = &{$self->{$method}}($self, $full_path); |
|
|
0
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
} else { |
|
71
|
0
|
|
|
|
|
|
die "\$self->{$method_ref} needs to be a CODE ref"; |
|
72
|
|
|
|
|
|
|
} |
|
73
|
|
|
|
|
|
|
} else { |
|
74
|
0
|
|
|
|
|
|
die "couldn't find a $method method to load $full_path"; |
|
75
|
|
|
|
|
|
|
} |
|
76
|
|
|
|
|
|
|
} |
|
77
|
|
|
|
|
|
|
} |
|
78
|
0
|
0
|
0
|
|
|
|
die "conf file returned a non-hash ref" unless(ref $this_ref && ref $this_ref eq 'HASH'); |
|
79
|
0
|
|
|
|
|
|
foreach (keys %{$this_ref}) { |
|
|
0
|
|
|
|
|
|
|
|
80
|
0
|
|
|
|
|
|
$return->{$_} = $this_ref->{$_}; |
|
81
|
|
|
|
|
|
|
} |
|
82
|
|
|
|
|
|
|
} |
|
83
|
0
|
|
|
|
|
|
return $return; |
|
84
|
|
|
|
|
|
|
} |
|
85
|
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
sub to_array { |
|
87
|
0
|
|
|
0
|
0
|
|
my $values = shift; |
|
88
|
0
|
0
|
|
|
|
|
return () unless defined $values; |
|
89
|
0
|
0
|
|
|
|
|
if (ref $values eq "ARRAY") { |
|
90
|
0
|
|
|
|
|
|
return @$values; |
|
91
|
|
|
|
|
|
|
} |
|
92
|
0
|
|
|
|
|
|
return ($values); |
|
93
|
|
|
|
|
|
|
} |
|
94
|
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
sub merge_in_args { |
|
96
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
|
97
|
0
|
0
|
|
|
|
|
my %PASSED_ARGS = (ref $_[0] eq 'HASH') ? %{$_[0]} : @_; |
|
|
0
|
|
|
|
|
|
|
|
98
|
0
|
|
|
|
|
|
foreach my $passed_arg (keys %PASSED_ARGS) { |
|
99
|
0
|
0
|
0
|
|
|
|
if(ref $PASSED_ARGS{$passed_arg} && ref $PASSED_ARGS{$passed_arg} eq 'HASH') { |
|
100
|
0
|
|
|
|
|
|
foreach my $key (keys %{$PASSED_ARGS{$passed_arg}}) { |
|
|
0
|
|
|
|
|
|
|
|
101
|
0
|
|
|
|
|
|
$self->{$passed_arg}{$key} = $PASSED_ARGS{$passed_arg}{$key}; |
|
102
|
|
|
|
|
|
|
} |
|
103
|
|
|
|
|
|
|
} else { |
|
104
|
0
|
|
|
|
|
|
$self->{$passed_arg} = $PASSED_ARGS{$passed_arg} |
|
105
|
|
|
|
|
|
|
} |
|
106
|
|
|
|
|
|
|
} |
|
107
|
|
|
|
|
|
|
} |
|
108
|
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
sub load_yaml { |
|
110
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
|
111
|
0
|
|
|
|
|
|
my $full_path = shift; |
|
112
|
0
|
|
|
|
|
|
require YAML; |
|
113
|
0
|
|
|
|
|
|
return YAML::LoadFile($full_path); |
|
114
|
|
|
|
|
|
|
} |
|
115
|
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
sub load_perl { |
|
117
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
|
118
|
0
|
|
|
|
|
|
my $full_path = shift; |
|
119
|
0
|
|
|
|
|
|
return do $full_path; |
|
120
|
|
|
|
|
|
|
} |
|
121
|
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
sub load_storable { |
|
123
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
|
124
|
0
|
|
|
|
|
|
my $full_path = shift; |
|
125
|
0
|
|
|
|
|
|
require Storable; |
|
126
|
0
|
|
|
|
|
|
return Storable::retrieve($full_path); |
|
127
|
|
|
|
|
|
|
} |
|
128
|
|
|
|
|
|
|
sub load_split { |
|
129
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
|
130
|
0
|
|
|
|
|
|
my $full_path = shift; |
|
131
|
0
|
|
|
|
|
|
my $this_ref = {}; |
|
132
|
0
|
0
|
|
|
|
|
open(FILE, $full_path) || die "couldn't open $full_path: $!"; |
|
133
|
0
|
|
|
|
|
|
while() { |
|
134
|
0
|
0
|
|
|
|
|
next if(/^\s*#/); |
|
135
|
0
|
0
|
|
|
|
|
next unless(/^(\S+)\s+(.+)\n?/); |
|
136
|
0
|
|
|
|
|
|
$this_ref->{$1} = $2; |
|
137
|
|
|
|
|
|
|
} |
|
138
|
0
|
|
|
|
|
|
close(FILE); |
|
139
|
0
|
|
|
|
|
|
return $this_ref; |
|
140
|
|
|
|
|
|
|
} |
|
141
|
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
sub load_xml { |
|
143
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
|
144
|
0
|
|
|
|
|
|
my $full_path = shift; |
|
145
|
0
|
|
|
|
|
|
require XML::Simple; |
|
146
|
0
|
|
|
|
|
|
return XML::Simple::XMLin($full_path); |
|
147
|
|
|
|
|
|
|
} |
|
148
|
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
1; |
|
150
|
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
__END__ |