Op.xs

filter: Statementstmt 95.4% 678 / 710 Branchbran 68.3% 488 / 714 Conditioncond n/a MC/DCmcdc n/a Subroutinesub n/a Podpod n/a totaltotal 81.8% 1166 / 1424 CC 0 SCAR 0
CC
0
Cov
0%
CRAP 0
« include/ex_op_reg.h ↑ Summary include/ex_op_call.h »
1 #define PERL_NO_GET_CONTEXT
2 #include "EXTERN.h"
3 #include "perl.h"
4 #include "XSUB.h"
5 #define NEED_caller_cx
6 #define NEED_mg_findext
7 #include "ppport.h"
8  
9 #include "xop_compat.h"
10 #include "ex_op_compat.h"
11 #include "ex_op.h"
12 #include "ex_op_reg.h"
13  
14 START_MY_CXT
15  
16 #include "ex_op_call.h"
17 #include "ex_op_kw.h"
18  
19 static void
20 39 eo_cxt_init(pTHX_ my_cxt_t *cxt)
21 {
22 39 cxt->exports = newHV();
23 39 cxt->ret = NULL;
24 39 cxt->ret_top = 0;
25 39 cxt->ret_max = 0;
26 39 cxt->level_gv = gv_fetchpvs("Ex::Op::ExportLevel", GV_ADDMULTI, SVt_PV);
27 39 cxt->verbose_gv = gv_fetchpvs("Ex::Op::Verbose", GV_ADDMULTI, SVt_PV);
28 39 ▶ if (!SvOK(GvSVn(cxt->level_gv)))
Branch: 2 branches
BranchTrueFalseTotal
if (!SvOK(GvSVn(cxt->level_gv))) 39 0 39
if (!SvOK(GvSVn(cxt->level_gv))) 39 0 39
29 39 ▶ sv_setiv(GvSVn(cxt->level_gv), 0);
Branch: 1 branch
BranchTrueFalseTotal
sv_setiv(GvSVn(cxt->level_gv), 0); 39 0 39
30 39 ▶ if (!SvOK(GvSVn(cxt->verbose_gv)))
Branch: 2 branches
BranchTrueFalseTotal
if (!SvOK(GvSVn(cxt->verbose_gv))) 39 0 39
if (!SvOK(GvSVn(cxt->verbose_gv))) 39 0 39
31 39 ▶ sv_setiv(GvSVn(cxt->verbose_gv), 0);
Branch: 1 branch
BranchTrueFalseTotal
sv_setiv(GvSVn(cxt->verbose_gv), 0); 39 0 39
32 39 cxt->import_cv = get_cvs("Ex::Op::import", 0);
33 39 cxt->export_cv = get_cvs("Ex::Op::export", 0);
34 39 cxt->export_fail_cv = get_cvs("Ex::Op::export_fail", 0);
35 39 }
36  
37 /* What Exporter's caller($level) sees from inside an exporter sub. An XSUB
38 * has no frame of its own, so level 0 is the statement that called it and
39 * level N is the call site of the Perl frame N-1 above it. */
40 static const COP *
41 6416 eo_caller_cop(pTHX_ IV level)
42 {
43 const PERL_CONTEXT *cx;
44 6416 ▶ if (level <= 0)
Branch: 1 branch
BranchTrueFalseTotal
if (level <= 0) 6410 6 6416
45 6410 return PL_curcop;
46 6 cx = caller_cx((I32)(level - 1), NULL);
47 6 ▶ return cx ? cx->blk_oldcop : NULL;
Branch: 1 branch
BranchTrueFalseTotal
return cx ? cx->blk_oldcop : NULL; 6 0 6
48 }
49  
50 static SV *
51 6593 eo_stash_name(pTHX_ HV *stash)
52 {
53 6593 ▶ if (!stash || !HvNAME_get(stash))
Branch: 8 branches
BranchTrueFalseTotal
if (!stash || !HvNAME_get(stash)) 6593 0 6593
if (!stash || !HvNAME_get(stash)) 6593 0 6593
if (!stash || !HvNAME_get(stash)) 6593 0 6593
if (!stash || !HvNAME_get(stash)) 0 6593 6593
if (!stash || !HvNAME_get(stash)) 0 0 0
if (!stash || !HvNAME_get(stash)) 6593 0 6593
if (!stash || !HvNAME_get(stash)) 0 6593 6593
if (!stash || !HvNAME_get(stash)) 0 6593 6593
54 0 return newSVpvs_flags("main", SVs_TEMP);
55 6593 ▶ return newSVpvn_flags(HvNAME_get(stash), HvNAMELEN_get(stash),
Branch: 20 branches
BranchTrueFalseTotal
return newSVpvn_flags(HvNAME_get(stash), HvNAMELEN_get(stash), 6593 0 6593
return newSVpvn_flags(HvNAME_get(stash), HvNAMELEN_get(stash), 6593 0 6593
return newSVpvn_flags(HvNAME_get(stash), HvNAMELEN_get(stash), 0 6593 6593
return newSVpvn_flags(HvNAME_get(stash), HvNAMELEN_get(stash), 0 0 0
return newSVpvn_flags(HvNAME_get(stash), HvNAMELEN_get(stash), 6593 0 6593
return newSVpvn_flags(HvNAME_get(stash), HvNAMELEN_get(stash), 0 6593 6593
return newSVpvn_flags(HvNAME_get(stash), HvNAMELEN_get(stash), 0 6593 6593
return newSVpvn_flags(HvNAME_get(stash), HvNAMELEN_get(stash), 0 6593 6593
return newSVpvn_flags(HvNAME_get(stash), HvNAMELEN_get(stash), 6593 0 6593
return newSVpvn_flags(HvNAME_get(stash), HvNAMELEN_get(stash), 6593 0 6593
return newSVpvn_flags(HvNAME_get(stash), HvNAMELEN_get(stash), 0 6593 6593
return newSVpvn_flags(HvNAME_get(stash), HvNAMELEN_get(stash), 0 0 0
return newSVpvn_flags(HvNAME_get(stash), HvNAMELEN_get(stash), 6593 0 6593
return newSVpvn_flags(HvNAME_get(stash), HvNAMELEN_get(stash), 0 6593 6593
return newSVpvn_flags(HvNAME_get(stash), HvNAMELEN_get(stash), 6593 0 6593
return newSVpvn_flags(HvNAME_get(stash), HvNAMELEN_get(stash), 6593 0 6593
return newSVpvn_flags(HvNAME_get(stash), HvNAMELEN_get(stash), 0 6593 6593
return newSVpvn_flags(HvNAME_get(stash), HvNAMELEN_get(stash), 0 0 0
return newSVpvn_flags(HvNAME_get(stash), HvNAMELEN_get(stash), 6593 0 6593
return newSVpvn_flags(HvNAME_get(stash), HvNAMELEN_get(stash), 0 6593 6593
56 SVs_TEMP | (HvNAMEUTF8(stash) ? SVf_UTF8 : 0));
57 }
58  
59 static SV *
60 1354 eo_qualify(pTHX_ SV *pkg, const char *name, STRLEN len, bool utf8)
61 {
62 1354 SV *full = newSVsv(pkg);
63 1354 sv_2mortal(full);
64 1354 sv_catpvs(full, "::");
65 1354 ▶ if (utf8 && !SvUTF8(full))
Branch: 2 branches
BranchTrueFalseTotal
if (utf8 && !SvUTF8(full)) 0 1354 1354
if (utf8 && !SvUTF8(full)) 0 0 0
66 0 sv_utf8_upgrade(full);
67 1354 ▶ if (SvUTF8(full) && !utf8) {
Branch: 2 branches
BranchTrueFalseTotal
if (SvUTF8(full) && !utf8) { 0 1354 1354
if (SvUTF8(full) && !utf8) { 0 0 0
68 0 SV *tail = newSVpvn_flags(name, len, SVs_TEMP);
69 0 sv_catsv(full, tail);
70 }
71 else {
72 1354 sv_catpvn(full, name, len);
73 }
74 1354 return full;
75 }
76  
77 /* The glob a plain name already has in a stash, found without building
78 * "Pkg::name". NULL for a qualified or UTF-8 name, or one with no glob yet. */
79 static GV *
80 86958 eo_stash_gv(pTHX_ HV *stash, const char *name, STRLEN len, bool utf8)
81 {
82 SV **svp;
83 86958 ▶ if (!stash || utf8 || !len || memchr(name, ':', len) || memchr(name, '\'', len))
Branch: 5 branches
BranchTrueFalseTotal
if (!stash || utf8 || !len || memchr(name, ':', len) || memchr(name, '\'', len)) 86958 0 86958
if (!stash || utf8 || !len || memchr(name, ':', len) || memchr(name, '\'', len)) 86958 0 86958
if (!stash || utf8 || !len || memchr(name, ':', len) || memchr(name, '\'', len)) 86958 0 86958
if (!stash || utf8 || !len || memchr(name, ':', len) || memchr(name, '\'', len)) 86956 2 86958
if (!stash || utf8 || !len || memchr(name, ':', len) || memchr(name, '\'', len)) 0 86956 86956
84 2 return NULL;
85 86956 svp = hv_fetch(stash, name, (I32)len, 0);
86 86956 ▶ return (svp && isGV_with_GP(*svp)) ? (GV *)*svp : NULL;
Branch: 4 branches
BranchTrueFalseTotal
return (svp && isGV_with_GP(*svp)) ? (GV *)*svp : NULL; 76358 10598 86956
return (svp && isGV_with_GP(*svp)) ? (GV *)*svp : NULL; 76358 0 76358
return (svp && isGV_with_GP(*svp)) ? (GV *)*svp : NULL; 0 76358 76358
return (svp && isGV_with_GP(*svp)) ? (GV *)*svp : NULL; 0 0 0
87 }
88  
89 /* The same, made when it is not there yet, for a name gv_fetchpvn would
90 * give nothing special: two or more word characters, the first lower case
91 * or an underscore. EXPORT, ISA, VERSION, ARGV, SIG, ENV, STDIN, $a, $b and
92 * the rest all start otherwise, and go the long way. */
93 static GV *
94 10833 eo_stash_gv_add(pTHX_ HV *stash, const char *name, STRLEN len, bool utf8)
95 {
96 10833 GV *gv = eo_stash_gv(aTHX_ stash, name, len, utf8);
97 STRLEN i;
98 SV **svp;
99 10833 ▶ if (gv || !stash || utf8 || len < 2 || !(isLOWER(*name) || *name == '_'))
Branch: 6 branches
BranchTrueFalseTotal
if (gv || !stash || utf8 || len < 2 || !(isLOWER(*name) || *name == '_')) 10547 286 10833
if (gv || !stash || utf8 || len < 2 || !(isLOWER(*name) || *name == '_')) 10547 0 10547
if (gv || !stash || utf8 || len < 2 || !(isLOWER(*name) || *name == '_')) 10547 0 10547
if (gv || !stash || utf8 || len < 2 || !(isLOWER(*name) || *name == '_')) 10519 28 10547
if (gv || !stash || utf8 || len < 2 || !(isLOWER(*name) || *name == '_')) 531 9988 10519
if (gv || !stash || utf8 || len < 2 || !(isLOWER(*name) || *name == '_')) 531 0 531
100 845 return gv;
101 20217 ▶ for (i = 1; i < len; i++)
Branch: 1 branch
BranchTrueFalseTotal
for (i = 1; i < len; i++) 10229 9988 20217
102 10229 ▶ if (!isWORDCHAR(name[i]))
Branch: 1 branch
BranchTrueFalseTotal
if (!isWORDCHAR(name[i])) 0 10229 10229
103 0 return NULL;
104 9988 svp = hv_fetch(stash, name, (I32)len, 1);
105 9988 ▶ if (!svp)
Branch: 1 branch
BranchTrueFalseTotal
if (!svp) 0 9988 9988
106 0 return NULL;
107 9988 ▶ if (!isGV_with_GP(*svp))
Branch: 3 branches
BranchTrueFalseTotal
if (!isGV_with_GP(*svp)) 0 9988 9988
if (!isGV_with_GP(*svp)) 0 0 0
if (!isGV_with_GP(*svp)) 0 0 0
108 9988 gv_init((GV *)*svp, stash, name, len, TRUE);
109 9988 ▶ return isGV_with_GP(*svp) ? (GV *)*svp : NULL;
Branch: 3 branches
BranchTrueFalseTotal
return isGV_with_GP(*svp) ? (GV *)*svp : NULL; 9988 0 9988
return isGV_with_GP(*svp) ? (GV *)*svp : NULL; 0 9988 9988
return isGV_with_GP(*svp) ? (GV *)*svp : NULL; 0 0 0
110 }
111  
112 static GV *
113 28116 eo_pkg_gv(pTHX_ SV *pkg, const char *name, STRLEN len, svtype type)
114 {
115 28116 GV *gv = eo_stash_gv(aTHX_ gv_stashsv(pkg, 0), name, len, FALSE);
116 28116 ▶ if (gv)
Branch: 1 branch
BranchTrueFalseTotal
if (gv) 28105 11 28116
117 28105 return gv;
118 11 gv = gv_fetchsv(eo_qualify(aTHX_ pkg, name, len, FALSE), 0, type);
119 11 ▶ return (gv && isGV_with_GP(gv)) ? gv : NULL;
Branch: 4 branches
BranchTrueFalseTotal
return (gv && isGV_with_GP(gv)) ? gv : NULL; 0 11 11
return (gv && isGV_with_GP(gv)) ? gv : NULL; 0 0 0
return (gv && isGV_with_GP(gv)) ? gv : NULL; 0 0 0
return (gv && isGV_with_GP(gv)) ? gv : NULL; 0 0 0
120 }
121  
122 static AV *
123 22889 eo_pkg_av(pTHX_ SV *pkg, const char *name, STRLEN len)
124 {
125 22889 GV *gv = eo_pkg_gv(aTHX_ pkg, name, len, SVt_PVAV);
126 22889 ▶ return gv ? GvAV(gv) : NULL;
Branch: 1 branch
BranchTrueFalseTotal
return gv ? GvAV(gv) : NULL; 22878 11 22889
127 }
128  
129 static HV *
130 5227 eo_pkg_hv(pTHX_ SV *pkg, const char *name, STRLEN len)
131 {
132 5227 GV *gv = eo_pkg_gv(aTHX_ pkg, name, len, SVt_PVHV);
133 5227 ▶ return gv ? GvHV(gv) : NULL;
Branch: 1 branch
BranchTrueFalseTotal
return gv ? GvHV(gv) : NULL; 5227 0 5227
134 }
135  
136 static SV *
137 16703 eo_strip_amp(pTHX_ SV *sv)
138 {
139 STRLEN len;
140 16703 const char *s = SvPV_const(sv, len);
141 16703 ▶ if (len && *s == '&') {
Branch: 2 branches
BranchTrueFalseTotal
if (len && *s == '&') { 16703 0 16703
if (len && *s == '&') { 0 16703 16703
142 0 s++;
143 0 len--;
144 }
145 16703 return newSVpvn_flags(s, len, SVs_TEMP | (SvUTF8(sv) ? SVf_UTF8 : 0));
146 }
147  
148 /* Exporter's _rebuild_cache runs s/^&// over @EXPORT and @EXPORT_OK
149 * themselves, so after the first import with a list :DEFAULT names d2, not
150 * &d2. The arrays are changed in place here too. */
151 static void
152 3846 eo_add_names(pTHX_ HV *set, AV *av)
153 {
154 SSize_t i, top;
155 3846 ▶ if (!av)
Branch: 1 branch
BranchTrueFalseTotal
if (!av) 0 3846 3846
156 0 return;
157 3846 top = av_len(av);
158 21067 ▶ for (i = 0; i <= top; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i <= top; i++) { 17221 3846 21067
159 17221 SV **svp = av_fetch(av, i, 0);
160 STRLEN len;
161 const char *s;
162 17221 ▶ if (!svp)
Branch: 1 branch
BranchTrueFalseTotal
if (!svp) 0 17221 17221
163 0 continue;
164 17221 s = SvPV_const(*svp, len);
165 17221 ▶ if (len && *s == '&')
Branch: 2 branches
BranchTrueFalseTotal
if (len && *s == '&') 17221 0 17221
if (len && *s == '&') 11 17210 17221
166 11 sv_chop(*svp, s + 1);
167 17221 (void)hv_store_ent(set, *svp, &PL_sv_yes, 0);
168 }
169 }
170  
171 static void
172 5273 eo_av_append(pTHX_ AV *to, AV *from)
173 {
174 SSize_t i, top;
175 5273 ▶ if (!from)
Branch: 1 branch
BranchTrueFalseTotal
if (!from) 0 5273 5273
176 0 return;
177 5273 top = av_len(from);
178 18979 ▶ for (i = 0; i <= top; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i <= top; i++) { 13706 5273 18979
179 13706 SV **svp = av_fetch(from, i, 0);
180 13706 ▶ av_push(to, svp ? newSVsv(*svp) : newSV(0));
Branch: 1 branch
BranchTrueFalseTotal
av_push(to, svp ? newSVsv(*svp) : newSV(0)); 13706 0 13706
181 }
182 }
183  
184 static AV *
185 93 eo_av_copy(pTHX_ AV *from)
186 {
187 93 AV *to = (AV *)sv_2mortal((SV *)newAV());
188 93 eo_av_append(aTHX_ to, from);
189 93 return to;
190 }
191  
192 static SV *
193 9 eo_join(pTHX_ AV *av, const char *sep)
194 {
195 9 SV *out = sv_2mortal(newSVpvs(""));
196 9 SSize_t i, top = av_len(av);
197 27 ▶ for (i = 0; i <= top; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i <= top; i++) { 18 9 27
198 18 SV **svp = av_fetch(av, i, 0);
199 18 ▶ if (i)
Branch: 1 branch
BranchTrueFalseTotal
if (i) 9 9 18
200 9 sv_catpv(out, sep);
201 18 ▶ if (svp)
Branch: 1 branch
BranchTrueFalseTotal
if (svp) 18 0 18
202 18 sv_catsv(out, *svp);
203 }
204 9 return out;
205 }
206  
207 /* The set of exportable names for a package, with & stripped, as
208 * Exporter's %Cache holds it. It is rebuilt when @EXPORT or @EXPORT_OK has
209 * been replaced or changed size, and by the caller on a miss, as Exporter
210 * rebuilds on a miss. */
211 static HV *
212 1923 eo_cache_build(pTHX_ SV *pkg, AV *exp, AV *ok)
213 {
214 dMY_CXT;
215 1923 HV *set = newHV();
216 1923 AV *entry = newAV();
217 1923 eo_add_names(aTHX_ set, exp);
218 1923 eo_add_names(aTHX_ set, ok);
219 1923 av_store(entry, EO_CACHE_SET, newRV_noinc((SV *)set));
220 1923 ▶ av_store(entry, EO_CACHE_EXP, exp ? newRV_inc((SV *)exp) : newSV(0));
Branch: 1 branch
BranchTrueFalseTotal
av_store(entry, EO_CACHE_EXP, exp ? newRV_inc((SV *)exp) : newSV(0)); 1923 0 1923
221 1923 ▶ av_store(entry, EO_CACHE_OK, ok ? newRV_inc((SV *)ok) : newSV(0));
Branch: 1 branch
BranchTrueFalseTotal
av_store(entry, EO_CACHE_OK, ok ? newRV_inc((SV *)ok) : newSV(0)); 1923 0 1923
222 1923 ▶ av_store(entry, EO_CACHE_NEXP, newSViv(exp ? av_len(exp) : -2));
Branch: 1 branch
BranchTrueFalseTotal
av_store(entry, EO_CACHE_NEXP, newSViv(exp ? av_len(exp) : -2)); 1923 0 1923
223 1923 ▶ av_store(entry, EO_CACHE_NOK, newSViv(ok ? av_len(ok) : -2));
Branch: 1 branch
BranchTrueFalseTotal
av_store(entry, EO_CACHE_NOK, newSViv(ok ? av_len(ok) : -2)); 1923 0 1923
224 1923 (void)hv_store_ent(MY_CXT.exports, pkg, newRV_noinc((SV *)entry), 0);
225 1923 return set;
226 }
227  
228 static bool
229 12846 eo_cache_same(pTHX_ AV *entry, I32 slot, I32 nslot, AV *av)
230 {
231 12846 SV **ref = av_fetch(entry, slot, 0);
232 12846 SV **n = av_fetch(entry, nslot, 0);
233 AV *had;
234 12846 ▶ if (!ref || !n)
Branch: 2 branches
BranchTrueFalseTotal
if (!ref || !n) 12846 0 12846
if (!ref || !n) 0 12846 12846
235 0 return FALSE;
236 12846 ▶ had = SvROK(*ref) ? (AV *)SvRV(*ref) : NULL;
Branch: 1 branch
BranchTrueFalseTotal
had = SvROK(*ref) ? (AV *)SvRV(*ref) : NULL; 12846 0 12846
237 12846 ▶ if (had != av)
Branch: 1 branch
BranchTrueFalseTotal
if (had != av) 1 12845 12846
238 1 return FALSE;
239 12845 ▶ return SvIV(*n) == (av ? av_len(av) : -2);
Branch: 1 branch
BranchTrueFalseTotal
return SvIV(*n) == (av ? av_len(av) : -2); 12845 0 12845
240 }
241  
242 static HV *
243 6449 eo_cache_get(pTHX_ SV *pkg, AV *exp, AV *ok, bool *built)
244 {
245 dMY_CXT;
246 6449 HE *he = hv_fetch_ent(MY_CXT.exports, pkg, 0, 0);
247 6449 ▶ if (he && SvROK(HeVAL(he))) {
Branch: 2 branches
BranchTrueFalseTotal
if (he && SvROK(HeVAL(he))) { 6423 26 6449
if (he && SvROK(HeVAL(he))) { 6423 0 6423
248 6423 AV *entry = (AV *)SvRV(HeVAL(he));
249 6423 ▶ if (eo_cache_same(aTHX_ entry, EO_CACHE_EXP, EO_CACHE_NEXP, exp)
Branch: 1 branch
BranchTrueFalseTotal
if (eo_cache_same(aTHX_ entry, EO_CACHE_EXP, EO_CACHE_NEXP, exp) 6423 0 6423
250 6423 ▶ && eo_cache_same(aTHX_ entry, EO_CACHE_OK, EO_CACHE_NOK, ok)) {
Branch: 1 branch
BranchTrueFalseTotal
&& eo_cache_same(aTHX_ entry, EO_CACHE_OK, EO_CACHE_NOK, ok)) { 6419 4 6423
251 6419 SV **set = av_fetch(entry, EO_CACHE_SET, 0);
252 6419 *built = FALSE;
253 6419 return (HV *)SvRV(*set);
254 }
255 }
256 30 *built = TRUE;
257 30 return eo_cache_build(aTHX_ pkg, exp, ok);
258 }
259  
260 static bool
261 4291 eo_is_word_start(const char *s, STRLEN len, bool utf8)
262 {
263 U8 c;
264 4291 ▶ if (!len)
Branch: 1 branch
BranchTrueFalseTotal
if (!len) 0 4291 4291
265 0 return TRUE;
266 4291 c = (U8)*s;
267 4291 ▶ if (utf8 && c >= 0x80)
Branch: 2 branches
BranchTrueFalseTotal
if (utf8 && c >= 0x80) 0 4291 4291
if (utf8 && c >= 0x80) 0 0 0
268 0 return TRUE;
269 4291 return isWORDCHAR(c) ? TRUE : FALSE;
270 }
271  
272 static void eo_install_slow(pTHX_ SV *pkg, SV *callpkg, SV *name);
273  
274 /* The usual install: a plain name in two stashes, both found once for the
275 * whole import. Anything else goes the long way, by full name. */
276 static void
277 10841 eo_install_one(pTHX_ SV *pkg, SV *callpkg, HV *srcstash, HV *dststash, SV *name)
278 {
279 STRLEN len;
280 10841 const char *s = SvPV_const(name, len);
281 10841 bool utf8 = SvUTF8(name) ? TRUE : FALSE;
282 10841 char type = '&';
283 GV *src, *dgv;
284 SV *thing, *ref;
285  
286 10841 ▶ if (utf8 || !len) {
Branch: 2 branches
BranchTrueFalseTotal
if (utf8 || !len) { 10841 0 10841
if (utf8 || !len) { 0 10841 10841
287 0 eo_install_slow(aTHX_ pkg, callpkg, name);
288 1660 return;
289 }
290 10841 ▶ if (!isWORDCHAR(*s)) {
Branch: 1 branch
BranchTrueFalseTotal
if (!isWORDCHAR(*s)) { 4907 5934 10841
291 4907 type = *s;
292 4907 s++;
293 4907 len--;
294 }
295 10841 src = eo_stash_gv(aTHX_ srcstash, s, len, FALSE);
296 10841 ▶ if (!src) {
Branch: 1 branch
BranchTrueFalseTotal
if (!src) { 7 10834 10841
297 7 eo_install_slow(aTHX_ pkg, callpkg, name);
298 7 return;
299 }
300 10834 switch (type) {
301 5929 ▶ case '&': thing = (SV *)GvCVu(src); break;
Branch: 1 branch
BranchTrueFalseTotal
case '&': thing = (SV *)GvCVu(src); break; 5929 0 5929
302 1704 ▶ case '$': thing = GvSVn(src); break;
Branch: 1 branch
BranchTrueFalseTotal
case '$': thing = GvSVn(src); break; 1704 0 1704
303 1522 ▶ case '@': thing = (SV *)GvAVn(src); break;
Branch: 1 branch
BranchTrueFalseTotal
case '@': thing = (SV *)GvAVn(src); break; 1522 0 1522
304 586 ▶ case '%': thing = (SV *)GvHVn(src); break;
Branch: 1 branch
BranchTrueFalseTotal
case '%': thing = (SV *)GvHVn(src); break; 586 0 586
305 1093 case '*': thing = (SV *)src; break;
306 0 default: thing = NULL; break;
307 }
308 10834 ▶ if (!thing || !(dgv = eo_stash_gv_add(aTHX_ dststash, s, len, FALSE))) {
Branch: 2 branches
BranchTrueFalseTotal
if (!thing || !(dgv = eo_stash_gv_add(aTHX_ dststash, s, len, FALSE))) { 10833 1 10834
if (!thing || !(dgv = eo_stash_gv_add(aTHX_ dststash, s, len, FALSE))) { 559 10274 10833
309 560 eo_install_slow(aTHX_ pkg, callpkg, name);
310 560 return;
311 }
312  
313 10274 ▶ if (type == '*') {
Branch: 1 branch
BranchTrueFalseTotal
if (type == '*') { 1093 9181 10274
314 1093 sv_setsv_mg((SV *)dgv, thing);
315 1093 GvIMPORTED_on(dgv);
316 1093 return;
317 }
318 9181 ref = newRV_inc(thing);
319 9181 sv_setsv_mg((SV *)dgv, ref);
320 9181 SvREFCNT_dec(ref);
321 9181 switch (type) {
322 5379 case '&': GvIMPORTED_CV_on(dgv); break;
323 1700 case '$': GvIMPORTED_SV_on(dgv); break;
324 1519 case '@': GvIMPORTED_AV_on(dgv); break;
325 583 case '%': GvIMPORTED_HV_on(dgv); break;
326 }
327 }
328  
329 static void
330 567 eo_install_slow(pTHX_ SV *pkg, SV *callpkg, SV *name)
331 {
332 STRLEN len;
333 567 const char *s = SvPV_const(name, len);
334 567 bool utf8 = SvUTF8(name) ? TRUE : FALSE;
335 567 char type = '&';
336 SV *src, *dst, *ref;
337 GV *gv, *dgv;
338  
339 567 ▶ if (!eo_is_word_start(s, len, utf8)) {
Branch: 1 branch
BranchTrueFalseTotal
if (!eo_is_word_start(s, len, utf8)) { 11 556 567
340 11 type = *s;
341 11 s++;
342 11 len--;
343 }
344  
345 567 src = eo_qualify(aTHX_ pkg, s, len, utf8);
346 567 dst = eo_qualify(aTHX_ callpkg, s, len, utf8);
347  
348 567 switch (type) {
349 556 case '&': {
350 HV *st;
351 556 CV *cv = sv_2cv(src, &st, &gv, GV_ADDMULTI);
352 556 ref = sv_2mortal(newRV_inc((SV *)cv));
353 556 break;
354 }
355 5 case '$':
356 5 gv = gv_fetchsv(src, GV_ADDMULTI, SVt_PV);
357 5 ▶ ref = sv_2mortal(newRV_inc(GvSVn(gv)));
Branch: 1 branch
BranchTrueFalseTotal
ref = sv_2mortal(newRV_inc(GvSVn(gv))); 5 0 5
358 5 break;
359 3 case '@':
360 3 gv = gv_fetchsv(src, GV_ADDMULTI, SVt_PVAV);
361 3 ▶ ref = sv_2mortal(newRV_inc((SV *)GvAVn(gv)));
Branch: 1 branch
BranchTrueFalseTotal
ref = sv_2mortal(newRV_inc((SV *)GvAVn(gv))); 3 0 3
362 3 break;
363 3 case '%':
364 3 gv = gv_fetchsv(src, GV_ADDMULTI, SVt_PVHV);
365 3 ▶ ref = sv_2mortal(newRV_inc((SV *)GvHVn(gv)));
Branch: 1 branch
BranchTrueFalseTotal
ref = sv_2mortal(newRV_inc((SV *)GvHVn(gv))); 3 0 3
366 3 break;
367 0 case '*':
368 0 ref = (SV *)gv_fetchsv(src, GV_ADDMULTI, SVt_PVGV);
369 0 break;
370 0 default:
371 0 Perl_croak(aTHX_ "Can't export symbol: %c%" SVf, type,
372 0 ▶ SVfARG(newSVpvn_flags(s, len, SVs_TEMP | (utf8 ? SVf_UTF8 : 0))));
Branch: 1 branch
BranchTrueFalseTotal
SVfARG(newSVpvn_flags(s, len, SVs_TEMP | (utf8 ? SVf_UTF8 : 0)))); 0 0 0
373 }
374  
375 567 dgv = gv_fetchsv(dst, GV_ADDMULTI, SVt_PVGV);
376 567 sv_setsv_mg((SV *)dgv, ref);
377  
378 567 switch (type) {
379 556 case '&': GvIMPORTED_CV_on(dgv); break;
380 5 case '$': GvIMPORTED_SV_on(dgv); break;
381 3 case '@': GvIMPORTED_AV_on(dgv); break;
382 3 case '%': GvIMPORTED_HV_on(dgv); break;
383 0 case '*': GvIMPORTED_on(dgv); break;
384 }
385 567 }
386  
387 /* Exporter assigns the globs from its own file, which has no lexical
388 * warnings, so a redefinition warns only under $^W. The copy of the caller's
389 * statement keeps its file and line for the message and drops its warnings. */
390 static void
391 3087 eo_install_list(pTHX_ SV *pkg, SV *callpkg, HV *srcstash, SV **list, SSize_t n)
392 {
393 COP fake;
394 SSize_t i;
395  
396 3087 ENTER;
397 3087 StructCopy(PL_curcop, &fake, COP);
398 3087 fake.cop_warnings = pWARN_STD;
399 3087 SAVEVPTR(PL_curcop);
400 3087 PL_curcop = &fake;
401  
402 {
403 3087 HV *dststash = gv_stashsv(callpkg, GV_ADD);
404 13928 ▶ for (i = 0; i < n; i++)
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < n; i++) 10841 3087 13928
405 10841 ▶ if (list[i])
Branch: 1 branch
BranchTrueFalseTotal
if (list[i]) 10841 0 10841
406 10841 eo_install_one(aTHX_ pkg, callpkg, srcstash, dststash, list[i]);
407 }
408  
409 3087 LEAVE;
410 3087 }
411  
412 static void
413 3067 eo_install(pTHX_ SV *pkg, SV *callpkg, AV *names)
414 {
415 3067 eo_install_list(aTHX_ pkg, callpkg, gv_stashsv(pkg, 0), AvARRAY(names), av_len(names) + 1);
416 3067 }
417  
418 static void
419 1092 eo_call_version(pTHX_ SV *pkg, SV *wanted)
420 {
421 1092 dSP;
422 1092 ENTER;
423 1092 SAVETMPS;
424 1092 ▶ PUSHMARK(SP);
Branch: 1 branch
BranchTrueFalseTotal
PUSHMARK(SP); 0 1092 1092
425 1092 ▶ XPUSHs(pkg);
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(pkg); 0 1092 1092
426 1092 ▶ XPUSHs(wanted);
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(wanted); 0 1092 1092
427 1092 PUTBACK;
428 1092 call_method("VERSION", G_DISCARD);
429 1089 ▶ FREETMPS;
Branch: 1 branch
BranchTrueFalseTotal
FREETMPS; 1089 0 1089
430 1089 LEAVE;
431 1089 }
432  
433 /* The names in a list of specs, in the order first added. Exporter keeps
434 * them in a hash, so its order is the hash's; the set is the same. */
435 typedef struct {
436 AV *order;
437 HV *at;
438 } eo_picks;
439  
440 static void
441 29791 eo_pick(pTHX_ eo_picks *p, SV *name, bool remove)
442 {
443 29791 ▶ if (remove) {
Branch: 1 branch
BranchTrueFalseTotal
if (remove) { 6158 23633 29791
444 6158 (void)hv_delete_ent(p->at, name, G_DISCARD, 0);
445 }
446 23633 ▶ else if (!hv_exists_ent(p->at, name, 0)) {
Branch: 1 branch
BranchTrueFalseTotal
else if (!hv_exists_ent(p->at, name, 0)) { 21035 2598 23633
447 21035 av_push(p->order, newSVsv(name));
448 21035 (void)hv_store_ent(p->at, name, newSViv(av_len(p->order)), 0);
449 }
450 29791 }
451  
452 static AV *
453 5218 eo_picked(pTHX_ eo_picks *p)
454 {
455 5218 AV *out = (AV *)sv_2mortal((SV *)newAV());
456 5218 SSize_t i, top = av_len(p->order);
457 26253 ▶ for (i = 0; i <= top; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i <= top; i++) { 21035 5218 26253
458 21035 SV *name = *av_fetch(p->order, i, 0);
459 21035 HE *he = hv_fetch_ent(p->at, name, 0, 0);
460 21035 ▶ if (he && SvIV(HeVAL(he)) == i)
Branch: 2 branches
BranchTrueFalseTotal
if (he && SvIV(HeVAL(he)) == i) 18813 2222 21035
if (he && SvIV(HeVAL(he)) == i) 18346 467 18813
461 18346 av_push(out, newSVsv(name));
462 }
463 5218 return out;
464 }
465  
466 static bool
467 6386 eo_has_specs(pTHX_ AV *names)
468 {
469 6386 SSize_t i, top = av_len(names);
470 12913 ▶ for (i = 0; i <= top; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i <= top; i++) { 11748 1165 12913
471 STRLEN len;
472 11748 const char *s = SvPV_const(*av_fetch(names, i, 0), len);
473 11748 ▶ if (len && (*s == '/' || *s == '!' || *s == ':'))
Branch: 4 branches
BranchTrueFalseTotal
if (len && (*s == '/' || *s == '!' || *s == ':')) 11065 683 11748
if (len && (*s == '/' || *s == '!' || *s == ':')) 10404 661 11065
if (len && (*s == '/' || *s == '!' || *s == ':')) 8454 1950 10404
if (len && (*s == '/' || *s == '!' || *s == ':')) 2610 5844 8454
474 5221 return TRUE;
475 }
476 1165 return FALSE;
477 }
478  
479 static AV *
480 1850 eo_all_exports(pTHX_ AV *exp, AV *ok)
481 {
482 1850 AV *all = (AV *)sv_2mortal((SV *)newAV());
483 1850 HV *seen = (HV *)sv_2mortal((SV *)newHV());
484 AV *lists[2];
485 int l;
486 1850 lists[0] = exp;
487 1850 lists[1] = ok;
488 5550 ▶ for (l = 0; l < 2; l++) {
Branch: 1 branch
BranchTrueFalseTotal
for (l = 0; l < 2; l++) { 3700 1850 5550
489 SSize_t i, top;
490 3700 ▶ if (!lists[l])
Branch: 1 branch
BranchTrueFalseTotal
if (!lists[l]) 0 3700 3700
491 0 continue;
492 3700 top = av_len(lists[l]);
493 20403 ▶ for (i = 0; i <= top; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i <= top; i++) { 16703 3700 20403
494 16703 SV **svp = av_fetch(lists[l], i, 0);
495 SV *name;
496 16703 ▶ if (!svp)
Branch: 1 branch
BranchTrueFalseTotal
if (!svp) 0 16703 16703
497 0 continue;
498 16703 name = eo_strip_amp(aTHX_ *svp);
499 16703 ▶ if (hv_exists_ent(seen, name, 0))
Branch: 1 branch
BranchTrueFalseTotal
if (hv_exists_ent(seen, name, 0)) 1 16702 16703
500 1 continue;
501 16702 (void)hv_store_ent(seen, name, &PL_sv_yes, 0);
502 16702 av_push(all, newSVsv(name));
503 }
504 }
505 1850 return all;
506 }
507  
508 static void
509 2063 eo_grep(pTHX_ AV *into, AV *from, const char *pat, STRLEN plen, bool utf8)
510 {
511 2063 ▶ SV *patsv = newSVpvn_flags(pat, plen, SVs_TEMP | (utf8 ? SVf_UTF8 : 0));
Branch: 1 branch
BranchTrueFalseTotal
SV *patsv = newSVpvn_flags(pat, plen, SVs_TEMP | (utf8 ? SVf_UTF8 : 0)); 0 2063 2063
512 REGEXP *rx;
513 COP fake;
514 2063 SSize_t i, top = av_len(from);
515  
516 2063 ENTER;
517 2063 StructCopy(PL_curcop, &fake, COP);
518 2063 fake.cop_hints = 0;
519 2063 SAVEVPTR(PL_curcop);
520 2063 PL_curcop = &fake;
521 2063 SAVEI32(*(I32 *)&PL_hints);
522 2063 PL_hints = 0;
523 2063 rx = pregcomp(patsv, 0);
524 2060 LEAVE;
525  
526 20638 ▶ for (i = 0; i <= top; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i <= top; i++) { 18578 2060 20638
527 18578 SV *name = *av_fetch(from, i, 0);
528 STRLEN len;
529 18578 char *s = SvPV(name, len);
530 18578 ▶ if (pregexec(rx, s, s + len, s, 0, name, 1))
Branch: 1 branch
BranchTrueFalseTotal
if (pregexec(rx, s, s + len, s, 0, name, 1)) 8220 10358 18578
531 8220 av_push(into, newSVsv(name));
532 }
533 2060 ReREFCNT_dec(rx);
534 2060 }
535  
536 static AV *
537 5221 eo_walk_specs(pTHX_ SV *pkg, AV *specs, AV *exp, AV *ok, bool verbose, I32 *oops)
538 {
539 5221 HV *tags = eo_pkg_hv(aTHX_ pkg, STR_WITH_LEN("EXPORT_TAGS"));
540 5221 AV *all = NULL;
541 eo_picks p;
542 SSize_t i, top;
543  
544 5221 p.order = (AV *)sv_2mortal((SV *)newAV());
545 5221 p.at = (HV *)sv_2mortal((SV *)newHV());
546  
547 5221 ▶ if (av_len(specs) >= 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (av_len(specs) >= 0) { 5221 0 5221
548 STRLEN len;
549 5221 const char *s = SvPV_const(*av_fetch(specs, 0, 0), len);
550 5221 ▶ if (len && *s == '!')
Branch: 2 branches
BranchTrueFalseTotal
if (len && *s == '!') 4957 264 5221
if (len && *s == '!') 1051 3906 4957
551 1051 av_unshift(specs, 1), av_store(specs, 0, newSVpvs(":DEFAULT"));
552 }
553  
554 5221 top = av_len(specs);
555 21607 ▶ for (i = 0; i <= top; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i <= top; i++) { 16389 5218 21607
556 16389 SV *spec = *av_fetch(specs, i, 0);
557 16389 AV *names = (AV *)sv_2mortal((SV *)newAV());
558 STRLEN len;
559 16389 const char *s = SvPV_const(spec, len);
560 16389 bool utf8 = SvUTF8(spec) ? TRUE : FALSE;
561 16389 bool remove = FALSE;
562 SSize_t j, ntop;
563  
564 16389 ▶ if (len && *s == '!') {
Branch: 2 branches
BranchTrueFalseTotal
if (len && *s == '!') { 15605 784 16389
if (len && *s == '!') { 3085 12520 15605
565 3085 remove = TRUE;
566 3085 s++;
567 3085 len--;
568 }
569  
570 21560 ▶ if (len && *s == ':') {
Branch: 2 branches
BranchTrueFalseTotal
if (len && *s == ':') { 15605 784 16389
if (len && *s == ':') { 6197 9408 15605
571 6197 ▶ SV *tag = newSVpvn_flags(s + 1, len - 1, SVs_TEMP | (utf8 ? SVf_UTF8 : 0));
Branch: 1 branch
BranchTrueFalseTotal
SV *tag = newSVpvn_flags(s + 1, len - 1, SVs_TEMP | (utf8 ? SVf_UTF8 : 0)); 0 6197 6197
572 HE *he;
573 6197 ▶ if (len - 1 == 7 && memEQ(s + 1, "DEFAULT", 7)) {
Branch: 2 branches
BranchTrueFalseTotal
if (len - 1 == 7 && memEQ(s + 1, "DEFAULT", 7)) { 2079 4118 6197
if (len - 1 == 7 && memEQ(s + 1, "DEFAULT", 7)) { 2079 0 2079
574 2079 eo_av_append(aTHX_ names, exp);
575 }
576 7210 ▶ else if (tags && (he = hv_fetch_ent(tags, tag, 0, 0)) && SvTRUE(HeVAL(he))) {
Branch: 3 branches
BranchTrueFalseTotal
else if (tags && (he = hv_fetch_ent(tags, tag, 0, 0)) && SvTRUE(HeVAL(he))) { 4118 0 4118
else if (tags && (he = hv_fetch_ent(tags, tag, 0, 0)) && SvTRUE(HeVAL(he))) { 3092 1026 4118
else if (tags && (he = hv_fetch_ent(tags, tag, 0, 0)) && SvTRUE(HeVAL(he))) { 3092 0 3092
577 3092 SV *val = HeVAL(he);
578 3092 ▶ if (!SvROK(val) || SvTYPE(SvRV(val)) != SVt_PVAV)
Branch: 2 branches
BranchTrueFalseTotal
if (!SvROK(val) || SvTYPE(SvRV(val)) != SVt_PVAV) 3092 0 3092
if (!SvROK(val) || SvTYPE(SvRV(val)) != SVt_PVAV) 0 3092 3092
579 0 Perl_croak(aTHX_ "Not an ARRAY reference");
580 3092 eo_av_append(aTHX_ names, (AV *)SvRV(val));
581 }
582 else {
583 1026 Perl_warn(aTHX_ "\"%" SVf "\" is not defined in %%%" SVf "::EXPORT_TAGS",
584 SVfARG(tag), SVfARG(pkg));
585 1026 ++*oops;
586 1026 continue;
587 }
588 }
589 10192 ▶ else if (len >= 2 && *s == '/'
Branch: 2 branches
BranchTrueFalseTotal
else if (len >= 2 && *s == '/' 9407 785 10192
else if (len >= 2 && *s == '/' 2063 7344 9407
590 4123 ▶ && (s[len - 1] == '/' || (len >= 3 && s[len - 1] == '\n' && s[len - 2] == '/'))) {
Branch: 4 branches
BranchTrueFalseTotal
&& (s[len - 1] == '/' || (len >= 3 && s[len - 1] == '\n' && s[len - 2] == '/'))) { 0 2063 2063
&& (s[len - 1] == '/' || (len >= 3 && s[len - 1] == '\n' && s[len - 2] == '/'))) { 0 0 0
&& (s[len - 1] == '/' || (len >= 3 && s[len - 1] == '\n' && s[len - 2] == '/'))) { 0 0 0
&& (s[len - 1] == '/' || (len >= 3 && s[len - 1] == '\n' && s[len - 2] == '/'))) { 0 0 0
591 2063 ▶ STRLEN plen = s[len - 1] == '/' ? len - 2 : len - 3;
Branch: 1 branch
BranchTrueFalseTotal
STRLEN plen = s[len - 1] == '/' ? len - 2 : len - 3; 2063 0 2063
592 2063 ▶ if (!all)
Branch: 1 branch
BranchTrueFalseTotal
if (!all) 1850 213 2063
593 1850 all = eo_all_exports(aTHX_ exp, ok);
594 2063 eo_grep(aTHX_ names, all, s + 1, plen, utf8);
595 }
596 else {
597 8129 ▶ av_push(names, newSVpvn_flags(s, len, utf8 ? SVf_UTF8 : 0));
Branch: 1 branch
BranchTrueFalseTotal
av_push(names, newSVpvn_flags(s, len, utf8 ? SVf_UTF8 : 0)); 0 8129 8129
598 }
599  
600 15360 ▶ if (verbose)
Branch: 1 branch
BranchTrueFalseTotal
if (verbose) 3 15357 15360
601 3 ▶ Perl_warn(aTHX_ "Import %s: %" SVf " ", remove ? "del" : "add",
Branch: 1 branch
BranchTrueFalseTotal
Perl_warn(aTHX_ "Import %s: %" SVf " ", remove ? "del" : "add", 1 2 3
602 3 SVfARG(eo_join(aTHX_ names, " ")));
603  
604 15360 ntop = av_len(names);
605 45151 ▶ for (j = 0; j <= ntop; j++)
Branch: 1 branch
BranchTrueFalseTotal
for (j = 0; j <= ntop; j++) 29791 15360 45151
606 29791 eo_pick(aTHX_ &p, *av_fetch(names, j, 0), remove);
607 }
608  
609 5218 return eo_picked(aTHX_ &p);
610 }
611  
612 static AV *
613 673 eo_call_export_fail(pTHX_ SV *pkg, AV *failed)
614 {
615 dMY_CXT;
616 673 HV *stash = gv_stashsv(pkg, 0);
617 673 ▶ GV *meth = stash ? gv_fetchmethod_autoload(stash, "export_fail", FALSE) : NULL;
Branch: 1 branch
BranchTrueFalseTotal
GV *meth = stash ? gv_fetchmethod_autoload(stash, "export_fail", FALSE) : NULL; 673 0 673
618 673 ▶ CV *fcv = (meth && isGV_with_GP(meth)) ? GvCV(meth) : NULL;
Branch: 4 branches
BranchTrueFalseTotal
CV *fcv = (meth && isGV_with_GP(meth)) ? GvCV(meth) : NULL; 672 1 673
CV *fcv = (meth && isGV_with_GP(meth)) ? GvCV(meth) : NULL; 672 0 672
CV *fcv = (meth && isGV_with_GP(meth)) ? GvCV(meth) : NULL; 0 672 672
CV *fcv = (meth && isGV_with_GP(meth)) ? GvCV(meth) : NULL; 0 0 0
619 673 AV *out = (AV *)sv_2mortal((SV *)newAV());
620 SSize_t i, top;
621 I32 count;
622 673 dSP;
623  
624 673 ▶ if (!fcv || fcv == MY_CXT.export_fail_cv) {
Branch: 2 branches
BranchTrueFalseTotal
if (!fcv || fcv == MY_CXT.export_fail_cv) { 672 1 673
if (!fcv || fcv == MY_CXT.export_fail_cv) { 0 672 672
625 1 eo_av_append(aTHX_ out, failed);
626 1 return out;
627 }
628  
629 672 ENTER;
630 672 SAVETMPS;
631 672 ▶ PUSHMARK(SP);
Branch: 1 branch
BranchTrueFalseTotal
PUSHMARK(SP); 0 672 672
632 672 top = av_len(failed);
633 672 ▶ EXTEND(SP, top + 2);
Branch: 2 branches
BranchTrueFalseTotal
EXTEND(SP, top + 2); 672 0 672
EXTEND(SP, top + 2); 0 672 672
634 672 PUSHs(pkg);
635 1371 ▶ for (i = 0; i <= top; i++)
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i <= top; i++) 699 672 1371
636 699 PUSHs(*av_fetch(failed, i, 0));
637 672 PUTBACK;
638 672 count = call_sv((SV *)fcv, G_ARRAY);
639 672 SPAGAIN;
640 1364 ▶ for (i = 0; i < count; i++)
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < count; i++) 692 672 1364
641 692 av_push(out, newSVsv(SP[i - count + 1]));
642 672 SP -= count;
643 672 PUTBACK;
644 672 ▶ FREETMPS;
Branch: 1 branch
BranchTrueFalseTotal
FREETMPS; 668 4 672
645 672 LEAVE;
646 672 return out;
647 }
648  
649 static void
650 3736 eo_check_fail(pTHX_ SV *pkg, AV *names, bool verbose)
651 {
652 3736 AV *fail = eo_pkg_av(aTHX_ pkg, STR_WITH_LEN("EXPORT_FAIL"));
653 HV *fset;
654 AV *expanded, *failed;
655 SSize_t i, top;
656  
657 3736 ▶ if (!fail || av_len(fail) < 0)
Branch: 2 branches
BranchTrueFalseTotal
if (!fail || av_len(fail) < 0) 3725 11 3736
if (!fail || av_len(fail) < 0) 43 3682 3725
658 54 return;
659  
660 3682 fset = (HV *)sv_2mortal((SV *)newHV());
661 3682 expanded = (AV *)sv_2mortal((SV *)newAV());
662 3682 top = av_len(fail);
663 7406 ▶ for (i = 0; i <= top; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i <= top; i++) { 3724 3682 7406
664 3724 SV **svp = av_fetch(fail, i, 0);
665 STRLEN len;
666 const char *s;
667 3724 ▶ if (!svp)
Branch: 1 branch
BranchTrueFalseTotal
if (!svp) 0 3724 3724
668 0 continue;
669 3724 s = SvPV_const(*svp, len);
670 3724 av_push(expanded, newSVsv(*svp));
671 3724 (void)hv_store_ent(fset, *svp, &PL_sv_yes, 0);
672 3724 ▶ if (len && eo_is_word_start(s, len, SvUTF8(*svp) ? TRUE : FALSE)) {
Branch: 2 branches
BranchTrueFalseTotal
if (len && eo_is_word_start(s, len, SvUTF8(*svp) ? TRUE : FALSE)) { 3724 0 3724
if (len && eo_is_word_start(s, len, SvUTF8(*svp) ? TRUE : FALSE)) { 3724 0 3724
673 3724 SV *amp = sv_2mortal(newSVpvs("&"));
674 3724 sv_catsv(amp, *svp);
675 3724 av_push(expanded, newSVsv(amp));
676 3724 (void)hv_store_ent(fset, amp, &PL_sv_yes, 0);
677 }
678 }
679 3682 ▶ if (verbose)
Branch: 1 branch
BranchTrueFalseTotal
if (verbose) 1 3681 3682
680 1 Perl_warn(aTHX_ "%" SVf "::EXPORT_FAIL cached: %" SVf,
681 1 SVfARG(pkg), SVfARG(eo_join(aTHX_ expanded, " ")));
682  
683 3682 failed = (AV *)sv_2mortal((SV *)newAV());
684 3682 top = av_len(names);
685 16795 ▶ for (i = 0; i <= top; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i <= top; i++) { 13113 3682 16795
686 13113 SV *sym = *av_fetch(names, i, 0);
687 13113 ▶ if (hv_exists_ent(fset, sym, 0))
Branch: 1 branch
BranchTrueFalseTotal
if (hv_exists_ent(fset, sym, 0)) 700 12413 13113
688 700 av_push(failed, newSVsv(sym));
689 }
690 3682 ▶ if (av_len(failed) < 0)
Branch: 1 branch
BranchTrueFalseTotal
if (av_len(failed) < 0) 3009 673 3682
691 3009 return;
692  
693 673 failed = eo_call_export_fail(aTHX_ pkg, failed);
694 673 top = av_len(failed);
695 1366 ▶ for (i = 0; i <= top; i++)
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i <= top; i++) 693 673 1366
696 693 Perl_warn(aTHX_ "\"%" SVf "\" is not implemented by the %" SVf " module on this architecture",
697 693 SVfARG(*av_fetch(failed, i, 0)), SVfARG(pkg));
698 673 ▶ if (top >= 0)
Branch: 1 branch
BranchTrueFalseTotal
if (top >= 0) 669 4 673
699 669 Perl_croak(aTHX_ "Can't continue after import errors");
700 }
701  
702 static void
703 24378 eo_vivify(pTHX_ SV *pkg, const char *name, STRLEN len, svtype type)
704 {
705 24378 GV *gv = eo_stash_gv(aTHX_ gv_stashsv(pkg, 0), name, len, FALSE);
706 24378 ▶ if (!gv)
Branch: 1 branch
BranchTrueFalseTotal
if (!gv) 26 24352 24378
707 26 gv = gv_fetchsv(eo_qualify(aTHX_ pkg, name, len, FALSE), GV_ADDMULTI, type);
708 24378 ▶ if (type == SVt_PVAV)
Branch: 1 branch
BranchTrueFalseTotal
if (type == SVt_PVAV) 19157 5221 24378
709 19157 ▶ (void)GvAVn(gv);
Branch: 1 branch
BranchTrueFalseTotal
(void)GvAVn(gv); 19157 0 19157
710 else
711 5221 ▶ (void)GvHVn(gv);
Branch: 1 branch
BranchTrueFalseTotal
(void)GvHVn(gv); 5221 0 5221
712 24378 }
713  
714 static bool
715 7171 eo_has_nonword(const char *s, STRLEN len, bool utf8)
716 {
717 STRLEN i;
718 12891 ▶ for (i = 0; i < len; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < len; i++) { 10848 2043 12891
719 10848 U8 c = (U8)s[i];
720 10848 ▶ if (utf8 && c >= 0x80)
Branch: 2 branches
BranchTrueFalseTotal
if (utf8 && c >= 0x80) 0 10848 10848
if (utf8 && c >= 0x80) 0 0 0
721 0 continue;
722 10848 ▶ if (!isWORDCHAR(c))
Branch: 1 branch
BranchTrueFalseTotal
if (!isWORDCHAR(c)) 5128 5720 10848
723 5128 return TRUE;
724 }
725 2043 return FALSE;
726 }
727  
728 /* Exporter.pm's import takes Exporter::Heavy only for some lists, and the
729 * heavy path is the one that touches @EXPORT_FAIL. This is its test. */
730 static bool
731 6390 eo_would_be_heavy(pTHX_ SV *pkg, AV *list, bool args, HV *set, bool verbose)
732 {
733 6390 HV *stash = gv_stashsv(pkg, 0);
734 6390 ▶ SV **failgv = stash ? hv_fetchs(stash, "EXPORT_FAIL", 0) : NULL;
Branch: 1 branch
BranchTrueFalseTotal
SV **failgv = stash ? hv_fetchs(stash, "EXPORT_FAIL", 0) : NULL; 6390 0 6390
735 6390 ▶ AV *fail = failgv ? eo_pkg_av(aTHX_ pkg, STR_WITH_LEN("EXPORT_FAIL")) : NULL;
Branch: 1 branch
BranchTrueFalseTotal
AV *fail = failgv ? eo_pkg_av(aTHX_ pkg, STR_WITH_LEN("EXPORT_FAIL")) : NULL; 6368 22 6390
736 6390 SV *first = NULL;
737 SSize_t i, top;
738  
739 6390 ▶ if (verbose)
Branch: 1 branch
BranchTrueFalseTotal
if (verbose) 4 6386 6390
740 4 return TRUE;
741 6386 ▶ if (fail && av_len(fail) >= 1)
Branch: 2 branches
BranchTrueFalseTotal
if (fail && av_len(fail) >= 1) 6365 21 6386
if (fail && av_len(fail) >= 1) 53 6312 6365
742 53 return TRUE;
743 6333 ▶ if (fail && av_len(fail) >= 0) {
Branch: 2 branches
BranchTrueFalseTotal
if (fail && av_len(fail) >= 0) { 6312 21 6333
if (fail && av_len(fail) >= 0) { 6273 39 6312
744 6273 SV **svp = av_fetch(fail, 0, 0);
745 6273 ▶ first = svp ? *svp : NULL;
Branch: 1 branch
BranchTrueFalseTotal
first = svp ? *svp : NULL; 6273 0 6273
746 }
747  
748 6333 ▶ top = list ? av_len(list) : -1;
Branch: 1 branch
BranchTrueFalseTotal
top = list ? av_len(list) : -1; 6333 0 6333
749 7126 ▶ for (i = 0; i <= top; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i <= top; i++) { 7099 27 7126
750 7099 SV **svp = av_fetch(list, i, 0);
751 STRLEN len;
752 const char *s;
753 7099 ▶ if (!svp)
Branch: 1 branch
BranchTrueFalseTotal
if (!svp) 0 7099 7099
754 0 continue;
755 7099 s = SvPV_const(*svp, len);
756 7099 ▶ if (eo_has_nonword(s, len, SvUTF8(*svp) ? TRUE : FALSE))
Branch: 1 branch
BranchTrueFalseTotal
if (eo_has_nonword(s, len, SvUTF8(*svp) ? TRUE : FALSE)) 5101 1998 7099
757 6306 return TRUE;
758 1998 ▶ if (args && set && !hv_exists_ent(set, *svp, 0))
Branch: 3 branches
BranchTrueFalseTotal
if (args && set && !hv_exists_ent(set, *svp, 0)) 1985 13 1998
if (args && set && !hv_exists_ent(set, *svp, 0)) 1985 0 1985
if (args && set && !hv_exists_ent(set, *svp, 0)) 818 1167 1985
759 818 return TRUE;
760 1180 ▶ if (first && sv_eq(*svp, first))
Branch: 2 branches
BranchTrueFalseTotal
if (first && sv_eq(*svp, first)) 1158 22 1180
if (first && sv_eq(*svp, first)) 387 771 1158
761 387 return TRUE;
762 }
763 27 return FALSE;
764 }
765  
766 static void
767 6419 eo_export(pTHX_ SV *pkg, SV *callpkg, SV **items, I32 n, const COP *errcop, bool via_import)
768 {
769 dMY_CXT;
770 AV *exp, *names;
771 6419 ▶ bool verbose = SvTRUE(GvSVn(MY_CXT.verbose_gv)) ? TRUE : FALSE;
Branch: 1 branch
BranchTrueFalseTotal
bool verbose = SvTRUE(GvSVn(MY_CXT.verbose_gv)) ? TRUE : FALSE; 6419 0 6419
772  
773 6419 ENTER;
774 6419 ▶ if (errcop && errcop != PL_curcop) {
Branch: 2 branches
BranchTrueFalseTotal
if (errcop && errcop != PL_curcop) { 6419 0 6419
if (errcop && errcop != PL_curcop) { 5 6414 6419
775 5 SAVEVPTR(PL_curcop);
776 5 PL_curcop = (COP *)errcop;
777 }
778  
779 /* The common import: plain names, every one already known, and nothing
780 * that would send Exporter.pm down its heavy path. It is installed
781 * straight from the stack. */
782 6419 ▶ if (n > 0 && via_import && !verbose) {
Branch: 3 branches
BranchTrueFalseTotal
if (n > 0 && via_import && !verbose) { 6406 13 6419
if (n > 0 && via_import && !verbose) { 6398 8 6406
if (n > 0 && via_import && !verbose) { 6395 3 6398
783 6395 HV *stash = gv_stashsv(pkg, 0);
784 6395 GV *expgv = eo_stash_gv(aTHX_ stash, STR_WITH_LEN("EXPORT"), FALSE);
785 6395 GV *okgv = eo_stash_gv(aTHX_ stash, STR_WITH_LEN("EXPORT_OK"), FALSE);
786 6395 ▶ SV **failp = stash ? hv_fetchs(stash, "EXPORT_FAIL", 0) : NULL;
Branch: 1 branch
BranchTrueFalseTotal
SV **failp = stash ? hv_fetchs(stash, "EXPORT_FAIL", 0) : NULL; 6395 0 6395
787 6395 ▶ AV *fail = (failp && isGV_with_GP(*failp)) ? GvAV((GV *)*failp) : NULL;
Branch: 4 branches
BranchTrueFalseTotal
AV *fail = (failp && isGV_with_GP(*failp)) ? GvAV((GV *)*failp) : NULL; 6374 21 6395
AV *fail = (failp && isGV_with_GP(*failp)) ? GvAV((GV *)*failp) : NULL; 6374 0 6374
AV *fail = (failp && isGV_with_GP(*failp)) ? GvAV((GV *)*failp) : NULL; 0 6374 6374
AV *fail = (failp && isGV_with_GP(*failp)) ? GvAV((GV *)*failp) : NULL; 0 0 0
788 6395 ▶ if (expgv && GvAV(expgv) && okgv && GvAV(okgv)
Branch: 4 branches
BranchTrueFalseTotal
if (expgv && GvAV(expgv) && okgv && GvAV(okgv) 6386 9 6395
if (expgv && GvAV(expgv) && okgv && GvAV(okgv) 6386 0 6386
if (expgv && GvAV(expgv) && okgv && GvAV(okgv) 6386 0 6386
if (expgv && GvAV(expgv) && okgv && GvAV(okgv) 6386 0 6386
789 6386 ▶ && (!failp || (isGV_with_GP(*failp) && (!fail || av_len(fail) < 0)))) {
Branch: 6 branches
BranchTrueFalseTotal
&& (!failp || (isGV_with_GP(*failp) && (!fail || av_len(fail) < 0)))) { 6373 13 6386
&& (!failp || (isGV_with_GP(*failp) && (!fail || av_len(fail) < 0)))) { 6373 0 6373
&& (!failp || (isGV_with_GP(*failp) && (!fail || av_len(fail) < 0)))) { 0 6373 6373
&& (!failp || (isGV_with_GP(*failp) && (!fail || av_len(fail) < 0)))) { 0 0 0
&& (!failp || (isGV_with_GP(*failp) && (!fail || av_len(fail) < 0)))) { 6373 0 6373
&& (!failp || (isGV_with_GP(*failp) && (!fail || av_len(fail) < 0)))) { 50 6323 6373
790 bool current;
791 63 HV *set = eo_cache_get(aTHX_ pkg, GvAV(expgv), GvAV(okgv), &current);
792 I32 i;
793 92 ▶ for (i = 0; i < n; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < n; i++) { 72 20 92
794 STRLEN len;
795 const char *s;
796 72 ▶ if (!SvPOK(items[i]) || SvGMAGICAL(items[i]))
Branch: 2 branches
BranchTrueFalseTotal
if (!SvPOK(items[i]) || SvGMAGICAL(items[i])) 72 0 72
if (!SvPOK(items[i]) || SvGMAGICAL(items[i])) 72 0 72
797 break;
798 72 s = SvPVX_const(items[i]);
799 72 len = SvCUR(items[i]);
800 72 ▶ if (!len || eo_has_nonword(s, len, SvUTF8(items[i]) ? TRUE : FALSE)
Branch: 2 branches
BranchTrueFalseTotal
if (!len || eo_has_nonword(s, len, SvUTF8(items[i]) ? TRUE : FALSE) 72 0 72
if (!len || eo_has_nonword(s, len, SvUTF8(items[i]) ? TRUE : FALSE) 45 27 72
801 45 ▶ || !hv_exists_ent(set, items[i], 0))
Branch: 1 branch
BranchTrueFalseTotal
|| !hv_exists_ent(set, items[i], 0)) 29 16 45
802 break;
803 }
804 63 ▶ if (i == n) {
Branch: 1 branch
BranchTrueFalseTotal
if (i == n) { 20 43 63
805 20 eo_install_list(aTHX_ pkg, callpkg, stash, items, n);
806 20 LEAVE;
807 20 return;
808 }
809 }
810 }
811  
812 6399 eo_vivify(aTHX_ pkg, STR_WITH_LEN("EXPORT"), SVt_PVAV);
813 6399 ▶ if (n)
Branch: 1 branch
BranchTrueFalseTotal
if (n) 6386 13 6399
814 6386 eo_vivify(aTHX_ pkg, STR_WITH_LEN("EXPORT_OK"), SVt_PVAV);
815 6399 exp = eo_pkg_av(aTHX_ pkg, STR_WITH_LEN("EXPORT"));
816  
817 6399 ▶ if (n == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (n == 0) { 13 6386 6399
818 13 names = eo_av_copy(aTHX_ exp);
819 13 ▶ if (!via_import || eo_would_be_heavy(aTHX_ pkg, names, FALSE, NULL, verbose))
Branch: 2 branches
BranchTrueFalseTotal
if (!via_import || eo_would_be_heavy(aTHX_ pkg, names, FALSE, NULL, verbose)) 12 1 13
if (!via_import || eo_would_be_heavy(aTHX_ pkg, names, FALSE, NULL, verbose)) 4 8 12
820 5 eo_vivify(aTHX_ pkg, STR_WITH_LEN("EXPORT_FAIL"), SVt_PVAV);
821 }
822 else {
823 6386 AV *ok = eo_pkg_av(aTHX_ pkg, STR_WITH_LEN("EXPORT_OK"));
824 bool current;
825 6386 HV *set = eo_cache_get(aTHX_ pkg, exp, ok, &current);
826 6386 SV *errors = NULL;
827 6386 I32 oops = 0;
828 SSize_t i, top;
829 I32 i32;
830  
831 6386 names = (AV *)sv_2mortal((SV *)newAV());
832 25030 ▶ for (i32 = 0; i32 < n; i32++)
Branch: 1 branch
BranchTrueFalseTotal
for (i32 = 0; i32 < n; i32++) 18644 6386 25030
833 18644 av_push(names, newSVsv(items[i32]));
834  
835 6386 ▶ if (!via_import || eo_would_be_heavy(aTHX_ pkg, names, TRUE, set, verbose))
Branch: 2 branches
BranchTrueFalseTotal
if (!via_import || eo_would_be_heavy(aTHX_ pkg, names, TRUE, set, verbose)) 6378 8 6386
if (!via_import || eo_would_be_heavy(aTHX_ pkg, names, TRUE, set, verbose)) 6359 19 6378
836 6367 eo_vivify(aTHX_ pkg, STR_WITH_LEN("EXPORT_FAIL"), SVt_PVAV);
837  
838 6386 ▶ if (eo_has_specs(aTHX_ names)) {
Branch: 1 branch
BranchTrueFalseTotal
if (eo_has_specs(aTHX_ names)) { 5221 1165 6386
839 5221 eo_vivify(aTHX_ pkg, STR_WITH_LEN("EXPORT_TAGS"), SVt_PVHV);
840 5221 names = eo_walk_specs(aTHX_ pkg, names, exp, ok, verbose, &oops);
841 }
842  
843 6383 top = av_len(names);
844 27889 ▶ for (i = 0; i <= top; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i <= top; i++) { 21619 6270 27889
845 21619 SV *sym = *av_fetch(names, i, 0);
846 STRLEN len;
847 21619 const char *s = SvPV_const(sym, len);
848  
849 21619 ▶ if (hv_exists_ent(set, sym, 0))
Branch: 1 branch
BranchTrueFalseTotal
if (hv_exists_ent(set, sym, 0)) 17467 4152 21619
850 19441 continue;
851  
852 4152 ▶ if (len && isDIGIT(*s)) {
Branch: 2 branches
BranchTrueFalseTotal
if (len && isDIGIT(*s)) { 3102 1050 4152
if (len && isDIGIT(*s)) { 1092 2010 3102
853 1092 eo_call_version(aTHX_ pkg, sym);
854 1089 ▶ if (top == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (top == 0) { 76 1013 1089
855 76 names = eo_av_copy(aTHX_ exp);
856 110 break;
857 }
858 1013 ▶ if (top == 1 && !SvTRUE(*av_fetch(names, 1, 0))) {
Branch: 2 branches
BranchTrueFalseTotal
if (top == 1 && !SvTRUE(*av_fetch(names, 1, 0))) { 237 776 1013
if (top == 1 && !SvTRUE(*av_fetch(names, 1, 0))) { 34 203 237
859 34 names = (AV *)sv_2mortal((SV *)newAV());
860 34 break;
861 }
862 979 continue;
863 }
864  
865 3060 ▶ if (len && *s == '&') {
Branch: 2 branches
BranchTrueFalseTotal
if (len && *s == '&') { 2010 1050 3060
if (len && *s == '&') { 995 1015 2010
866 995 sv_chop(sym, s + 1);
867 995 ▶ if (hv_exists_ent(set, sym, 0))
Branch: 1 branch
BranchTrueFalseTotal
if (hv_exists_ent(set, sym, 0)) 993 2 995
868 993 continue;
869 }
870  
871 2067 ▶ if (!current) {
Branch: 1 branch
BranchTrueFalseTotal
if (!current) { 1893 174 2067
872 1893 set = eo_cache_build(aTHX_ pkg, exp, ok);
873 1893 current = TRUE;
874 1893 ▶ if (hv_exists_ent(set, sym, 0))
Branch: 1 branch
BranchTrueFalseTotal
if (hv_exists_ent(set, sym, 0)) 2 1891 1893
875 2 continue;
876 }
877  
878 2065 ▶ if (!errors)
Branch: 1 branch
BranchTrueFalseTotal
if (!errors) 1891 174 2065
879 1891 errors = sv_2mortal(newSVpvs(""));
880 2065 sv_catpvf(errors, "\"%" SVf "\" is not exported by the %" SVf " module\n",
881 SVfARG(sym), SVfARG(pkg));
882 2065 oops++;
883 }
884  
885 6380 ▶ if (oops) {
Branch: 1 branch
BranchTrueFalseTotal
if (oops) { 2657 3723 6380
886 2657 ▶ if (!errors)
Branch: 1 branch
BranchTrueFalseTotal
if (!errors) 766 1891 2657
887 766 errors = sv_2mortal(newSVpvs(""));
888 2657 sv_catpvs(errors, "Can't continue after import errors");
889 2657 Perl_croak(aTHX_ "%" SVf, SVfARG(errors));
890 }
891 }
892  
893 3736 eo_check_fail(aTHX_ pkg, names, verbose);
894  
895 3067 ▶ if (verbose) {
Branch: 1 branch
BranchTrueFalseTotal
if (verbose) { 4 3063 3067
896 4 AV *sorted = eo_av_copy(aTHX_ names);
897 4 ▶ if (av_len(sorted) > 0)
Branch: 1 branch
BranchTrueFalseTotal
if (av_len(sorted) > 0) 2 2 4
898 2 sortsv(AvARRAY(sorted), av_len(sorted) + 1, Perl_sv_cmp);
899 4 Perl_warn(aTHX_ "Importing into %" SVf " from %" SVf ": %" SVf,
900 4 SVfARG(callpkg), SVfARG(pkg), SVfARG(eo_join(aTHX_ sorted, ", ")));
901 }
902  
903 3067 eo_install(aTHX_ pkg, callpkg, names);
904 3067 LEAVE;
905 }
906  
907 static void
908 48 eo_setup(pTHX_ SV **items, I32 n)
909 {
910 dMY_CXT;
911 48 bool want_import = TRUE;
912 48 SV *errors = NULL;
913 I32 i;
914  
915 58 ▶ for (i = 0; i < n; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < n; i++) { 10 48 58
916 STRLEN len;
917 10 const char *s = SvPV_const(items[i], len);
918 10 ▶ if (len == 6 && memEQ(s, "import", 6))
Branch: 2 branches
BranchTrueFalseTotal
if (len == 6 && memEQ(s, "import", 6)) 7 3 10
if (len == 6 && memEQ(s, "import", 6)) 3 4 7
919 9 continue;
920 7 ▶ if (len == 9 && memEQ(s, "-noimport", 9)) {
Branch: 2 branches
BranchTrueFalseTotal
if (len == 9 && memEQ(s, "-noimport", 9)) { 2 5 7
if (len == 9 && memEQ(s, "-noimport", 9)) { 2 0 2
921 2 want_import = FALSE;
922 2 continue;
923 }
924 5 ▶ if (len == 6 && memEQ(s, "strict", 6)) {
Branch: 2 branches
BranchTrueFalseTotal
if (len == 6 && memEQ(s, "strict", 6)) { 4 1 5
if (len == 6 && memEQ(s, "strict", 6)) { 4 0 4
925 SV **v;
926 4 PL_hints |= HINT_LOCALIZE_HH;
927 4 ▶ v = hv_stores(GvHVn(PL_hintgv), EO_STRICT_KEY, newSViv(1));
Branch: 1 branch
BranchTrueFalseTotal
v = hv_stores(GvHVn(PL_hintgv), EO_STRICT_KEY, newSViv(1)); 4 0 4
928 4 ▶ if (v)
Branch: 1 branch
BranchTrueFalseTotal
if (v) 4 0 4
929 4 ▶ SvSETMAGIC(*v);
Branch: 1 branch
BranchTrueFalseTotal
SvSETMAGIC(*v); 4 0 4
930 4 continue;
931 }
932 1 ▶ if (!errors)
Branch: 1 branch
BranchTrueFalseTotal
if (!errors) 1 0 1
933 1 errors = sv_2mortal(newSVpvs(""));
934 1 sv_catpvf(errors, "\"%" SVf "\" is not exported by the Ex::Op module\n",
935 SVfARG(items[i]));
936 }
937 48 ▶ if (errors) {
Branch: 1 branch
BranchTrueFalseTotal
if (errors) { 1 47 48
938 1 sv_catpvs(errors, "Can't continue after import errors");
939 1 Perl_croak(aTHX_ "%" SVf, SVfARG(errors));
940 }
941  
942 {
943 SV **v;
944 47 PL_hints |= HINT_LOCALIZE_HH;
945 47 ▶ v = hv_stores(GvHVn(PL_hintgv), EO_KW_KEY, newSViv(1));
Branch: 1 branch
BranchTrueFalseTotal
v = hv_stores(GvHVn(PL_hintgv), EO_KW_KEY, newSViv(1)); 47 0 47
946 47 ▶ if (v)
Branch: 1 branch
BranchTrueFalseTotal
if (v) 47 0 47
947 47 ▶ SvSETMAGIC(*v);
Branch: 1 branch
BranchTrueFalseTotal
SvSETMAGIC(*v); 47 0 47
948 }
949  
950 47 ▶ if (want_import) {
Branch: 1 branch
BranchTrueFalseTotal
if (want_import) { 45 2 47
951 45 SV *callpkg = eo_stash_name(aTHX_ CopSTASH(PL_curcop));
952 45 SV *dst = eo_qualify(aTHX_ callpkg, STR_WITH_LEN("import"), FALSE);
953 45 GV *gv = gv_fetchsv(dst, 0, SVt_PVCV);
954 45 ▶ CV *have = (gv && isGV_with_GP(gv)) ? GvCVu(gv) : NULL;
Branch: 5 branches
BranchTrueFalseTotal
CV *have = (gv && isGV_with_GP(gv)) ? GvCVu(gv) : NULL; 5 40 45
CV *have = (gv && isGV_with_GP(gv)) ? GvCVu(gv) : NULL; 5 0 5
CV *have = (gv && isGV_with_GP(gv)) ? GvCVu(gv) : NULL; 0 5 5
CV *have = (gv && isGV_with_GP(gv)) ? GvCVu(gv) : NULL; 0 0 0
CV *have = (gv && isGV_with_GP(gv)) ? GvCVu(gv) : NULL; 5 0 5
955 45 ▶ if (!have || !(CvROOT(have) || CvXSUB(have))) {
Branch: 3 branches
BranchTrueFalseTotal
if (!have || !(CvROOT(have) || CvXSUB(have))) { 3 42 45
if (!have || !(CvROOT(have) || CvXSUB(have))) { 0 3 3
if (!have || !(CvROOT(have) || CvXSUB(have))) { 0 0 0
956 42 gv = gv_fetchsv(dst, GV_ADDMULTI, SVt_PVGV);
957 42 sv_setsv_mg((SV *)gv, sv_2mortal(newRV_inc((SV *)MY_CXT.import_cv)));
958 42 GvIMPORTED_CV_on(gv);
959 }
960 }
961 47 }
962  
963 static void
964 6 eo_push_tags(pTHX_ const char *var, STRLEN varlen, SV **items, I32 n)
965 {
966 6 SV *pkg = eo_stash_name(aTHX_ CopSTASH(PL_curcop));
967 6 HV *tags = eo_pkg_hv(aTHX_ pkg, STR_WITH_LEN("EXPORT_TAGS"));
968 6 ▶ AV *target = GvAVn(gv_fetchsv(eo_qualify(aTHX_ pkg, var, varlen, FALSE), GV_ADDMULTI, SVt_PVAV));
Branch: 1 branch
BranchTrueFalseTotal
AV *target = GvAVn(gv_fetchsv(eo_qualify(aTHX_ pkg, var, varlen, FALSE), GV_ADDMULTI, SVt_PVAV)); 6 0 6
969 6 AV *list = (AV *)sv_2mortal((SV *)newAV());
970 6 AV *nontag = (AV *)sv_2mortal((SV *)newAV());
971 SSize_t i, top;
972 I32 i32;
973  
974 6 ▶ if (n) {
Branch: 1 branch
BranchTrueFalseTotal
if (n) { 4 2 6
975 11 ▶ for (i32 = 0; i32 < n; i32++)
Branch: 1 branch
BranchTrueFalseTotal
for (i32 = 0; i32 < n; i32++) 7 4 11
976 7 av_push(list, newSVsv(items[i32]));
977 }
978 2 ▶ else if (tags) {
Branch: 1 branch
BranchTrueFalseTotal
else if (tags) { 2 0 2
979 HE *he;
980 2 hv_iterinit(tags);
981 7 ▶ while ((he = hv_iternext(tags)))
Branch: 1 branch
BranchTrueFalseTotal
while ((he = hv_iternext(tags))) 5 2 7
982 5 av_push(list, newSVsv(hv_iterkeysv(he)));
983 2 ▶ if (av_len(list) > 0)
Branch: 1 branch
BranchTrueFalseTotal
if (av_len(list) > 0) 2 0 2
984 2 sortsv(AvARRAY(list), av_len(list) + 1, Perl_sv_cmp);
985 }
986  
987 6 top = av_len(list);
988 18 ▶ for (i = 0; i <= top; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i <= top; i++) { 12 6 18
989 12 SV *name = *av_fetch(list, i, 0);
990 12 ▶ HE *he = tags ? hv_fetch_ent(tags, name, 0, 0) : NULL;
Branch: 1 branch
BranchTrueFalseTotal
HE *he = tags ? hv_fetch_ent(tags, name, 0, 0) : NULL; 12 0 12
991 20 ▶ if (he && SvTRUE(HeVAL(he))) {
Branch: 2 branches
BranchTrueFalseTotal
if (he && SvTRUE(HeVAL(he))) { 8 4 12
if (he && SvTRUE(HeVAL(he))) { 8 0 8
992 8 SV *val = HeVAL(he);
993 8 ▶ if (!SvROK(val) || SvTYPE(SvRV(val)) != SVt_PVAV)
Branch: 2 branches
BranchTrueFalseTotal
if (!SvROK(val) || SvTYPE(SvRV(val)) != SVt_PVAV) 8 0 8
if (!SvROK(val) || SvTYPE(SvRV(val)) != SVt_PVAV) 0 8 8
994 0 Perl_croak(aTHX_ "Not an ARRAY reference");
995 8 eo_av_append(aTHX_ target, (AV *)SvRV(val));
996 }
997 else {
998 4 av_push(nontag, newSVsv(name));
999 4 av_push(target, newSVsv(name));
1000 }
1001 }
1002  
1003 6 ▶ if (av_len(nontag) >= 0 && (PL_dowarn & G_WARN_ON))
Branch: 2 branches
BranchTrueFalseTotal
if (av_len(nontag) >= 0 && (PL_dowarn & G_WARN_ON)) 2 4 6
if (av_len(nontag) >= 0 && (PL_dowarn & G_WARN_ON)) 1 1 2
1004 1 Perl_warn(aTHX_ "%" SVf " are not tags of %" SVf,
1005 1 SVfARG(eo_join(aTHX_ nontag, ", ")), SVfARG(pkg));
1006 6 }
1007  
1008 MODULE = Ex::Op PACKAGE = Ex::Op
1009  
1010 PROTOTYPES: DISABLE
1011  
1012 void
1013 import(...)
1014 CODE:
1015 {
1016 SV *pkg;
1017 6458 ▶ if (items < 1)
Branch: 1 branch
BranchTrueFalseTotal
if (items < 1) 0 6458 6458
1018 0 XSRETURN_EMPTY;
1019 6458 pkg = ST(0);
1020 12916 ▶ if (!SvROK(pkg) && strEQ(SvPV_nolen_const(pkg), "Ex::Op")) {
Branch: 2 branches
BranchTrueFalseTotal
if (!SvROK(pkg) && strEQ(SvPV_nolen_const(pkg), "Ex::Op")) { 6458 0 6458
if (!SvROK(pkg) && strEQ(SvPV_nolen_const(pkg), "Ex::Op")) { 48 6410 6458
1021 48 eo_setup(aTHX_ &ST(1), items - 1);
1022 }
1023 else {
1024 dMY_CXT;
1025 6410 ▶ IV level = SvIV(GvSVn(MY_CXT.level_gv));
Branch: 1 branch
BranchTrueFalseTotal
IV level = SvIV(GvSVn(MY_CXT.level_gv)); 6410 0 6410
1026 6410 const COP *at = eo_caller_cop(aTHX_ level);
1027 6410 ▶ SV *callpkg = eo_stash_name(aTHX_ at ? CopSTASH(at) : NULL);
Branch: 1 branch
BranchTrueFalseTotal
SV *callpkg = eo_stash_name(aTHX_ at ? CopSTASH(at) : NULL); 6410 0 6410
1028 6410 eo_export(aTHX_ sv_mortalcopy(pkg), callpkg, &ST(1), items - 1, at, TRUE);
1029 }
1030 3126 XSRETURN_EMPTY;
1031 }
1032  
1033 void
1034 unimport(...)
1035 CODE:
1036 {
1037 4 ▶ if (items < 1 || SvROK(ST(0)) || !strEQ(SvPV_nolen_const(ST(0)), "Ex::Op"))
Branch: 3 branches
BranchTrueFalseTotal
if (items < 1 || SvROK(ST(0)) || !strEQ(SvPV_nolen_const(ST(0)), "Ex::Op")) 2 0 2
if (items < 1 || SvROK(ST(0)) || !strEQ(SvPV_nolen_const(ST(0)), "Ex::Op")) 2 0 2
if (items < 1 || SvROK(ST(0)) || !strEQ(SvPV_nolen_const(ST(0)), "Ex::Op")) 1 1 2
1038 1 XSRETURN_EMPTY;
1039 1 PL_hints |= HINT_LOCALIZE_HH;
1040 1 ▶ (void)hv_deletes(GvHVn(PL_hintgv), EO_KW_KEY, G_DISCARD);
Branch: 1 branch
BranchTrueFalseTotal
(void)hv_deletes(GvHVn(PL_hintgv), EO_KW_KEY, G_DISCARD); 1 0 1
1041 1 ▶ (void)hv_deletes(GvHVn(PL_hintgv), EO_STRICT_KEY, G_DISCARD);
Branch: 1 branch
BranchTrueFalseTotal
(void)hv_deletes(GvHVn(PL_hintgv), EO_STRICT_KEY, G_DISCARD); 1 0 1
1042 1 XSRETURN_EMPTY;
1043 }
1044  
1045 void
1046 export(pkg, callpkg, ...)
1047 SV *pkg
1048 SV *callpkg
1049 CODE:
1050 {
1051 4 eo_export(aTHX_ sv_mortalcopy(pkg), sv_mortalcopy(callpkg), &ST(2), items - 2, PL_curcop, FALSE);
1052 4 XSRETURN_EMPTY;
1053 }
1054  
1055 void
1056 export_to_level(pkg, level, ...)
1057 SV *pkg
1058 IV level
1059 CODE:
1060 {
1061 dMY_CXT;
1062 6 const COP *at = eo_caller_cop(aTHX_ level);
1063 6 ▶ SV *callpkg = eo_stash_name(aTHX_ at ? CopSTASH(at) : NULL);
Branch: 1 branch
BranchTrueFalseTotal
SV *callpkg = eo_stash_name(aTHX_ at ? CopSTASH(at) : NULL); 6 0 6
1064 6 ▶ I32 skip = items > 2 ? 3 : 2;
Branch: 1 branch
BranchTrueFalseTotal
I32 skip = items > 2 ? 3 : 2; 6 0 6
1065 6 HV *stash = gv_stashsv(pkg, 0);
1066 6 ▶ GV *meth = stash ? gv_fetchmethod_autoload(stash, "export", FALSE) : NULL;
Branch: 1 branch
BranchTrueFalseTotal
GV *meth = stash ? gv_fetchmethod_autoload(stash, "export", FALSE) : NULL; 6 0 6
1067 6 ▶ CV *ecv = (meth && isGV_with_GP(meth)) ? GvCV(meth) : NULL;
Branch: 4 branches
BranchTrueFalseTotal
CV *ecv = (meth && isGV_with_GP(meth)) ? GvCV(meth) : NULL; 2 4 6
CV *ecv = (meth && isGV_with_GP(meth)) ? GvCV(meth) : NULL; 2 0 2
CV *ecv = (meth && isGV_with_GP(meth)) ? GvCV(meth) : NULL; 0 2 2
CV *ecv = (meth && isGV_with_GP(meth)) ? GvCV(meth) : NULL; 0 0 0
1068  
1069 7 ▶ if (ecv && ecv != MY_CXT.export_cv) {
Branch: 2 branches
BranchTrueFalseTotal
if (ecv && ecv != MY_CXT.export_cv) { 2 4 6
if (ecv && ecv != MY_CXT.export_cv) { 1 1 2
1070 1 AV *args = (AV *)sv_2mortal((SV *)newAV());
1071 SSize_t i, top;
1072 1 av_push(args, newSVsv(pkg));
1073 1 av_push(args, newSVsv(callpkg));
1074 2 ▶ for (i = skip; i < items; i++)
Branch: 1 branch
BranchTrueFalseTotal
for (i = skip; i < items; i++) 1 1 2
1075 1 av_push(args, newSVsv(ST(i)));
1076 1 top = av_len(args);
1077 1 SP = MARK;
1078 1 ▶ PUSHMARK(SP);
Branch: 1 branch
BranchTrueFalseTotal
PUSHMARK(SP); 0 1 1
1079 1 ▶ EXTEND(SP, top + 1);
Branch: 2 branches
BranchTrueFalseTotal
EXTEND(SP, top + 1); 1 0 1
EXTEND(SP, top + 1); 0 1 1
1080 4 ▶ for (i = 0; i <= top; i++)
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i <= top; i++) 3 1 4
1081 3 PUSHs(*av_fetch(args, i, 0));
1082 1 PUTBACK;
1083 1 call_sv((SV *)ecv, G_VOID | G_DISCARD);
1084 }
1085 else {
1086 5 eo_export(aTHX_ sv_mortalcopy(pkg), callpkg, &ST(skip), items - skip, at, FALSE);
1087 }
1088 5 XSRETURN_EMPTY;
1089 }
1090  
1091 void
1092 export_fail(self, ...)
1093 SV *self
1094 PPCODE:
1095 {
1096 I32 i;
1097 PERL_UNUSED_VAR(self);
1098 3 ▶ for (i = 1; i < items; i++)
Branch: 1 branch
BranchTrueFalseTotal
for (i = 1; i < items; i++) 2 1 3
1099 2 ST(i - 1) = ST(i);
1100 1 XSRETURN(items - 1);
1101 }
1102  
1103 void
1104 export_tags(...)
1105 CODE:
1106 {
1107 3 eo_push_tags(aTHX_ STR_WITH_LEN("EXPORT"), &ST(0), items);
1108 3 XSRETURN_EMPTY;
1109 }
1110  
1111 void
1112 export_ok_tags(...)
1113 CODE:
1114 {
1115 3 eo_push_tags(aTHX_ STR_WITH_LEN("EXPORT_OK"), &ST(0), items);
1116 3 XSRETURN_EMPTY;
1117 }
1118  
1119 SV *
1120 require_version(self, wanted)
1121 SV *self
1122 SV *wanted
1123 CODE:
1124 {
1125 1 ▶ SV *pkg = SvROK(self) && SvOBJECT(SvRV(self))
Branch: 1 branch
BranchTrueFalseTotal
SV *pkg = SvROK(self) && SvOBJECT(SvRV(self)) 1 0 1
1126 1 ▶ ? newSVpv(HvNAME_get(SvSTASH(SvRV(self))), 0)
Branch: 6 branches
BranchTrueFalseTotal
? newSVpv(HvNAME_get(SvSTASH(SvRV(self))), 0) 1 0 1
? newSVpv(HvNAME_get(SvSTASH(SvRV(self))), 0) 1 0 1
? newSVpv(HvNAME_get(SvSTASH(SvRV(self))), 0) 0 1 1
? newSVpv(HvNAME_get(SvSTASH(SvRV(self))), 0) 0 0 0
? newSVpv(HvNAME_get(SvSTASH(SvRV(self))), 0) 1 0 1
? newSVpv(HvNAME_get(SvSTASH(SvRV(self))), 0) 0 1 1
1127 8 ▶ : newSVsv(self);
Branch: 1 branch
BranchTrueFalseTotal
: newSVsv(self); 1 7 8
1128 I32 count;
1129 8 sv_2mortal(pkg);
1130 8 ▶ PUSHMARK(SP);
Branch: 1 branch
BranchTrueFalseTotal
PUSHMARK(SP); 0 8 8
1131 8 ▶ XPUSHs(pkg);
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(pkg); 0 8 8
1132 8 ▶ XPUSHs(wanted);
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(wanted); 0 8 8
1133 8 PUTBACK;
1134 8 count = call_method("VERSION", G_SCALAR);
1135 5 SPAGAIN;
1136 5 ▶ RETVAL = count ? newSVsv(POPs) : newSV(0);
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = count ? newSVsv(POPs) : newSV(0); 5 0 5
1137 5 PUTBACK;
1138 }
1139 OUTPUT:
1140 RETVAL
1141  
1142 void
1143 reset_cache(...)
1144 CODE:
1145 {
1146 dMY_CXT;
1147 I32 i;
1148 2 ▶ if (items == 0)
Branch: 1 branch
BranchTrueFalseTotal
if (items == 0) 1 1 2
1149 1 hv_clear(MY_CXT.exports);
1150 3 ▶ for (i = 0; i < items; i++)
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < items; i++) 1 2 3
1151 1 (void)hv_delete_ent(MY_CXT.exports, ST(i), G_DISCARD, 0);
1152 2 XSRETURN_EMPTY;
1153 }
1154  
1155 void
1156 make(name, code)
1157 SV *name
1158 SV *code
1159 PPCODE:
1160 {
1161 2272 CV *cv = eo_code_arg(aTHX_ code, "Ex::Op::make");
1162 STRLEN len;
1163 2271 const char *s = SvPV_const(name, len);
1164 SV *full;
1165 GV *gv;
1166 eo_op_t *e;
1167  
1168 2271 ▶ if (!len)
Branch: 1 branch
BranchTrueFalseTotal
if (!len) 1 2270 2271
1169 1 Perl_croak(aTHX_ "Ex::Op::make needs a name");
1170 2270 ▶ if (instr(s, "::"))
Branch: 1 branch
BranchTrueFalseTotal
if (instr(s, "::")) 2144 126 2270
1171 2144 full = sv_mortalcopy(name);
1172 else
1173 126 full = eo_qualify(aTHX_ eo_stash_name(aTHX_ CopSTASH(PL_curcop)), s, len,
1174 126 SvUTF8(name) ? TRUE : FALSE);
1175  
1176 2270 gv = gv_fetchsv(full, GV_ADDMULTI, SVt_PVCV);
1177 2270 sv_setsv_mg((SV *)gv, code);
1178  
1179 2270 e = eo_register(aTHX_ cv);
1180 2270 ▶ if (!e->accepted && eo_strict_on(aTHX))
Branch: 2 branches
BranchTrueFalseTotal
if (!e->accepted && eo_strict_on(aTHX)) 35 2235 2270
if (!e->accepted && eo_strict_on(aTHX)) 1 34 35
1181 1 Perl_croak(aTHX_ "%" SVf " cannot be an op: %s", SVfARG(full), e->why);
1182  
1183 2269 ▶ ST(0) = e->accepted ? &PL_sv_yes : &PL_sv_no;
Branch: 1 branch
BranchTrueFalseTotal
ST(0) = e->accepted ? &PL_sv_yes : &PL_sv_no; 2235 34 2269
1184 2269 XSRETURN(1);
1185 }
1186  
1187 void
1188 is_op(code)
1189 SV *code
1190 PPCODE:
1191 {
1192 57 CV *cv = eo_code_arg(aTHX_ code, "Ex::Op::is_op");
1193 56 ▶ ST(0) = eo_op_live(aTHX_ cv) ? &PL_sv_yes : &PL_sv_no;
Branch: 1 branch
BranchTrueFalseTotal
ST(0) = eo_op_live(aTHX_ cv) ? &PL_sv_yes : &PL_sv_no; 29 27 56
1194 56 XSRETURN(1);
1195 }
1196  
1197 void
1198 why_not(code)
1199 SV *code
1200 PPCODE:
1201 {
1202 49 CV *cv = eo_code_arg(aTHX_ code, "Ex::Op::why_not");
1203 49 eo_op_t *e = eo_op_find(aTHX_ cv);
1204 49 ▶ if (eo_op_live(aTHX_ cv))
Branch: 1 branch
BranchTrueFalseTotal
if (eo_op_live(aTHX_ cv)) 14 35 49
1205 14 ST(0) = &PL_sv_undef;
1206 35 ▶ else if (!e)
Branch: 1 branch
BranchTrueFalseTotal
else if (!e) 2 33 35
1207 2 ST(0) = sv_2mortal(newSVpvs("it was never made an op"));
1208 33 ▶ else if (e->why)
Branch: 1 branch
BranchTrueFalseTotal
else if (e->why) 32 1 33
1209 32 ST(0) = sv_2mortal(newSVpv(e->why, 0));
1210 else
1211 1 ST(0) = sv_2mortal(newSVpvs("it has been redefined or undefined since it was made an op"));
1212 49 XSRETURN(1);
1213 }
1214  
1215 #ifdef EO_TEST_HOOKS
1216  
1217 void
1218 _test_add_checker()
1219 CODE:
1220 eo_wrap_check(OP_ENTERSUB, eo_test_ck, &eo_test_next_ck);
1221  
1222 IV
1223 _test_checker_seen()
1224 CODE:
1225 RETVAL = eo_test_seen;
1226 OUTPUT:
1227 RETVAL
1228  
1229 IV
1230 _test_check_wrap()
1231 CODE:
1232 RETVAL = EO_CHECK_WRAP;
1233 OUTPUT:
1234 RETVAL
1235  
1236 #endif
1237  
1238 void
1239 CLONE(...)
1240 CODE:
1241 {
1242 MY_CXT_CLONE;
1243 0 eo_cxt_init(aTHX_ &MY_CXT);
1244 PERL_UNUSED_VAR(items);
1245 }
1246  
1247 BOOT:
1248 {
1249 MY_CXT_INIT;
1250 39 eo_cxt_init(aTHX_ &MY_CXT);
1251 39 eo_boot_ops(aTHX);
1252 39 eo_boot_keyword(aTHX);
1253 }
« include/ex_op_reg.h ↑ Summary include/ex_op_call.h »