| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
# $Id: Stag.pm,v 1.41 2007/10/15 04:08:45 cmungall Exp $ |
|
2
|
|
|
|
|
|
|
# ------------------------------------------------------- |
|
3
|
|
|
|
|
|
|
# |
|
4
|
|
|
|
|
|
|
# Copyright (C) 2004 Chris Mungall |
|
5
|
|
|
|
|
|
|
# |
|
6
|
|
|
|
|
|
|
# See also - http://stag.sourceforge.net |
|
7
|
|
|
|
|
|
|
# |
|
8
|
|
|
|
|
|
|
# This module is free software. |
|
9
|
|
|
|
|
|
|
# You may distribute this module under the same terms as perl itself |
|
10
|
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
#--- |
|
12
|
|
|
|
|
|
|
# POD docs at end of file |
|
13
|
|
|
|
|
|
|
#--- |
|
14
|
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
package Data::Stag; |
|
16
|
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
require 5.006; |
|
18
|
20
|
|
|
20
|
|
237906
|
use strict; |
|
|
20
|
|
|
|
|
52
|
|
|
|
20
|
|
|
|
|
1698
|
|
|
19
|
20
|
|
|
20
|
|
286
|
use vars qw(@ISA @EXPORT_OK %EXPORT_TAGS $DEBUG $AUTOLOAD @AUTOMETHODS @OLD); |
|
|
20
|
|
|
|
|
41
|
|
|
|
20
|
|
|
|
|
4273
|
|
|
20
|
20
|
|
|
20
|
|
110
|
use Carp; |
|
|
20
|
|
|
|
|
42
|
|
|
|
20
|
|
|
|
|
2495
|
|
|
21
|
20
|
|
|
20
|
|
11746
|
use Data::Stag::Base; |
|
|
20
|
|
|
|
|
60
|
|
|
|
20
|
|
|
|
|
1136
|
|
|
22
|
|
|
|
|
|
|
|
|
23
|
20
|
|
|
20
|
|
120
|
use vars qw($VERSION); |
|
|
20
|
|
|
|
|
34
|
|
|
|
20
|
|
|
|
|
3929
|
|
|
24
|
|
|
|
|
|
|
$VERSION="0.14"; |
|
25
|
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
@AUTOMETHODS = qw( |
|
27
|
|
|
|
|
|
|
new |
|
28
|
|
|
|
|
|
|
node |
|
29
|
|
|
|
|
|
|
nodify stagify |
|
30
|
|
|
|
|
|
|
unflatten |
|
31
|
|
|
|
|
|
|
from |
|
32
|
|
|
|
|
|
|
f find |
|
33
|
|
|
|
|
|
|
fn findnode |
|
34
|
|
|
|
|
|
|
fvl findvallist |
|
35
|
|
|
|
|
|
|
fv findval |
|
36
|
|
|
|
|
|
|
fvl findvallist |
|
37
|
|
|
|
|
|
|
sfv sfindval |
|
38
|
|
|
|
|
|
|
g get |
|
39
|
|
|
|
|
|
|
sg sget scalarget |
|
40
|
|
|
|
|
|
|
gl getl getlist |
|
41
|
|
|
|
|
|
|
gn getn getnode |
|
42
|
|
|
|
|
|
|
sgetmap sgm |
|
43
|
|
|
|
|
|
|
s set |
|
44
|
|
|
|
|
|
|
setl |
|
45
|
|
|
|
|
|
|
u unset |
|
46
|
|
|
|
|
|
|
free |
|
47
|
|
|
|
|
|
|
a add |
|
48
|
|
|
|
|
|
|
e element name |
|
49
|
|
|
|
|
|
|
k kids children |
|
50
|
|
|
|
|
|
|
ak addkid addchild |
|
51
|
|
|
|
|
|
|
subnodes |
|
52
|
|
|
|
|
|
|
tnodes |
|
53
|
|
|
|
|
|
|
ntnodes |
|
54
|
|
|
|
|
|
|
isterminal |
|
55
|
|
|
|
|
|
|
j ij ijoin nj njoin |
|
56
|
|
|
|
|
|
|
paste |
|
57
|
|
|
|
|
|
|
qm qmatch |
|
58
|
|
|
|
|
|
|
tm tmatch |
|
59
|
|
|
|
|
|
|
tmh tmatchhash |
|
60
|
|
|
|
|
|
|
tmn tmatchnode |
|
61
|
|
|
|
|
|
|
cm cmatch |
|
62
|
|
|
|
|
|
|
w where |
|
63
|
|
|
|
|
|
|
iterate |
|
64
|
|
|
|
|
|
|
run |
|
65
|
|
|
|
|
|
|
collapse |
|
66
|
|
|
|
|
|
|
merge |
|
67
|
|
|
|
|
|
|
d duplicate |
|
68
|
|
|
|
|
|
|
isanode |
|
69
|
|
|
|
|
|
|
parser |
|
70
|
|
|
|
|
|
|
parse parsefile |
|
71
|
|
|
|
|
|
|
parsestr |
|
72
|
|
|
|
|
|
|
generate gen write |
|
73
|
|
|
|
|
|
|
makehandler mh |
|
74
|
|
|
|
|
|
|
findhandler |
|
75
|
|
|
|
|
|
|
getformathandler |
|
76
|
|
|
|
|
|
|
chainhandlers |
|
77
|
|
|
|
|
|
|
xml |
|
78
|
|
|
|
|
|
|
sxpr |
|
79
|
|
|
|
|
|
|
itext |
|
80
|
|
|
|
|
|
|
indent |
|
81
|
|
|
|
|
|
|
hash tree2hash |
|
82
|
|
|
|
|
|
|
pairs tree2pairs |
|
83
|
|
|
|
|
|
|
sax tree2sax |
|
84
|
|
|
|
|
|
|
xp xpath tree2xpath |
|
85
|
|
|
|
|
|
|
xpq xpquery xpathquery |
|
86
|
|
|
|
|
|
|
); |
|
87
|
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
@EXPORT_OK = |
|
90
|
|
|
|
|
|
|
(( |
|
91
|
|
|
|
|
|
|
map { |
|
92
|
|
|
|
|
|
|
"stag_$_" |
|
93
|
|
|
|
|
|
|
} @AUTOMETHODS |
|
94
|
|
|
|
|
|
|
), |
|
95
|
|
|
|
|
|
|
qw( |
|
96
|
|
|
|
|
|
|
Node |
|
97
|
|
|
|
|
|
|
stag_unflatten |
|
98
|
|
|
|
|
|
|
stag_nodify |
|
99
|
|
|
|
|
|
|
stag_load |
|
100
|
|
|
|
|
|
|
stag_loadxml |
|
101
|
|
|
|
|
|
|
) |
|
102
|
|
|
|
|
|
|
); |
|
103
|
|
|
|
|
|
|
%EXPORT_TAGS = (all => [@EXPORT_OK], |
|
104
|
|
|
|
|
|
|
lazy => [@EXPORT_OK, |
|
105
|
|
|
|
|
|
|
@AUTOMETHODS]); |
|
106
|
|
|
|
|
|
|
@ISA = qw(Exporter); |
|
107
|
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
our $DEBUG; |
|
109
|
|
|
|
|
|
|
our $IMPL = "Data::Stag::StagImpl"; |
|
110
|
20
|
|
|
20
|
|
18751
|
use Data::Stag::StagImpl; |
|
|
20
|
|
|
|
|
116
|
|
|
|
20
|
|
|
|
|
6345
|
|
|
111
|
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
sub DEBUG { |
|
113
|
0
|
0
|
|
0
|
0
|
0
|
$DEBUG = shift if @_; |
|
114
|
0
|
|
|
|
|
0
|
return $DEBUG; |
|
115
|
|
|
|
|
|
|
} |
|
116
|
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
sub IMPL { |
|
118
|
0
|
0
|
|
0
|
0
|
0
|
$IMPL = shift if @_; |
|
119
|
0
|
|
|
|
|
0
|
return $IMPL; |
|
120
|
|
|
|
|
|
|
} |
|
121
|
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
# OO usage |
|
123
|
|
|
|
|
|
|
sub new { |
|
124
|
180
|
|
|
180
|
1
|
676
|
shift; |
|
125
|
180
|
|
|
|
|
679
|
return $IMPL->new(@_); |
|
126
|
|
|
|
|
|
|
} |
|
127
|
|
|
|
|
|
|
# procedural usage |
|
128
|
|
|
|
|
|
|
sub stag_new { |
|
129
|
0
|
|
|
0
|
0
|
0
|
return $IMPL->new(@_); |
|
130
|
|
|
|
|
|
|
} |
|
131
|
|
|
|
|
|
|
*Node = \&stag_new; |
|
132
|
|
|
|
|
|
|
*node = \&stag_new; |
|
133
|
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
sub stag_from { |
|
135
|
0
|
|
|
0
|
0
|
0
|
return $IMPL->from(@_); |
|
136
|
|
|
|
|
|
|
} |
|
137
|
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
sub stag_load { |
|
139
|
0
|
|
|
0
|
0
|
0
|
my $node = stag_new(); |
|
140
|
0
|
|
|
|
|
0
|
return $node->parse(@_); |
|
141
|
|
|
|
|
|
|
} |
|
142
|
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
sub stag_loadxml { |
|
144
|
0
|
|
|
0
|
0
|
0
|
return $IMPL->from('xml', @_); |
|
145
|
|
|
|
|
|
|
} |
|
146
|
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
sub stag_nodify { |
|
148
|
1067
|
|
|
1067
|
0
|
4190
|
bless shift, $IMPL; |
|
149
|
|
|
|
|
|
|
} |
|
150
|
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
# allows entering trees like this |
|
152
|
|
|
|
|
|
|
# [tag=>val, tag=>val, tag=>val] |
|
153
|
|
|
|
|
|
|
sub stag_unflatten { |
|
154
|
0
|
|
|
0
|
0
|
0
|
return $IMPL->unflatten(@_); |
|
155
|
|
|
|
|
|
|
} |
|
156
|
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
#sub xml2tree { |
|
158
|
|
|
|
|
|
|
# warn("DEPRECATED: xml2tree"); |
|
159
|
|
|
|
|
|
|
# stag_from('xml', @_); |
|
160
|
|
|
|
|
|
|
#} |
|
161
|
|
|
|
|
|
|
#sub tree2xml { |
|
162
|
|
|
|
|
|
|
# warn("DEPRECATED: tree2xml"); |
|
163
|
|
|
|
|
|
|
# stag_xml(@_); |
|
164
|
|
|
|
|
|
|
#} |
|
165
|
|
|
|
|
|
|
|
|
166
|
20
|
|
|
20
|
|
228
|
no strict 'refs'; |
|
|
20
|
|
|
|
|
45
|
|
|
|
20
|
|
|
|
|
3968
|
|
|
167
|
|
|
|
|
|
|
sub AUTOLOAD { |
|
168
|
49
|
|
|
49
|
|
79448
|
my @args = @_; |
|
169
|
|
|
|
|
|
|
|
|
170
|
49
|
|
|
|
|
108
|
my $name = $AUTOLOAD; |
|
171
|
49
|
|
|
|
|
331
|
$name =~ s/.*://; # strip fully-qualified portion |
|
172
|
49
|
|
|
|
|
117
|
$name =~ s/^stag//; |
|
173
|
49
|
|
|
|
|
117
|
$name =~ s/_//g; |
|
174
|
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
# make it all lower case |
|
176
|
49
|
50
|
|
|
|
393
|
unless (UNIVERSAL::can($IMPL, $name)) { |
|
177
|
0
|
|
|
|
|
0
|
$name = lc($name); |
|
178
|
|
|
|
|
|
|
} |
|
179
|
49
|
|
|
|
|
160
|
my $meth = $IMPL.'::'.$name; |
|
180
|
|
|
|
|
|
|
|
|
181
|
49
|
|
|
|
|
298
|
&$meth(@args); |
|
182
|
|
|
|
|
|
|
} |
|
183
|
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
1; |
|
185
|
|
|
|
|
|
|
|
|
186
|
|
|
|
|
|
|
__END__ |