| 1 |
|
| |
| 2 |
|
| # File::Raw::XML::XPath: a compiled expression, and the two classes an |
| 3 |
|
| # attribute or a namespace node in a result comes back as. The compiled |
| 4 |
|
| # object holds no document; every result does, exactly as a Node does. |
| 5 |
|
| |
| 6 |
|
| MODULE = File::Raw::XML PACKAGE = File::Raw::XML::XPath |
| 7 |
|
| |
| 8 |
|
| SV * |
| 9 |
|
| new(class, expr, ...) |
| 10 |
|
| const char *class |
| 11 |
|
| SV *expr |
| 12 |
|
| PREINIT: |
| 13 |
|
| HV *opts; |
| 14 |
|
| frx_xpath *x; |
| 15 |
|
| CODE: |
| 16 |
7 |
| opts = frx_opts_hv(aTHX_ &ST(0), 2, items, "new"); |
| 17 |
7 |
| x = frx_xpath_from_opts(aTHX_ expr, opts, "new"); |
| 18 |
7 |
| RETVAL = frx_xpath_bless(aTHX_ x, class); |
| 19 |
|
| OUTPUT: |
| 20 |
|
| RETVAL |
| 21 |
|
| |
| 22 |
|
| void |
| 23 |
|
| find(self, context) |
| 24 |
|
| SV *self |
| 25 |
|
| SV *context |
| 26 |
|
| PREINIT: |
| 27 |
|
| frx_xpath *x; |
| 28 |
|
| frx_doc *d; |
| 29 |
|
| const frx_node *ctx; |
| 30 |
|
| SV *doc_iv; |
| 31 |
|
| frx_xp_val v; |
| 32 |
11 |
| const char *err = NULL; |
| 33 |
|
| AV *av; |
| 34 |
|
| I32 i, n; |
| 35 |
|
| PPCODE: |
| 36 |
11 |
| x = frx_xpath_from_sv(aTHX_ self, "find"); |
| 37 |
10 |
| ctx = frx_xpath_context(aTHX_ context, "find", &d, &doc_iv); |
| 38 |
10 |
▶ | if (!frx_xpath_eval_at(x, d, ctx, &v, &err)) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (!frx_xpath_eval_at(x, d, ctx, &v, &err)) { |
0 |
10 |
10 |
|
| 39 |
0 |
| frx_xp_val_free(&v); |
| 40 |
0 |
▶ | croak("File::Raw::XML: find: %s", err ? err : "the expression could not be evaluated"); |
Branch: 1 branch
| Branch | True | False | Total |
| croak("File::Raw::XML: find: %s", err ? err : "the expression could not be evaluated"); |
0 |
0 |
0 |
|
| 41 |
|
| } |
| 42 |
10 |
| av = frx_xp_result_av(aTHX_ &v, doc_iv, GIMME_V); |
| 43 |
10 |
| frx_xp_val_free(&v); |
| 44 |
10 |
| n = av_len(av) + 1; |
| 45 |
10 |
▶ | EXTEND(SP, n); |
Branch: 2 branches
| Branch | True | False | Total |
| EXTEND(SP, n); |
10 |
0 |
10 |
| EXTEND(SP, n); |
0 |
10 |
10 |
|
| 46 |
20 |
▶ | for (i = 0; i < n; i++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (i = 0; i < n; i++) { |
10 |
10 |
20 |
|
| 47 |
10 |
| SV **e = av_fetch(av, i, 0); |
| 48 |
10 |
▶ | PUSHs(sv_2mortal(SvREFCNT_inc(e ? *e : &PL_sv_undef))); |
Branch: 1 branch
| Branch | True | False | Total |
| PUSHs(sv_2mortal(SvREFCNT_inc(e ? *e : &PL_sv_undef))); |
10 |
0 |
10 |
|
| 49 |
|
| } |
| 50 |
|
| |
| 51 |
|
| MODULE = File::Raw::XML PACKAGE = File::Raw::XML::Node |
| 52 |
|
| |
| 53 |
|
| void |
| 54 |
|
| xpath(self, expr, ...) |
| 55 |
|
| SV *self |
| 56 |
|
| SV *expr |
| 57 |
|
| PREINIT: |
| 58 |
|
| HV *opts; |
| 59 |
|
| frx_xpath *x; |
| 60 |
|
| frx_doc *d; |
| 61 |
|
| const frx_node *ctx; |
| 62 |
|
| SV *doc_iv; |
| 63 |
|
| frx_xp_val v; |
| 64 |
1 |
| const char *err = NULL; |
| 65 |
|
| AV *av; |
| 66 |
|
| I32 i, n; |
| 67 |
|
| int ok; |
| 68 |
|
| PPCODE: |
| 69 |
1 |
| ctx = frx_xpath_context(aTHX_ self, "xpath", &d, &doc_iv); |
| 70 |
1 |
| opts = frx_opts_hv(aTHX_ &ST(0), 2, items, "xpath"); |
| 71 |
1 |
| x = frx_xpath_from_opts(aTHX_ expr, opts, "xpath"); |
| 72 |
1 |
| ok = frx_xpath_eval_at(x, d, ctx, &v, &err); |
| 73 |
1 |
▶ | if (!ok) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (!ok) { |
0 |
1 |
1 |
|
| 74 |
|
| char msg[512]; |
| 75 |
0 |
| my_snprintf(msg, sizeof msg, "File::Raw::XML: xpath: %s", |
| 76 |
0 |
▶ | err ? err : "the expression could not be evaluated"); |
Branch: 1 branch
| Branch | True | False | Total |
| err ? err : "the expression could not be evaluated"); |
0 |
0 |
0 |
|
| 77 |
0 |
| frx_xp_val_free(&v); |
| 78 |
0 |
| frx_xpath_free(x); |
| 79 |
0 |
| croak("%s", msg); |
| 80 |
|
| } |
| 81 |
1 |
| av = frx_xp_result_av(aTHX_ &v, doc_iv, GIMME_V); |
| 82 |
1 |
| frx_xp_val_free(&v); |
| 83 |
1 |
| frx_xpath_free(x); |
| 84 |
1 |
| n = av_len(av) + 1; |
| 85 |
1 |
▶ | EXTEND(SP, n); |
Branch: 2 branches
| Branch | True | False | Total |
| EXTEND(SP, n); |
1 |
0 |
1 |
| EXTEND(SP, n); |
0 |
1 |
1 |
|
| 86 |
2 |
▶ | for (i = 0; i < n; i++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (i = 0; i < n; i++) { |
1 |
1 |
2 |
|
| 87 |
1 |
| SV **e = av_fetch(av, i, 0); |
| 88 |
1 |
▶ | PUSHs(sv_2mortal(SvREFCNT_inc(e ? *e : &PL_sv_undef))); |
Branch: 1 branch
| Branch | True | False | Total |
| PUSHs(sv_2mortal(SvREFCNT_inc(e ? *e : &PL_sv_undef))); |
1 |
0 |
1 |
|
| 89 |
|
| } |
| 90 |
|
| |
| 91 |
|
| MODULE = File::Raw::XML PACKAGE = File::Raw::XML::Document |
| 92 |
|
| |
| 93 |
|
| void |
| 94 |
|
| xpath(self, expr, ...) |
| 95 |
|
| SV *self |
| 96 |
|
| SV *expr |
| 97 |
|
| PREINIT: |
| 98 |
|
| HV *opts; |
| 99 |
|
| frx_xpath *x; |
| 100 |
|
| frx_doc *d; |
| 101 |
|
| const frx_node *ctx; |
| 102 |
|
| SV *doc_iv; |
| 103 |
|
| frx_xp_val v; |
| 104 |
226 |
| const char *err = NULL; |
| 105 |
|
| AV *av; |
| 106 |
|
| I32 i, n; |
| 107 |
|
| int ok; |
| 108 |
|
| PPCODE: |
| 109 |
226 |
| ctx = frx_xpath_context(aTHX_ self, "xpath", &d, &doc_iv); |
| 110 |
226 |
| opts = frx_opts_hv(aTHX_ &ST(0), 2, items, "xpath"); |
| 111 |
226 |
| x = frx_xpath_from_opts(aTHX_ expr, opts, "xpath"); |
| 112 |
204 |
| ok = frx_xpath_eval_at(x, d, ctx, &v, &err); |
| 113 |
204 |
▶ | if (!ok) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (!ok) { |
2 |
202 |
204 |
|
| 114 |
|
| char msg[512]; |
| 115 |
2 |
| my_snprintf(msg, sizeof msg, "File::Raw::XML: xpath: %s", |
| 116 |
2 |
▶ | err ? err : "the expression could not be evaluated"); |
Branch: 1 branch
| Branch | True | False | Total |
| err ? err : "the expression could not be evaluated"); |
2 |
0 |
2 |
|
| 117 |
2 |
| frx_xp_val_free(&v); |
| 118 |
2 |
| frx_xpath_free(x); |
| 119 |
2 |
| croak("%s", msg); |
| 120 |
|
| } |
| 121 |
202 |
| av = frx_xp_result_av(aTHX_ &v, doc_iv, GIMME_V); |
| 122 |
202 |
| frx_xp_val_free(&v); |
| 123 |
202 |
| frx_xpath_free(x); |
| 124 |
202 |
| n = av_len(av) + 1; |
| 125 |
202 |
▶ | EXTEND(SP, n); |
Branch: 2 branches
| Branch | True | False | Total |
| EXTEND(SP, n); |
202 |
0 |
202 |
| EXTEND(SP, n); |
0 |
202 |
202 |
|
| 126 |
445 |
▶ | for (i = 0; i < n; i++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (i = 0; i < n; i++) { |
243 |
202 |
445 |
|
| 127 |
243 |
| SV **e = av_fetch(av, i, 0); |
| 128 |
243 |
▶ | PUSHs(sv_2mortal(SvREFCNT_inc(e ? *e : &PL_sv_undef))); |
Branch: 1 branch
| Branch | True | False | Total |
| PUSHs(sv_2mortal(SvREFCNT_inc(e ? *e : &PL_sv_undef))); |
243 |
0 |
243 |
|
| 129 |
|
| } |
| 130 |
|
| |
| 131 |
|
| MODULE = File::Raw::XML PACKAGE = File::Raw::XML::Attr |
| 132 |
|
| |
| 133 |
|
| SV * |
| 134 |
|
| name(self) |
| 135 |
|
| SV *self |
| 136 |
|
| ALIAS: |
| 137 |
|
| local = 1 |
| 138 |
|
| ns = 2 |
| 139 |
|
| prefix = 3 |
| 140 |
|
| value = 4 |
| 141 |
|
| PREINIT: |
| 142 |
|
| const frx_node *owner; |
| 143 |
|
| const frx_attr *a; |
| 144 |
|
| int ix_at; |
| 145 |
27 |
| const char *meth[] = { "name", "local", "ns", "prefix", "value" }; |
| 146 |
|
| CODE: |
| 147 |
27 |
| owner = frx_entry_from_sv(aTHX_ self, meth[ix], 0, &ix_at, NULL); |
| 148 |
27 |
▶ | if (ix_at < 0 || ix_at >= owner->n_attrs) |
Branch: 2 branches
| Branch | True | False | Total |
| if (ix_at < 0 || ix_at >= owner->n_attrs) |
27 |
0 |
27 |
| if (ix_at < 0 || ix_at >= owner->n_attrs) |
0 |
27 |
27 |
|
| 149 |
0 |
| croak("File::Raw::XML: %s: the attribute is no longer in its element", meth[ix]); |
| 150 |
27 |
| a = &owner->attrs[ix_at]; |
| 151 |
27 |
| switch (ix) { |
| 152 |
7 |
| case 1: RETVAL = frx_str_sv(aTHX_ &a->local); break; |
| 153 |
8 |
| case 2: RETVAL = frx_str_sv(aTHX_ &a->ns); break; |
| 154 |
2 |
| case 3: RETVAL = frx_str_sv(aTHX_ &a->prefix); break; |
| 155 |
8 |
| case 4: RETVAL = frx_str_sv(aTHX_ &a->value); break; |
| 156 |
2 |
| default: RETVAL = frx_str_sv(aTHX_ &a->qname); break; |
| 157 |
|
| } |
| 158 |
|
| OUTPUT: |
| 159 |
|
| RETVAL |
| 160 |
|
| |
| 161 |
|
| SV * |
| 162 |
|
| owner(self) |
| 163 |
|
| SV *self |
| 164 |
|
| ALIAS: |
| 165 |
|
| doc = 1 |
| 166 |
|
| PREINIT: |
| 167 |
|
| const frx_node *o; |
| 168 |
|
| SV *doc_iv; |
| 169 |
|
| CODE: |
| 170 |
2 |
▶ | o = frx_entry_from_sv(aTHX_ self, ix ? "doc" : "owner", 0, NULL, &doc_iv); |
Branch: 1 branch
| Branch | True | False | Total |
| o = frx_entry_from_sv(aTHX_ self, ix ? "doc" : "owner", 0, NULL, &doc_iv); |
1 |
1 |
2 |
|
| 171 |
2 |
▶ | RETVAL = ix ? frx_node_doc_rv(aTHX_ doc_iv) : frx_node_bless(aTHX_ doc_iv, o); |
Branch: 1 branch
| Branch | True | False | Total |
| RETVAL = ix ? frx_node_doc_rv(aTHX_ doc_iv) : frx_node_bless(aTHX_ doc_iv, o); |
1 |
1 |
2 |
|
| 172 |
|
| OUTPUT: |
| 173 |
|
| RETVAL |
| 174 |
|
| |
| 175 |
|
| MODULE = File::Raw::XML PACKAGE = File::Raw::XML::Namespace |
| 176 |
|
| |
| 177 |
|
| SV * |
| 178 |
|
| name(self) |
| 179 |
|
| SV *self |
| 180 |
|
| ALIAS: |
| 181 |
|
| prefix = 1 |
| 182 |
|
| value = 2 |
| 183 |
|
| uri = 3 |
| 184 |
|
| PREINIT: |
| 185 |
|
| const frx_node *owner; |
| 186 |
|
| frx_str p, u; |
| 187 |
|
| int ix_at; |
| 188 |
14 |
| const char *meth[] = { "name", "prefix", "value", "uri" }; |
| 189 |
|
| CODE: |
| 190 |
14 |
| owner = frx_entry_from_sv(aTHX_ self, meth[ix], 1, &ix_at, NULL); |
| 191 |
13 |
▶ | if (!frx_xp_ns_at(owner, ix_at, &p, &u)) |
Branch: 1 branch
| Branch | True | False | Total |
| if (!frx_xp_ns_at(owner, ix_at, &p, &u)) |
0 |
13 |
13 |
|
| 192 |
0 |
| croak("File::Raw::XML: %s: out of memory", meth[ix]); |
| 193 |
13 |
▶ | RETVAL = frx_str_sv(aTHX_ ix >= 2 ? &u : &p); |
Branch: 1 branch
| Branch | True | False | Total |
| RETVAL = frx_str_sv(aTHX_ ix >= 2 ? &u : &p); |
7 |
6 |
13 |
|
| 194 |
|
| OUTPUT: |
| 195 |
|
| RETVAL |
| 196 |
|
| |
| 197 |
|
| SV * |
| 198 |
|
| owner(self) |
| 199 |
|
| SV *self |
| 200 |
|
| ALIAS: |
| 201 |
|
| doc = 1 |
| 202 |
|
| PREINIT: |
| 203 |
|
| const frx_node *o; |
| 204 |
|
| SV *doc_iv; |
| 205 |
|
| CODE: |
| 206 |
1 |
▶ | o = frx_entry_from_sv(aTHX_ self, ix ? "doc" : "owner", 1, NULL, &doc_iv); |
Branch: 1 branch
| Branch | True | False | Total |
| o = frx_entry_from_sv(aTHX_ self, ix ? "doc" : "owner", 1, NULL, &doc_iv); |
0 |
1 |
1 |
|
| 207 |
1 |
▶ | RETVAL = ix ? frx_node_doc_rv(aTHX_ doc_iv) : frx_node_bless(aTHX_ doc_iv, o); |
Branch: 1 branch
| Branch | True | False | Total |
| RETVAL = ix ? frx_node_doc_rv(aTHX_ doc_iv) : frx_node_bless(aTHX_ doc_iv, o); |
0 |
1 |
1 |
|
| 208 |
|
| OUTPUT: |
| 209 |
|
| RETVAL |