xs/node.xs

filter: Statementstmt 96.2% 103 / 107 Branchbran 87.1% 54 / 62 Conditioncond n/a MC/DCmcdc n/a Subroutinesub n/a Podpod n/a totaltotal 92.9% 157 / 169 CC 0 SCAR 0
CC
0
Cov
0%
CRAP 0
« include/frx/frx_c14n.h ↑ Summary include/frx/frx_ns.h »
1  
2 # File::Raw::XML::Node: every kind, distinguished by kind. Each method is
3 # a wrapper over a core tree function; the namespace argument is undef for
4 # any and '' for none, the ABI's NULL versus "".
5  
6 MODULE = File::Raw::XML PACKAGE = File::Raw::XML::Node
7  
8 IV
9 kind(self)
10 SV *self
11 CODE:
12 227 ▶ RETVAL = frx_node_from_sv(aTHX_ self, "kind", NULL)->kind;
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = frx_node_from_sv(aTHX_ self, "kind", NULL)->kind; 133 92 225
13 OUTPUT:
14 RETVAL
15  
16 SV *
17 ns(self)
18 SV *self
19 ALIAS:
20 prefix = 1
21 local = 2
22 name = 3
23 PREINIT:
24 const frx_node *n;
25 1367 const char *meth[] = { "ns", "prefix", "local", "name" };
26 CODE:
27 1367 n = frx_node_from_sv(aTHX_ self, meth[ix], NULL);
28 1365 switch (ix) {
29 2 case 1: RETVAL = frx_str_sv(aTHX_ &n->prefix); break;
30 125 case 2: RETVAL = frx_str_sv(aTHX_ &n->local); break;
31 88 case 3: RETVAL = frx_str_sv(aTHX_ &n->qname); break;
32 1150 default: RETVAL = frx_str_sv(aTHX_ &n->ns); break;
33 }
34 OUTPUT:
35 RETVAL
36  
37 SV *
38 attr(self, local)
39 SV *self
40 const char *local
41 PREINIT:
42 const frx_node *n;
43 const frx_str *v;
44 CODE:
45 760757 n = frx_node_from_sv(aTHX_ self, "attr", NULL);
46 760757 v = frx_attr_value(n, NULL, local);
47 760757 ▶ RETVAL = v ? frx_str_sv(aTHX_ v) : newSV(0);
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = v ? frx_str_sv(aTHX_ v) : newSV(0); 760756 1 760757
48 OUTPUT:
49 RETVAL
50  
51 SV *
52 attr_ns(self, ns, local)
53 SV *self
54 SV *ns
55 const char *local
56 PREINIT:
57 const frx_node *n;
58 const frx_str *v;
59 CODE:
60 6 n = frx_node_from_sv(aTHX_ self, "attr_ns", NULL);
61 6 v = frx_attr_value(n, frx_ns_arg(aTHX_ ns), local);
62 6 ▶ RETVAL = v ? frx_str_sv(aTHX_ v) : newSV(0);
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = v ? frx_str_sv(aTHX_ v) : newSV(0); 5 1 6
63 OUTPUT:
64 RETVAL
65  
66 SV *
67 attrs(self)
68 SV *self
69 PREINIT:
70 const frx_node *n;
71 AV *out;
72 int i;
73 CODE:
74 88 n = frx_node_from_sv(aTHX_ self, "attrs", NULL);
75 88 out = newAV();
76 115 ▶ for (i = 0; i < n->n_attrs; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < n->n_attrs; i++) { 27 88 115
77 27 AV *a = newAV();
78 27 av_push(a, frx_str_sv(aTHX_ &n->attrs[i].ns));
79 27 av_push(a, frx_str_sv(aTHX_ &n->attrs[i].prefix));
80 27 av_push(a, frx_str_sv(aTHX_ &n->attrs[i].local));
81 27 av_push(a, frx_str_sv(aTHX_ &n->attrs[i].value));
82 27 av_push(out, newRV_noinc((SV *)a));
83 }
84 88 RETVAL = newRV_noinc((SV *)out);
85 OUTPUT:
86 RETVAL
87  
88 void
89 children(self)
90 SV *self
91 ALIAS:
92 elements = 1
93 PREINIT:
94 const frx_node *n, *c;
95 SV *doc_iv;
96 PPCODE:
97 154 ▶ n = frx_node_from_sv(aTHX_ self, ix ? "elements" : "children", &doc_iv);
Branch: 1 branch
BranchTrueFalseTotal
n = frx_node_from_sv(aTHX_ self, ix ? "elements" : "children", &doc_iv); 69 85 154
98 348 ▶ for (c = n->first_child; c; c = c->next) {
Branch: 1 branch
BranchTrueFalseTotal
for (c = n->first_child; c; c = c->next) { 194 154 348
99 194 ▶ if (ix && c->kind != FRX_ELEMENT) continue;
Branch: 2 branches
BranchTrueFalseTotal
if (ix && c->kind != FRX_ELEMENT) continue; 112 82 194
if (ix && c->kind != FRX_ELEMENT) continue; 32 80 112
100 162 ▶ XPUSHs(sv_2mortal(frx_node_bless(aTHX_ doc_iv, c)));
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(sv_2mortal(frx_node_bless(aTHX_ doc_iv, c))); 0 162 162
101 }
102  
103 void
104 find(self, ns, local)
105 SV *self
106 SV *ns
107 const char *local
108 PREINIT:
109 const frx_node *n, *c;
110 SV *doc_iv;
111 const char *nsp;
112 PPCODE:
113 12 n = frx_node_from_sv(aTHX_ self, "find", &doc_iv);
114 12 nsp = frx_ns_arg(aTHX_ ns);
115 23 ▶ for (c = frx_find(n, nsp, local, NULL); c; c = frx_find(n, nsp, local, c))
Branch: 1 branch
BranchTrueFalseTotal
for (c = frx_find(n, nsp, local, NULL); c; c = frx_find(n, nsp, local, c)) 11 12 23
116 11 ▶ XPUSHs(sv_2mortal(frx_node_bless(aTHX_ doc_iv, c)));
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(sv_2mortal(frx_node_bless(aTHX_ doc_iv, c))); 0 11 11
117  
118 void
119 descendants(self, ns, local)
120 SV *self
121 SV *ns
122 const char *local
123 PREINIT:
124 const frx_node *n, *c;
125 SV *doc_iv;
126 const char *nsp;
127 PPCODE:
128 18 n = frx_node_from_sv(aTHX_ self, "descendants", &doc_iv);
129 18 nsp = frx_ns_arg(aTHX_ ns);
130 1202582 ▶ for (c = n->first_child; c; c = frx_walk_next(c, n))
Branch: 1 branch
BranchTrueFalseTotal
for (c = n->first_child; c; c = frx_walk_next(c, n)) 1202564 18 1202582
131 1202564 ▶ if (frx_node_matches(c, nsp, local))
Branch: 1 branch
BranchTrueFalseTotal
if (frx_node_matches(c, nsp, local)) 101226 1101338 1202564
132 101226 ▶ XPUSHs(sv_2mortal(frx_node_bless(aTHX_ doc_iv, c)));
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(sv_2mortal(frx_node_bless(aTHX_ doc_iv, c))); 0 101226 101226
133  
134 SV *
135 text(self)
136 SV *self
137 PREINIT:
138 const frx_node *n;
139 frx_buf b;
140 CODE:
141 127 n = frx_node_from_sv(aTHX_ self, "text", NULL);
142 127 frx_buf_init(&b);
143 127 frx_text(n, &b);
144 127 ▶ if (b.failed) { frx_buf_free(&b); croak("File::Raw::XML: text: out of memory"); }
Branch: 1 branch
BranchTrueFalseTotal
if (b.failed) { frx_buf_free(&b); croak("File::Raw::XML: text: out of memory"); } 0 127 127
145 127 ▶ RETVAL = newSVpvn(b.p ? b.p : "", b.len);
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = newSVpvn(b.p ? b.p : "", b.len); 121 6 127
146 127 SvUTF8_on(RETVAL);
147 127 frx_buf_free(&b);
148 OUTPUT:
149 RETVAL
150  
151 SV *
152 parent(self)
153 SV *self
154 PREINIT:
155 const frx_node *n;
156 SV *doc_iv;
157 CODE:
158 215 n = frx_node_from_sv(aTHX_ self, "parent", &doc_iv);
159 215 ▶ RETVAL = n->parent ? frx_node_bless(aTHX_ doc_iv, n->parent) : newSV(0);
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = n->parent ? frx_node_bless(aTHX_ doc_iv, n->parent) : newSV(0); 210 5 215
160 OUTPUT:
161 RETVAL
162  
163 SV *
164 doc(self)
165 SV *self
166 PREINIT:
167 SV *doc_iv;
168 CODE:
169 7 (void)frx_node_from_sv(aTHX_ self, "doc", &doc_iv);
170 7 RETVAL = frx_node_doc_rv(aTHX_ doc_iv);
171 OUTPUT:
172 RETVAL
173  
174 SV *
175 to_string(self, ...)
176 SV *self
177 PREINIT:
178 const frx_node *n;
179 SV *doc_iv;
180 HV *opts;
181 frx_write_opts o;
182 int perl_chars;
183 CODE:
184 25 n = frx_node_from_sv(aTHX_ self, "to_string", &doc_iv);
185 25 opts = frx_opts_hv(aTHX_ &ST(0), 1, items, "to_string");
186 25 frx_write_opts_from_hv(aTHX_ opts, &o, &perl_chars, "to_string", 0);
187 25 RETVAL = frx_write_sv(aTHX_ n, frx_doc_from_iv(aTHX_ doc_iv), &o, perl_chars, "to_string");
188 OUTPUT:
189 RETVAL
190  
191 SV *
192 c14n(self, ...)
193 SV *self
194 PREINIT:
195 const frx_node *n;
196 SV *doc_iv;
197 HV *opts;
198 frx_c14n c;
199 CODE:
200 109 n = frx_node_from_sv(aTHX_ self, "c14n", &doc_iv);
201 109 opts = frx_opts_hv(aTHX_ &ST(0), 1, items, "c14n");
202 108 frx_c14n_opts(aTHX_ opts, doc_iv, &c, "c14n");
203 103 RETVAL = frx_c14n_sv(aTHX_ n, &c, "c14n");
204 OUTPUT:
205 RETVAL
206  
207 # ---- editing: every method returns the node it acted on or made
208  
209 SV *
210 append(self, child)
211 SV *self
212 SV *child
213 ALIAS:
214 insert_before = 1
215 PREINIT:
216 frx_node *n, *c;
217 SV *doc_iv;
218 frx_doc *d;
219 frx_err e;
220 int ok;
221 CODE:
222 41 ▶ n = (frx_node *)frx_node_from_sv(aTHX_ self, ix ? "insert_before" : "append", &doc_iv);
Branch: 1 branch
BranchTrueFalseTotal
n = (frx_node *)frx_node_from_sv(aTHX_ self, ix ? "insert_before" : "append", &doc_iv); 5 36 41
223 41 d = frx_doc_from_iv(aTHX_ doc_iv);
224 41 ▶ c = frx_node_arg(aTHX_ child, doc_iv, ix ? "insert_before" : "append");
Branch: 1 branch
BranchTrueFalseTotal
c = frx_node_arg(aTHX_ child, doc_iv, ix ? "insert_before" : "append"); 5 36 41
225 40 ▶ ok = ix ? frx_insert_before(d, n, c, &e) : frx_append_child(d, n, c, &e);
Branch: 1 branch
BranchTrueFalseTotal
ok = ix ? frx_insert_before(d, n, c, &e) : frx_append_child(d, n, c, &e); 5 35 40
226 40 ▶ if (!ok) frx_edit_croak(aTHX_ ix ? "insert_before" : "append", &e);
Branch: 2 branches
BranchTrueFalseTotal
if (!ok) frx_edit_croak(aTHX_ ix ? "insert_before" : "append", &e); 7 33 40
if (!ok) frx_edit_croak(aTHX_ ix ? "insert_before" : "append", &e); 1 6 7
227 33 RETVAL = frx_node_bless(aTHX_ doc_iv, c);
228 OUTPUT:
229 RETVAL
230  
231 SV *
232 detach(self)
233 SV *self
234 PREINIT:
235 frx_node *n;
236 SV *doc_iv;
237 frx_err e;
238 CODE:
239 9 n = (frx_node *)frx_node_from_sv(aTHX_ self, "detach", &doc_iv);
240 9 ▶ if (!frx_remove(frx_doc_from_iv(aTHX_ doc_iv), n, &e)) frx_edit_croak(aTHX_ "detach", &e);
Branch: 1 branch
BranchTrueFalseTotal
if (!frx_remove(frx_doc_from_iv(aTHX_ doc_iv), n, &e)) frx_edit_croak(aTHX_ "detach", &e); 1 8 9
241 8 RETVAL = frx_node_bless(aTHX_ doc_iv, n);
242 OUTPUT:
243 RETVAL
244  
245 SV *
246 set_attr(self, ns, name, value)
247 SV *self
248 SV *ns
249 SV *name
250 SV *value
251 PREINIT:
252 frx_node *n;
253 SV *doc_iv;
254 frx_err e;
255 STRLEN nslen, nlen, plen, llen, vlen;
256 const char *nsp, *namep, *prefix, *local, *v;
257 CODE:
258 16 n = (frx_node *)frx_node_from_sv(aTHX_ self, "set_attr", &doc_iv);
259 16 nsp = frx_arg_bytes(aTHX_ ns, &nslen);
260 16 namep = frx_arg_bytes(aTHX_ name, &nlen);
261 16 v = frx_arg_bytes(aTHX_ value, &vlen);
262 16 frx_split_arg(namep, nlen, &prefix, &plen, &local, &llen);
263 16 ▶ if (!frx_set_attr(frx_doc_from_iv(aTHX_ doc_iv), n, nsp, nslen, prefix, plen, local, llen, v, vlen, &e))
Branch: 1 branch
BranchTrueFalseTotal
if (!frx_set_attr(frx_doc_from_iv(aTHX_ doc_iv), n, nsp, nslen, prefix, plen, local, llen, v, vlen, &e)) 3 13 16
264 3 frx_edit_croak(aTHX_ "set_attr", &e);
265 13 RETVAL = frx_node_bless(aTHX_ doc_iv, n);
266 OUTPUT:
267 RETVAL
268  
269 SV *
270 remove_attr(self, ns, local)
271 SV *self
272 SV *ns
273 SV *local
274 PREINIT:
275 frx_node *n;
276 SV *doc_iv;
277 frx_err e;
278 STRLEN nslen, llen;
279 const char *nsp, *l;
280 CODE:
281 4 n = (frx_node *)frx_node_from_sv(aTHX_ self, "remove_attr", &doc_iv);
282 4 nsp = frx_arg_bytes(aTHX_ ns, &nslen);
283 4 l = frx_arg_bytes(aTHX_ local, &llen);
284 4 ▶ if (!frx_remove_attr(frx_doc_from_iv(aTHX_ doc_iv), n, nsp, nslen, l, llen, &e))
Branch: 1 branch
BranchTrueFalseTotal
if (!frx_remove_attr(frx_doc_from_iv(aTHX_ doc_iv), n, nsp, nslen, l, llen, &e)) 0 4 4
285 0 frx_edit_croak(aTHX_ "remove_attr", &e);
286 4 RETVAL = frx_node_bless(aTHX_ doc_iv, n);
287 OUTPUT:
288 RETVAL
289  
290 SV *
291 set_text(self, text)
292 SV *self
293 SV *text
294 PREINIT:
295 frx_node *n;
296 SV *doc_iv;
297 frx_err e;
298 STRLEN len;
299 const char *s;
300 CODE:
301 14 n = (frx_node *)frx_node_from_sv(aTHX_ self, "set_text", &doc_iv);
302 14 s = frx_arg_bytes(aTHX_ text, &len);
303 14 ▶ if (!frx_set_text(frx_doc_from_iv(aTHX_ doc_iv), n, s, len, &e)) frx_edit_croak(aTHX_ "set_text", &e);
Branch: 1 branch
BranchTrueFalseTotal
if (!frx_set_text(frx_doc_from_iv(aTHX_ doc_iv), n, s, len, &e)) frx_edit_croak(aTHX_ "set_text", &e); 3 11 14
304 11 RETVAL = frx_node_bless(aTHX_ doc_iv, n);
305 OUTPUT:
306 RETVAL
307  
308 SV *
309 declare_ns(self, prefix, uri)
310 SV *self
311 SV *prefix
312 SV *uri
313 PREINIT:
314 frx_node *n;
315 SV *doc_iv;
316 frx_err e;
317 STRLEN plen, ulen;
318 const char *p, *u;
319 CODE:
320 6 n = (frx_node *)frx_node_from_sv(aTHX_ self, "declare_ns", &doc_iv);
321 6 p = frx_arg_bytes(aTHX_ prefix, &plen);
322 6 u = frx_arg_bytes(aTHX_ uri, &ulen);
323 6 ▶ if (!frx_declare_ns(frx_doc_from_iv(aTHX_ doc_iv), n, p, plen, u, ulen, &e)) frx_edit_croak(aTHX_ "declare_ns", &e);
Branch: 1 branch
BranchTrueFalseTotal
if (!frx_declare_ns(frx_doc_from_iv(aTHX_ doc_iv), n, p, plen, u, ulen, &e)) frx_edit_croak(aTHX_ "declare_ns", &e); 4 2 6
324 2 RETVAL = frx_node_bless(aTHX_ doc_iv, n);
325 OUTPUT:
326 RETVAL
327  
328 SV *
329 set_name(self, ns, name)
330 SV *self
331 SV *ns
332 SV *name
333 PREINIT:
334 frx_node *n;
335 SV *doc_iv;
336 frx_err e;
337 STRLEN nslen, nlen, plen, llen;
338 const char *nsp, *namep, *prefix, *local;
339 CODE:
340 1 n = (frx_node *)frx_node_from_sv(aTHX_ self, "set_name", &doc_iv);
341 1 nsp = frx_arg_bytes(aTHX_ ns, &nslen);
342 1 namep = frx_arg_bytes(aTHX_ name, &nlen);
343 1 frx_split_arg(namep, nlen, &prefix, &plen, &local, &llen);
344 1 ▶ if (!frx_set_name(frx_doc_from_iv(aTHX_ doc_iv), n, nsp, nslen, prefix, plen, local, llen, &e))
Branch: 1 branch
BranchTrueFalseTotal
if (!frx_set_name(frx_doc_from_iv(aTHX_ doc_iv), n, nsp, nslen, prefix, plen, local, llen, &e)) 0 1 1
345 0 frx_edit_croak(aTHX_ "set_name", &e);
346 1 RETVAL = frx_node_bless(aTHX_ doc_iv, n);
347 OUTPUT:
348 RETVAL
349  
350 # ---- the xml: attributes ---------------------------------------------------
351  
352 SV *
353 base_uri(self)
354 SV *self
355 PREINIT:
356 const frx_node *n;
357 SV *doc_iv;
358 frx_buf b;
359 CODE:
360 13 n = frx_node_from_sv(aTHX_ self, "base_uri", &doc_iv);
361 13 frx_buf_init(&b);
362 13 ▶ if (!frx_node_base_uri(n, frx_doc_from_iv(aTHX_ doc_iv), &b)) {
Branch: 1 branch
BranchTrueFalseTotal
if (!frx_node_base_uri(n, frx_doc_from_iv(aTHX_ doc_iv), &b)) { 0 13 13
363 0 frx_buf_free(&b);
364 0 croak("File::Raw::XML: base_uri: out of memory");
365 }
366 13 ▶ RETVAL = newSVpvn(b.p ? b.p : "", b.len);
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = newSVpvn(b.p ? b.p : "", b.len); 13 0 13
367 13 SvUTF8_on(RETVAL);
368 13 frx_buf_free(&b);
369 OUTPUT:
370 RETVAL
371  
372 SV *
373 lang(self)
374 SV *self
375 PREINIT:
376 const frx_node *n;
377 frx_str v;
378 CODE:
379 7 n = frx_node_from_sv(aTHX_ self, "lang", NULL);
380 7 v = frx_node_lang(n);
381 7 ▶ RETVAL = v.len ? frx_str_sv(aTHX_ &v) : newSV(0);
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = v.len ? frx_str_sv(aTHX_ &v) : newSV(0); 5 2 7
382 OUTPUT:
383 RETVAL
384  
385 SV *
386 space(self)
387 SV *self
388 CODE:
389 6 RETVAL = newSVpv(frx_node_space(frx_node_from_sv(aTHX_ self, "space", NULL)), 0);
390 OUTPUT:
391 RETVAL
« include/frx/frx_c14n.h ↑ Summary include/frx/frx_ns.h »