xs/document.xs

filter: Statementstmt 100% 66 / 66 Branchbran 75.0% 39 / 52 Conditioncond n/a MC/DCmcdc n/a Subroutinesub n/a Podpod n/a totaltotal 88.9% 105 / 118 CC 0 SCAR 0
CC
0
Cov
0%
CRAP 0
« include/frx/frx_enc.h ↑ Summary include/frx/frx_lex.h »
1  
2 # File::Raw::XML::Document: what a parse returns.
3  
4 MODULE = File::Raw::XML PACKAGE = File::Raw::XML::Document
5  
6 SV *
7 root(self)
8 SV *self
9 PREINIT:
10 frx_doc *d;
11 CODE:
12 761960 d = frx_doc_from_sv(aTHX_ self, "root");
13 761958 RETVAL = frx_node_bless(aTHX_ SvRV(self), d->root);
14 OUTPUT:
15 RETVAL
16  
17 SV *
18 document(self)
19 SV *self
20 PREINIT:
21 frx_doc *d;
22 CODE:
23 31 d = frx_doc_from_sv(aTHX_ self, "document");
24 31 RETVAL = frx_node_bless(aTHX_ SvRV(self), d->document);
25 OUTPUT:
26 RETVAL
27  
28 SV *
29 by_id(self, attr, value)
30 SV *self
31 const char *attr
32 SV *value
33 PREINIT:
34 frx_doc *d;
35 const frx_node *n;
36 STRLEN vlen;
37 const char *v;
38 CODE:
39 37 d = frx_doc_from_sv(aTHX_ self, "by_id");
40 37 v = frx_input(aTHX_ value, &vlen);
41 37 n = frx_by_id(d, attr, v, (size_t)vlen);
42 37 ▶ RETVAL = n ? frx_node_bless(aTHX_ SvRV(self), n) : newSV(0);
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = n ? frx_node_bless(aTHX_ SvRV(self), n) : newSV(0); 24 13 37
43 OUTPUT:
44 RETVAL
45  
46 SV *
47 version(self)
48 SV *self
49 PREINIT:
50 frx_doc *d;
51 CODE:
52 6 d = frx_doc_from_sv(aTHX_ self, "version");
53 6 RETVAL = newSVpvn(d->version.p, d->version.len);
54 OUTPUT:
55 RETVAL
56  
57 IV
58 standalone(self)
59 SV *self
60 PREINIT:
61 frx_doc *d;
62 CODE:
63 2 d = frx_doc_from_sv(aTHX_ self, "standalone");
64 2 ▶ RETVAL = d->standalone ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = d->standalone ? 1 : 0; 0 2 2
65 OUTPUT:
66 RETVAL
67  
68 SV *
69 doctype(self)
70 SV *self
71 PREINIT:
72 frx_doc *d;
73 HV *hv;
74 CODE:
75 /* { name, public_id, system_id, internal_subset }, the ids and the
76 * subset undef when the declaration had none; undef with no DOCTYPE */
77 8 d = frx_doc_from_sv(aTHX_ self, "doctype");
78 PERL_UNUSED_VAR(hv);
79 8 RETVAL = frx_doctype_sv(aTHX_ d->doctype);
80 OUTPUT:
81 RETVAL
82  
83 SV *
84 to_string(self, ...)
85 SV *self
86 PREINIT:
87 frx_doc *d;
88 HV *opts;
89 frx_write_opts o;
90 int perl_chars;
91 CODE:
92 1711 d = frx_doc_from_sv(aTHX_ self, "to_string");
93 1711 opts = frx_opts_hv(aTHX_ &ST(0), 1, items, "to_string");
94 1711 frx_write_opts_from_hv(aTHX_ opts, &o, &perl_chars, "to_string", 1);
95 1708 RETVAL = frx_write_sv(aTHX_ d->document, d, &o, perl_chars, "to_string");
96 OUTPUT:
97 RETVAL
98  
99 IV
100 equals(self, other)
101 SV *self
102 SV *other
103 PREINIT:
104 frx_doc *a, *b;
105 CODE:
106 1691 a = frx_doc_from_sv(aTHX_ self, "equals");
107 1691 b = frx_doc_from_sv(aTHX_ other, "equals");
108 1690 ▶ RETVAL = frx_tree_equal(a->document, b->document) ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = frx_tree_equal(a->document, b->document) ? 1 : 0; 1675 15 1690
109 OUTPUT:
110 RETVAL
111  
112 SV *
113 c14n(self, ...)
114 SV *self
115 PREINIT:
116 frx_doc *d;
117 HV *opts;
118 frx_c14n c;
119 CODE:
120 2605 d = frx_doc_from_sv(aTHX_ self, "c14n");
121 2605 opts = frx_opts_hv(aTHX_ &ST(0), 1, items, "c14n");
122 2605 frx_c14n_opts(aTHX_ opts, SvRV(self), &c, "c14n");
123 2605 RETVAL = frx_c14n_sv(aTHX_ d->document, &c, "c14n");
124 OUTPUT:
125 RETVAL
126  
127 # ---- building and editing -------------------------------------------------
128  
129 SV *
130 new_element(self, ns, name)
131 SV *self
132 SV *ns
133 SV *name
134 PREINIT:
135 frx_doc *d;
136 frx_node *n;
137 frx_err e;
138 STRLEN nslen, nlen, plen, llen;
139 const char *nsp, *namep, *prefix, *local;
140 CODE:
141 36 d = frx_doc_from_sv(aTHX_ self, "new_element");
142 36 nsp = frx_arg_bytes(aTHX_ ns, &nslen);
143 36 namep = frx_arg_bytes(aTHX_ name, &nlen);
144 36 frx_split_arg(namep, nlen, &prefix, &plen, &local, &llen);
145 36 n = frx_new_element(d, nsp, nslen, prefix, plen, local, llen, &e);
146 36 ▶ if (!n) frx_edit_croak(aTHX_ "new_element", &e);
Branch: 1 branch
BranchTrueFalseTotal
if (!n) frx_edit_croak(aTHX_ "new_element", &e); 5 31 36
147 31 RETVAL = frx_node_bless(aTHX_ SvRV(self), n);
148 OUTPUT:
149 RETVAL
150  
151 SV *
152 new_text(self, text)
153 SV *self
154 SV *text
155 ALIAS:
156 new_comment = 1
157 PREINIT:
158 frx_doc *d;
159 frx_node *n;
160 frx_err e;
161 STRLEN len;
162 const char *s;
163 CODE:
164 6 ▶ d = frx_doc_from_sv(aTHX_ self, ix ? "new_comment" : "new_text");
Branch: 1 branch
BranchTrueFalseTotal
d = frx_doc_from_sv(aTHX_ self, ix ? "new_comment" : "new_text"); 2 4 6
165 6 s = frx_arg_bytes(aTHX_ text, &len);
166 6 ▶ n = ix ? frx_new_comment(d, s, len, &e) : frx_new_text(d, s, len, &e);
Branch: 1 branch
BranchTrueFalseTotal
n = ix ? frx_new_comment(d, s, len, &e) : frx_new_text(d, s, len, &e); 2 4 6
167 6 ▶ if (!n) frx_edit_croak(aTHX_ ix ? "new_comment" : "new_text", &e);
Branch: 2 branches
BranchTrueFalseTotal
if (!n) frx_edit_croak(aTHX_ ix ? "new_comment" : "new_text", &e); 1 5 6
if (!n) frx_edit_croak(aTHX_ ix ? "new_comment" : "new_text", &e); 0 1 1
168 5 RETVAL = frx_node_bless(aTHX_ SvRV(self), n);
169 OUTPUT:
170 RETVAL
171  
172 SV *
173 new_pi(self, target, ...)
174 SV *self
175 SV *target
176 PREINIT:
177 frx_doc *d;
178 frx_node *n;
179 frx_err e;
180 STRLEN tlen, dlen;
181 const char *t, *data;
182 CODE:
183 3 d = frx_doc_from_sv(aTHX_ self, "new_pi");
184 3 t = frx_arg_bytes(aTHX_ target, &tlen);
185 3 ▶ data = frx_arg_bytes(aTHX_ items > 2 ? ST(2) : NULL, &dlen);
Branch: 1 branch
BranchTrueFalseTotal
data = frx_arg_bytes(aTHX_ items > 2 ? ST(2) : NULL, &dlen); 2 1 3
186 3 n = frx_new_pi(d, t, tlen, data, dlen, &e);
187 3 ▶ if (!n) frx_edit_croak(aTHX_ "new_pi", &e);
Branch: 1 branch
BranchTrueFalseTotal
if (!n) frx_edit_croak(aTHX_ "new_pi", &e); 1 2 3
188 2 RETVAL = frx_node_bless(aTHX_ SvRV(self), n);
189 OUTPUT:
190 RETVAL
191  
192 void
193 import_node(self, ...)
194 SV *self
195 ALIAS:
196 import = 1
197 PREINIT:
198 frx_doc *d;
199 const frx_node *src;
200 frx_node *copy;
201 frx_err e;
202 PPCODE:
203 /* `import` is the name the family reads, and perl's own: it calls
204 * __PACKAGE__->import for every `use` of this class, with the
205 * class name and whatever import list follows. Neither is a
206 * document, so that call is answered with nothing and only a real
207 * invocant with a node does the work. The alias cannot live in
208 * Document.pm: the class comes from this bundle, and the .pm is
209 * loaded only if someone uses it by name. */
210 PERL_UNUSED_VAR(ix);
211 3 ▶ if (items < 2 || !SvROK(self)) XSRETURN_EMPTY;
Branch: 2 branches
BranchTrueFalseTotal
if (items < 2 || !SvROK(self)) XSRETURN_EMPTY; 2 1 3
if (items < 2 || !SvROK(self)) XSRETURN_EMPTY; 0 2 2
212 2 d = frx_doc_from_sv(aTHX_ self, "import");
213 2 src = frx_node_from_sv(aTHX_ ST(1), "import", NULL);
214 2 copy = frx_import(d, src, &e);
215 2 ▶ if (!copy) frx_edit_croak(aTHX_ "import", &e);
Branch: 1 branch
BranchTrueFalseTotal
if (!copy) frx_edit_croak(aTHX_ "import", &e); 1 1 2
216 1 ▶ XPUSHs(sv_2mortal(frx_node_bless(aTHX_ SvRV(self), copy)));
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(sv_2mortal(frx_node_bless(aTHX_ SvRV(self), copy))); 0 1 1
217  
218 void
219 errors(self)
220 SV *self
221 PREINIT:
222 frx_doc *d;
223 const frx_verr *e;
224 char msg[512];
225 PPCODE:
226 /* validate => 'collect': every violation, in document order */
227 1025 d = frx_doc_from_sv(aTHX_ self, "errors");
228 1289 ▶ for (e = d->errors; e; e = e->next) {
Branch: 1 branch
BranchTrueFalseTotal
for (e = d->errors; e; e = e->next) { 264 1025 1289
229 264 size_t n = frx_verr_format(e, msg, sizeof msg);
230 264 ▶ XPUSHs(sv_2mortal(newSVpvn(msg, n)));
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(sv_2mortal(newSVpvn(msg, n))); 0 264 264
231 }
232  
233 MODULE = File::Raw::XML PACKAGE = File::Raw::XML
234  
235 SV *
236 new_document(class, ...)
237 const char *class
238 PREINIT:
239 HV *opts;
240 SV **v;
241 12 int v11 = 0;
242 frx_doc *d;
243 CODE:
244 PERL_UNUSED_VAR(class);
245 12 opts = frx_opts_hv(aTHX_ &ST(0), 1, items, "new_document");
246 14 ▶ if (opts && (v = hv_fetchs(opts, "version", 0))) {
Branch: 2 branches
BranchTrueFalseTotal
if (opts && (v = hv_fetchs(opts, "version", 0))) { 12 0 12
if (opts && (v = hv_fetchs(opts, "version", 0))) { 3 9 12
247 STRLEN n;
248 3 const char *s = SvPV(*v, n);
249 3 ▶ if (n == 3 && memcmp(s, "1.1", 3) == 0) v11 = 1;
Branch: 2 branches
BranchTrueFalseTotal
if (n == 3 && memcmp(s, "1.1", 3) == 0) v11 = 1; 2 1 3
if (n == 3 && memcmp(s, "1.1", 3) == 0) v11 = 1; 2 0 2
250 1 ▶ else if (!(n == 3 && memcmp(s, "1.0", 3) == 0))
Branch: 2 branches
BranchTrueFalseTotal
else if (!(n == 3 && memcmp(s, "1.0", 3) == 0)) 0 1 1
else if (!(n == 3 && memcmp(s, "1.0", 3) == 0)) 0 0 0
251 1 croak("File::Raw::XML: new_document: version must be 1.0 or 1.1");
252 2 ▶ if (hv_iterinit(opts) > 1) croak("File::Raw::XML: new_document: the one option is version");
Branch: 1 branch
BranchTrueFalseTotal
if (hv_iterinit(opts) > 1) croak("File::Raw::XML: new_document: the one option is version"); 0 2 2
253 9 ▶ } else if (opts && hv_iterinit(opts)) {
Branch: 2 branches
BranchTrueFalseTotal
} else if (opts && hv_iterinit(opts)) { 9 0 9
} else if (opts && hv_iterinit(opts)) { 1 8 9
254 1 croak("File::Raw::XML: new_document: the one option is version");
255 }
256 10 d = frx_doc_new_empty(v11);
257 10 ▶ if (!d) croak("File::Raw::XML: new_document: out of memory");
Branch: 1 branch
BranchTrueFalseTotal
if (!d) croak("File::Raw::XML: new_document: out of memory"); 0 10 10
258 10 RETVAL = frx_doc_bless(aTHX_ d);
259 OUTPUT:
260 RETVAL
« include/frx/frx_enc.h ↑ Summary include/frx/frx_lex.h »