7 get_H_callback(const char* key)
18 XPUSHs(sv_2mortal(newSVpv(key, 0)));
21 call_pv("re::engine::Plugin::_get_callback", G_SCALAR);
26 SvREFCNT_inc(callback); /* refcount++ or FREETMPS below will collect us */
28 /* If we don't get a valid CODE value return a NULL callback, in
29 * that case the hooks won't call back into Perl space */
30 if (!SvROK(callback) || SvTYPE(SvRV(callback)) != SVt_PVCV) {
42 #if PERL_VERSION <= 10
43 Plugin_comp(pTHX_ const SV * const pattern, const U32 flags)
45 Plugin_comp(pTHX_ SV * const pattern, U32 flags)
51 re__engine__Plugin re;
54 /* exp/xend version of the pattern & length */
56 char* exp = SvPV((SV*)pattern, plen);
58 /* Our blessed object */
61 Newxz(re, 1, struct replug);
62 sv_setref_pv(obj, "re::engine::Plugin", (void*)re);
67 re->rx = rx; /* Make the rx accessible from self->rx */
68 rx->intflags = flags; /* Flags for internal use */
69 rx->extflags = flags; /* Flags for perl to use */
70 rx->engine = RE_ENGINE_PLUGIN; /* Compile to use this engine */
72 #if PERL_VERSION <= 10
73 rx->refcnt = 1; /* Refcount so we won't be destroyed */
75 /* Precompiled pattern for pp_regcomp to use */
77 rx->precomp = savepvn(exp, rx->prelen);
79 /* Set up qr// stringification to be equivalent to the supplied
80 * pattern, this should be done via overload eventually.
82 rx->wraplen = rx->prelen;
83 Newx(rx->wrapped, rx->wraplen, char);
84 Copy(rx->precomp, rx->wrapped, rx->wraplen, char);
87 /* Store our private object */
90 /* Store the pattern for ->pattern */
91 re->pattern = (SV*)pattern;
92 SvREFCNT_inc(re->pattern);
95 * Call our callback function if one was defined, if not we've
96 * already set up all the stuff we're going to to need for
97 * subsequent exec and other calls
99 SV * callback = get_H_callback("comp");
109 call_sv(callback, G_DISCARD);
115 /* If any of the comp-time accessors were called we'll have to
116 * update the regexp struct with the new info.
119 buffers = rx->nparens;
121 Newxz(rx->offs, buffers + 1, regexp_paren_pair);
127 Plugin_exec(pTHX_ REGEXP * const RX, char *stringarg, char *strend,
128 char *strbeg, I32 minend, SV *sv, void *data, U32 flags)
132 SV * callback = get_H_callback("exec");
133 struct regexp *rx = rxREGEXP(RX);
134 GET_SELF_FROM_PPRIVATE(rx->pprivate);
137 /* Store the current str for ->str */
139 SvREFCNT_inc(self->str);
145 XPUSHs(rx->pprivate);
149 call_sv(callback, G_SCALAR);
171 Plugin_intuit(pTHX_ REGEXP * const RX, SV *sv, char *strpos,
172 char *strend, U32 flags, re_scream_pos_data *data)
176 PERL_UNUSED_ARG(strpos);
177 PERL_UNUSED_ARG(strend);
178 PERL_UNUSED_ARG(flags);
179 PERL_UNUSED_ARG(data);
184 Plugin_checkstr(pTHX_ REGEXP * const RX)
191 Plugin_free(pTHX_ REGEXP * const RX)
197 GET_SELF_FROM_PPRIVATE(rx->pprivate);
199 callback = self->cb_free;
206 XPUSHs(rx->pprivate);
209 call_sv(callback, G_DISCARD);
220 Plugin_dupe(pTHX_ REGEXP * const RX, CLONE_PARAMS *param)
222 struct regexp *rx = rxREGEXP(RX);
223 Perl_croak(aTHX_ "dupe not supported yet");
229 Plugin_numbered_buff_FETCH(pTHX_ REGEXP * const RX, const I32 paren,
235 struct regexp *rx = rxREGEXP(RX);
236 GET_SELF_FROM_PPRIVATE(rx->pprivate);
238 callback = self->cb_num_capture_buff_FETCH;
245 XPUSHs(rx->pprivate);
246 XPUSHs(sv_2mortal(newSViv(paren)));
249 items = call_sv(callback, G_SCALAR);
257 sv_setsv(sv, &PL_sv_undef);
264 sv_setsv(sv, &PL_sv_undef);
269 Plugin_numbered_buff_STORE(pTHX_ REGEXP * const RX, const I32 paren,
270 SV const * const value)
274 struct regexp *rx = rxREGEXP(RX);
275 GET_SELF_FROM_PPRIVATE(rx->pprivate);
277 callback = self->cb_num_capture_buff_STORE;
284 XPUSHs(rx->pprivate);
285 XPUSHs(sv_2mortal(newSViv(paren)));
286 XPUSHs(SvREFCNT_inc(value));
289 call_sv(callback, G_DISCARD);
298 Plugin_numbered_buff_LENGTH(pTHX_ REGEXP * const RX, const SV * const sv,
303 struct regexp *rx = rxREGEXP(RX);
304 GET_SELF_FROM_PPRIVATE(rx->pprivate);
306 callback = self->cb_num_capture_buff_LENGTH;
313 XPUSHs(rx->pprivate);
314 XPUSHs(sv_2mortal(newSViv(paren)));
317 call_sv(callback, G_SCALAR);
329 /* TODO: call FETCH and get the length on that value */
336 Plugin_named_buff (pTHX_ REGEXP * const RX, SV * const key, SV * const value,
343 Plugin_named_buff_iter (pTHX_ REGEXP * const RX, const SV * const lastkey,
350 Plugin_package(pTHX_ REGEXP * const RX)
353 return newSVpvs("re::engine::Plugin");
356 MODULE = re::engine::Plugin PACKAGE = re::engine::Plugin
360 pattern(re::engine::Plugin self, ...)
362 XPUSHs(self->pattern);
365 str(re::engine::Plugin self, ...)
370 mod(re::engine::Plugin self, ...)
373 if (self->rx->intflags & PMf_FOLD) {
374 XPUSHs(sv_2mortal(newSVpvs("i")));
379 if (self->rx->intflags & PMf_MULTILINE) {
380 XPUSHs(sv_2mortal(newSVpvs("m")));
385 if (self->rx->intflags & PMf_SINGLELINE) {
386 XPUSHs(sv_2mortal(newSVpvs("s")));
391 if (self->rx->intflags & PMf_EXTENDED) {
392 XPUSHs(sv_2mortal(newSVpvs("x")));
397 if (self->rx->intflags & RXf_PMf_KEEPCOPY) {
398 XPUSHs(sv_2mortal(newSVpvs("p")));
403 stash(re::engine::Plugin self, ...)
407 SvREFCNT_inc(self->stash);
414 minlen(re::engine::Plugin self, ...)
417 self->rx->minlen = (I32)SvIV(ST(1));
420 if (self->rx->minlen) {
421 XPUSHs(sv_2mortal(newSViv(self->rx->minlen)));
423 XPUSHs(sv_2mortal(&PL_sv_undef));
428 gofs(re::engine::Plugin self, ...)
431 self->rx->gofs = (U32)SvIV(ST(1));
434 if (self->rx->gofs) {
435 XPUSHs(sv_2mortal(newSVuv(self->rx->gofs)));
437 XPUSHs(sv_2mortal(&PL_sv_undef));
442 nparens(re::engine::Plugin self, ...)
445 self->rx->nparens = (U32)SvIV(ST(1));
448 if (self->rx->nparens) {
449 XPUSHs(sv_2mortal(newSVuv(self->rx->nparens)));
451 XPUSHs(sv_2mortal(&PL_sv_undef));
456 _num_capture_buff_FETCH(re::engine::Plugin self, ...)
459 self->cb_num_capture_buff_FETCH = ST(1);
460 SvREFCNT_inc(self->cb_num_capture_buff_FETCH);
464 _num_capture_buff_STORE(re::engine::Plugin self, ...)
467 self->cb_num_capture_buff_STORE = ST(1);
468 SvREFCNT_inc(self->cb_num_capture_buff_STORE);
472 _num_capture_buff_LENGTH(re::engine::Plugin self, ...)
475 self->cb_num_capture_buff_LENGTH = ST(1);
476 SvREFCNT_inc(self->cb_num_capture_buff_LENGTH);
482 XPUSHs(sv_2mortal(newSViv(PTR2IV(&engine_plugin))));