line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
#############################################################################
|
2
|
|
|
|
|
|
|
## Name: XMLPerl.pm
|
3
|
|
|
|
|
|
|
## Purpose: Config::XMLPerl
|
4
|
|
|
|
|
|
|
## Author: Graciliano M. P.
|
5
|
|
|
|
|
|
|
## Modified by:
|
6
|
|
|
|
|
|
|
## Created: 2004-01-15
|
7
|
|
|
|
|
|
|
## RCS-ID:
|
8
|
|
|
|
|
|
|
## Copyright: (c) 2004 Graciliano M. P.
|
9
|
|
|
|
|
|
|
## Licence: This program is free software; you can redistribute it and/or
|
10
|
|
|
|
|
|
|
## modify it under the same terms as Perl itself
|
11
|
|
|
|
|
|
|
#############################################################################
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
package Config::XMLPerl ;
|
14
|
1
|
|
|
1
|
|
5788
|
use 5.006 ;
|
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
36
|
|
15
|
|
|
|
|
|
|
|
16
|
1
|
|
|
1
|
|
6
|
use strict qw(vars);
|
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
27
|
|
17
|
|
|
|
|
|
|
|
18
|
1
|
|
|
1
|
|
4
|
use vars qw($VERSION @ISA) ;
|
|
1
|
|
|
|
|
5
|
|
|
1
|
|
|
|
|
105
|
|
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
$VERSION = '0.01' ;
|
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
require Exporter;
|
23
|
|
|
|
|
|
|
@ISA = qw(Exporter);
|
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
our @EXPORT = qw(config_load) ;
|
26
|
|
|
|
|
|
|
our @EXPORT_OK = @EXPORT ;
|
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
###########
|
29
|
|
|
|
|
|
|
# REQUIRE #
|
30
|
|
|
|
|
|
|
###########
|
31
|
|
|
|
|
|
|
|
32
|
1
|
|
|
1
|
|
973
|
use XML::Smart ;
|
|
1
|
|
|
|
|
28048
|
|
|
1
|
|
|
|
|
57
|
|
33
|
1
|
|
|
1
|
|
1046
|
use Safe ;
|
|
1
|
|
|
|
|
44733
|
|
|
1
|
|
|
|
|
88
|
|
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
########
|
36
|
|
|
|
|
|
|
# VARS #
|
37
|
|
|
|
|
|
|
########
|
38
|
|
|
|
|
|
|
|
39
|
1
|
|
|
1
|
|
11
|
use vars qw($CACHE_DELAY) ;
|
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
1648
|
|
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
$CACHE_DELAY = 0 ;
|
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
my ( %CACHE , $CACHE_SLEEP , $EVAL_VALUES_COMPARTMENT ) ;
|
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
################################################################################
|
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
my @PERMIT_OPS = qw(
|
48
|
|
|
|
|
|
|
:base_mem
|
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
null stub pushmark const defined undef
|
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
preinc i_preinc predec i_predec postinc i_postinc postdec i_postdec
|
53
|
|
|
|
|
|
|
int hex oct abs pow multiply i_multiply divide i_divide
|
54
|
|
|
|
|
|
|
modulo i_modulo add i_add subtract i_subtract
|
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
left_shift right_shift bit_and bit_xor bit_or negate i_negate
|
57
|
|
|
|
|
|
|
not complement
|
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
lt i_lt gt i_gt le i_le ge i_ge eq i_eq ne i_ne ncmp i_ncmp
|
60
|
|
|
|
|
|
|
slt sgt sle sge seq sne scmp
|
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
substr stringify length ord chr
|
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
ucfirst lcfirst uc lc quotemeta trans chop schop chomp schomp
|
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
match split
|
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
list lslice reverse
|
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
cond_expr flip flop andassign orassign and or xor
|
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
lineseq scope enter leave setstate
|
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
rv2cv
|
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
leaveeval
|
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
gvsv gv gelem
|
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
padsv padav padhv padany
|
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
refgen srefgen ref
|
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
time
|
86
|
|
|
|
|
|
|
sort
|
87
|
|
|
|
|
|
|
pack unpack
|
88
|
|
|
|
|
|
|
) ;
|
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
################################################################################
|
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
#######
|
94
|
|
|
|
|
|
|
# NEW #
|
95
|
|
|
|
|
|
|
#######
|
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
sub new {
|
98
|
0
|
|
|
0
|
0
|
0
|
shift ; return config_load(@_) ;
|
|
0
|
|
|
|
|
0
|
|
99
|
|
|
|
|
|
|
}
|
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
###############
|
102
|
|
|
|
|
|
|
# CONFIG_LOAD #
|
103
|
|
|
|
|
|
|
###############
|
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
sub config_load {
|
106
|
|
|
|
|
|
|
|
107
|
1
|
50
|
|
1
|
1
|
9
|
if ( my $doc = $CACHE{$_[0]} ) {
|
108
|
|
|
|
|
|
|
|
109
|
0
|
0
|
|
|
|
0
|
if ( (time-$CACHE_SLEEP) > $CACHE_DELAY ) {
|
110
|
0
|
|
|
|
|
0
|
my @stats = stat($_[0]) ;
|
111
|
0
|
0
|
0
|
|
|
0
|
if ( $doc->{s} != $stats[7] || $doc->{t} != $stats[9] ) {
|
112
|
0
|
|
|
|
|
0
|
$doc = undef ;
|
113
|
0
|
|
|
|
|
0
|
delete $CACHE{$_[0]} ;
|
114
|
|
|
|
|
|
|
}
|
115
|
|
|
|
|
|
|
}
|
116
|
0
|
0
|
|
|
|
0
|
return $doc->{x} if $doc ;
|
117
|
|
|
|
|
|
|
}
|
118
|
|
|
|
|
|
|
|
119
|
1
|
|
|
|
|
5
|
my ($data , $file) = read_data($_[0]) ;
|
120
|
|
|
|
|
|
|
|
121
|
1
|
|
|
|
|
4
|
$data =~ s/(?:^|\n)[ \t]*#[^\n]+//gs ;
|
122
|
|
|
|
|
|
|
|
123
|
1
|
|
|
|
|
11
|
my $xml = XML::Smart->new($data , 'html' ,
|
124
|
|
|
|
|
|
|
lowtag => 1 ,
|
125
|
|
|
|
|
|
|
lowarg => 1 ,
|
126
|
|
|
|
|
|
|
on_char => \&on_char ,
|
127
|
|
|
|
|
|
|
) ;
|
128
|
|
|
|
|
|
|
|
129
|
0
|
|
|
|
|
0
|
$xml = $xml->cut_root ;
|
130
|
|
|
|
|
|
|
|
131
|
0
|
0
|
|
|
|
0
|
if ( $file ) {
|
132
|
0
|
|
|
|
|
0
|
my @stats = stat($file) ;
|
133
|
0
|
|
|
|
|
0
|
$CACHE{$file}{x} = $xml ;
|
134
|
0
|
|
|
|
|
0
|
$CACHE{$file}{s} = $stats[7] ;
|
135
|
0
|
|
|
|
|
0
|
$CACHE{$file}{t} = $stats[9] ;
|
136
|
|
|
|
|
|
|
}
|
137
|
|
|
|
|
|
|
|
138
|
0
|
|
|
|
|
0
|
return $xml ;
|
139
|
|
|
|
|
|
|
}
|
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
###########
|
142
|
|
|
|
|
|
|
# ON_CHAR #
|
143
|
|
|
|
|
|
|
###########
|
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
sub on_char {
|
146
|
1
|
|
|
1
|
0
|
4693
|
my ( $tag , $pointer , $pointer_back , $cont) = @_ ;
|
147
|
|
|
|
|
|
|
|
148
|
1
|
|
|
|
|
2
|
my $data = $$cont ;
|
149
|
|
|
|
|
|
|
|
150
|
1
|
|
|
|
|
9
|
my (@args) = ( $data =~ /[^\n\w]*(\w+[\w:\.]*[ \t]*(?:=>?|->|:)[ \t]*[^\n]+)/gs ) ;
|
151
|
|
|
|
|
|
|
|
152
|
1
|
|
|
|
|
4
|
foreach my $args_i ( @args ) {
|
153
|
1
|
|
|
|
|
19
|
$data =~ s/\Q$args_i\E//s ;
|
154
|
1
|
|
|
|
|
8
|
my ($name,$val) = ( $args_i =~ /(\w+[\w:\.]*)[ \t]*(?:=>?|->|:)[ \t]*([^\n]+)/ );
|
155
|
1
|
|
|
|
|
9
|
$val =~ s/\s*,\s*$// ;
|
156
|
|
|
|
|
|
|
|
157
|
1
|
50
|
|
|
|
15
|
if ( $val =~ /^'([^'\\]*)'$/ ) { $val = $1 ;}
|
|
0
|
50
|
|
|
|
0
|
|
|
|
50
|
|
|
|
|
|
158
|
0
|
|
|
|
|
0
|
elsif ( $val =~ /^"([^"\\]*)"$/ ) { $val = $1 ;}
|
159
|
1
|
|
|
|
|
5
|
elsif ( $val =~ /^(?:\{.*?\}|\[.*?\]|'.*?'|".*?")$/ ) { $val = reval($val) ;}
|
160
|
|
|
|
|
|
|
|
161
|
0
|
|
|
|
|
0
|
$pointer->{$name} = $val ;
|
162
|
|
|
|
|
|
|
}
|
163
|
|
|
|
|
|
|
|
164
|
0
|
|
|
|
|
0
|
$data =~ s/\s+//gs ;
|
165
|
|
|
|
|
|
|
|
166
|
0
|
0
|
|
|
|
0
|
if ( !$data ) { $$cont = undef ;}
|
|
0
|
|
|
|
|
0
|
|
167
|
|
|
|
|
|
|
}
|
168
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
#############
|
170
|
|
|
|
|
|
|
# READ_DATA #
|
171
|
|
|
|
|
|
|
#############
|
172
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
sub read_data {
|
174
|
1
|
|
|
1
|
0
|
3
|
my $in = shift ;
|
175
|
1
|
|
|
|
|
1
|
my ($data , $file , $fh) ;
|
176
|
|
|
|
|
|
|
|
177
|
1
|
50
|
33
|
|
|
14
|
if ( ref($in) eq 'GLOB' ) { $fh = $in ;}
|
|
0
|
50
|
|
|
|
0
|
|
178
|
|
|
|
|
|
|
elsif ( $in !~ /[\r\n]/s && -e $in ) {
|
179
|
0
|
|
|
|
|
0
|
$file = $in ;
|
180
|
0
|
|
|
|
|
0
|
open ($fh,$in) ; binmode($fh) ;
|
|
0
|
|
|
|
|
0
|
|
181
|
|
|
|
|
|
|
}
|
182
|
|
|
|
|
|
|
|
183
|
1
|
50
|
|
|
|
6
|
if ( $fh ) {
|
|
|
50
|
|
|
|
|
|
184
|
0
|
|
|
|
|
0
|
1 while( read($fh , $data , 1024*8 , length($data) ) ) ;
|
185
|
|
|
|
|
|
|
}
|
186
|
1
|
|
|
|
|
2
|
elsif ($in =~ /[<>\r\n]/s) { $data = $in ;}
|
187
|
|
|
|
|
|
|
|
188
|
1
|
|
|
|
|
4
|
$data =~ s/\r\n?/\n/gs ;
|
189
|
|
|
|
|
|
|
|
190
|
1
|
50
|
|
|
|
5
|
return( $data , $file ) if wantarray ;
|
191
|
0
|
|
|
|
|
0
|
return $data ;
|
192
|
|
|
|
|
|
|
}
|
193
|
|
|
|
|
|
|
|
194
|
|
|
|
|
|
|
#########
|
195
|
|
|
|
|
|
|
# REVAL #
|
196
|
|
|
|
|
|
|
#########
|
197
|
|
|
|
|
|
|
|
198
|
|
|
|
|
|
|
sub reval {
|
199
|
1
|
50
|
|
1
|
0
|
5
|
if ( !$EVAL_VALUES_COMPARTMENT ) {
|
200
|
1
|
|
|
|
|
10
|
$EVAL_VALUES_COMPARTMENT = Safe->new('Config::XMLPerl::EVAL') ;
|
201
|
1
|
|
|
|
|
1081
|
$EVAL_VALUES_COMPARTMENT->permit_only(@PERMIT_OPS) ;
|
202
|
|
|
|
|
|
|
}
|
203
|
0
|
|
|
|
|
0
|
return $EVAL_VALUES_COMPARTMENT->reval(@_) ;
|
204
|
|
|
|
|
|
|
}
|
205
|
|
|
|
|
|
|
|
206
|
|
|
|
|
|
|
###############
|
207
|
|
|
|
|
|
|
# CLEAN_CACHE #
|
208
|
|
|
|
|
|
|
###############
|
209
|
|
|
|
|
|
|
|
210
|
|
|
|
|
|
|
sub CLEAN_CACHE {
|
211
|
1
|
|
|
1
|
0
|
4
|
%CACHE = () ;
|
212
|
1
|
|
|
|
|
7
|
$CACHE_SLEEP = undef ;
|
213
|
|
|
|
|
|
|
}
|
214
|
|
|
|
|
|
|
|
215
|
|
|
|
|
|
|
#######
|
216
|
|
|
|
|
|
|
# END #
|
217
|
|
|
|
|
|
|
#######
|
218
|
|
|
|
|
|
|
|
219
|
1
|
|
|
1
|
|
832
|
sub END { &CLEAN_CACHE ;}
|
220
|
|
|
|
|
|
|
|
221
|
|
|
|
|
|
|
#######
|
222
|
|
|
|
|
|
|
# END #
|
223
|
|
|
|
|
|
|
#######
|
224
|
|
|
|
|
|
|
|
225
|
|
|
|
|
|
|
1;
|
226
|
|
|
|
|
|
|
|
227
|
|
|
|
|
|
|
|
228
|
|
|
|
|
|
|
__END__
|