blib/lib/Data/Stag.pm

filter: Statementstmt 80.0% 44 / 55 Branchbran 16.6% 1 / 6 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 58.8% 10 / 17 Podpod 11.1% 1 / 9 totaltotal 64.3% 56 / 87 CC 4 SCAR 8.6
CC
4
Cov
74%
DEBUG
6.0
IMPL
6.0
AUTOLOAD
2.0
CRAP 2.4
« blib/lib/Data/Stag/XMLParser.pm ↑ Summary blib/lib/Data/Stag/ITextWriter.pm »
1 # $Id: Stag.pm,v 1.41 2007/10/15 04:08:45 cmungall Exp $
2 # -------------------------------------------------------
3 #
4 # Copyright (C) 2004 Chris Mungall <cjm@fruitfly.org>
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 20 require 5.006;
18 20 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 20 ▶use vars qw(@ISA @EXPORT_OK %EXPORT_TAGS $DEBUG $AUTOLOAD @AUTOMETHODS @OLD);
Subroutine BEGIN: called CC=1 SCAR=0.0
20 20 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
21 20 ▶use Data::Stag::Base;
Subroutine BEGIN: called CC=1 SCAR=0.0
22  
23 20 ▶use vars qw($VERSION);
Subroutine BEGIN: called CC=1 SCAR=0.0
24 20 $VERSION="0.14";
25  
26 20 @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 20 "stag_$_"
93 } @AUTOMETHODS
94 ),
95 qw(
96 Node
97 stag_unflatten
98 stag_nodify
99 stag_load
100 stag_loadxml
101 )
102 );
103 20 %EXPORT_TAGS = (all => [@EXPORT_OK],
104 lazy => [@EXPORT_OK,
105 @AUTOMETHODS]);
106 20 @ISA = qw(Exporter);
107  
108 20 our $DEBUG;
109 20 our $IMPL = "Data::Stag::StagImpl";
110 20 ▶use Data::Stag::StagImpl;
Subroutine BEGIN: called CC=1 SCAR=0.0
111  
112 0 ▶sub DEBUG {
Subroutine DEBUG: not called CC=2 SCAR=17.9
Pod undocumented
113 0 ▶ $DEBUG = shift if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 0 0 0
114 0 return $DEBUG;
115 }
116  
117 0 ▶sub IMPL {
Subroutine IMPL: not called CC=2 SCAR=17.9
Pod undocumented
118 0 ▶ $IMPL = shift if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 0 0 0
119 0 return $IMPL;
120 }
121  
122 # OO usage
123 180 ▶sub new {
Subroutine new: called CC=1 SCAR=0.0
Pod documented
124 180 shift;
125 180 return $IMPL->new(@_);
126 }
127 # procedural usage
128 0 ▶sub stag_new {
Subroutine stag_new: not called CC=1 SCAR=6.9
Pod undocumented
129 0 return $IMPL->new(@_);
130 }
131 20 *Node = \&stag_new;
132 20 *node = \&stag_new;
133  
134 0 ▶sub stag_from {
Subroutine stag_from: not called CC=1 SCAR=6.9
Pod undocumented
135 0 return $IMPL->from(@_);
136 }
137  
138 0 ▶sub stag_load {
Subroutine stag_load: not called CC=1 SCAR=6.9
Pod undocumented
139 0 my $node = stag_new();
140 0 return $node->parse(@_);
141 }
142  
143 0 ▶sub stag_loadxml {
Subroutine stag_loadxml: not called CC=1 SCAR=6.9
Pod undocumented
144 0 return $IMPL->from('xml', @_);
145 }
146  
147 1067 ▶sub stag_nodify {
Subroutine stag_nodify: called CC=1 SCAR=0.0
Pod undocumented
148 1067 bless shift, $IMPL;
149 }
150  
151 # allows entering trees like this
152 # [tag=>val, tag=>val, tag=>val]
153 0 ▶sub stag_unflatten {
Subroutine stag_unflatten: not called CC=1 SCAR=6.9
Pod undocumented
154 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 ▶no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
167 49 ▶sub AUTOLOAD {
Subroutine AUTOLOAD: called CC=2 SCAR=7.1
168 49 my @args = @_;
169  
170 49 my $name = $AUTOLOAD;
171 49 $name =~ s/.*://; # strip fully-qualified portion
172 49 $name =~ s/^stag//;
173 49 $name =~ s/_//g;
174  
175 # make it all lower case
176 49 ▶ unless (UNIVERSAL::can($IMPL, $name)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (UNIVERSAL::can($Data::Stag::IMPL, $name)) 0 49 49
177 0 $name = lc($name);
178 }
179 49 my $meth = $IMPL.'::'.$name;
180
181 49 &$meth(@args);
182 }
183  
184 20 1;
185  
186 __END__
« blib/lib/Data/Stag/XMLParser.pm ↑ Summary blib/lib/Data/Stag/ITextWriter.pm »