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 Plugin_comp(pTHX_ const SV * const pattern, const U32 flags)
46 re__engine__Plugin re;
50 /* exp/xend version of the pattern & length */
52 char* exp = SvPV((SV*)pattern, plen);
53 char* xend = exp + plen;
55 /* The REGEXP structure to return to perl */
58 /* Our blessed object */
61 Newxz(re, 1, struct replug);
62 sv_setref_pv(obj, "re::engine::Plugin", (void*)re);
64 re->rx = rx; /* Make the rx accessible from self->rx */
65 rx->refcnt = 1; /* Refcount so we won' be destroyed */
66 rx->intflags = flags; /* Flags for internal use */
67 rx->extflags = flags; /* Flags for perl to use */
68 rx->engine = RE_ENGINE_PLUGIN; /* Compile to use this engine */
70 /* Precompiled pattern for pp_regcomp to use */
72 rx->precomp = savepvn(exp, rx->prelen);
74 /* Set up qr// stringification to be equivalent to the supplied
75 * pattern, this should be done via overload eventually.
77 rx->wraplen = rx->prelen;
78 Newx(rx->wrapped, rx->wraplen, char);
79 Copy(rx->precomp, rx->wrapped, rx->wraplen, char);
81 /* Store our private object */
84 /* Store the pattern for ->pattern */
85 re->pattern = (SV*)pattern;
86 SvREFCNT_inc(re->pattern);
89 * Call our callback function if one was defined, if not we've
90 * already set up all the stuff we're going to to need for
91 * subsequent exec and other calls
93 SV * callback = get_H_callback("comp");
103 call_sv(callback, G_DISCARD);
109 /* If any of the comp-time accessors were called we'll have to
110 * update the regexp struct with the new info.
113 buffers = rx->nparens;
115 Newxz(rx->offs, buffers, regexp_paren_pair);
121 Plugin_exec(pTHX_ REGEXP * const rx, char *stringarg, char *strend,
122 char *strbeg, I32 minend, SV *sv, void *data, U32 flags)
126 SV * callback = get_H_callback("exec");
127 GET_SELF_FROM_PPRIVATE(rx->pprivate);
130 /* Store the current str for ->str */
132 SvREFCNT_inc(self->str);
138 XPUSHs(rx->pprivate);
142 call_sv(callback, G_SCALAR);
164 Plugin_intuit(pTHX_ REGEXP * const rx, SV *sv, char *strpos,
165 char *strend, U32 flags, re_scream_pos_data *data)
169 PERL_UNUSED_ARG(strpos);
170 PERL_UNUSED_ARG(strend);
171 PERL_UNUSED_ARG(flags);
172 PERL_UNUSED_ARG(data);
177 Plugin_checkstr(pTHX_ REGEXP * const rx)
184 Plugin_free(pTHX_ REGEXP * const rx)
190 GET_SELF_FROM_PPRIVATE(rx->pprivate);
192 callback = self->cb_free;
199 XPUSHs(rx->pprivate);
202 call_sv(callback, G_DISCARD);
213 Plugin_dupe(pTHX_ const REGEXP * rx, CLONE_PARAMS *param)
215 Perl_croak("dupe not supported yet");
221 Plugin_numbered_buff_FETCH(pTHX_ REGEXP * const rx, const I32 paren,
227 GET_SELF_FROM_PPRIVATE(rx->pprivate);
229 callback = self->cb_num_capture_buff_FETCH;
236 XPUSHs(rx->pprivate);
237 XPUSHs(sv_2mortal(newSViv(paren)));
240 items = call_sv(callback, G_SCALAR);
248 sv_setsv(sv, &PL_sv_undef);
255 sv_setsv(sv, &PL_sv_undef);
260 Plugin_numbered_buff_STORE(pTHX_ REGEXP * const rx, const I32 paren,
261 SV const * const value)
266 GET_SELF_FROM_PPRIVATE(rx->pprivate);
268 callback = self->cb_num_capture_buff_STORE;
275 XPUSHs(rx->pprivate);
276 XPUSHs(sv_2mortal(newSViv(paren)));
277 XPUSHs(SvREFCNT_inc(value));
280 call_sv(callback, G_DISCARD);
289 Plugin_numbered_buff_LENGTH(pTHX_ REGEXP * const rx, const SV * const sv,
295 GET_SELF_FROM_PPRIVATE(rx->pprivate);
297 callback = self->cb_num_capture_buff_LENGTH;
304 XPUSHs(rx->pprivate);
305 XPUSHs(sv_2mortal(newSViv(paren)));
308 call_sv(callback, G_SCALAR);
320 /* TODO: call FETCH and get the length on that value */
327 Plugin_named_buff (pTHX_ REGEXP * const rx, SV * const key, SV * const value,
334 Plugin_named_buff_iter (pTHX_ REGEXP * const rx, const SV * const lastkey,
341 Plugin_package(pTHX_ REGEXP * const rx)
344 return newSVpvs("re::engine::Plugin");
347 MODULE = re::engine::Plugin PACKAGE = re::engine::Plugin
351 pattern(re::engine::Plugin self, ...)
353 XPUSHs(self->pattern);
356 str(re::engine::Plugin self, ...)
361 mod(re::engine::Plugin self, ...)
364 if (self->rx->intflags & PMf_FOLD) {
365 XPUSHs(sv_2mortal(newSVpvs("i")));
370 if (self->rx->intflags & PMf_MULTILINE) {
371 XPUSHs(sv_2mortal(newSVpvs("m")));
376 if (self->rx->intflags & PMf_SINGLELINE) {
377 XPUSHs(sv_2mortal(newSVpvs("s")));
382 if (self->rx->intflags & PMf_EXTENDED) {
383 XPUSHs(sv_2mortal(newSVpvs("x")));
388 if (self->rx->intflags & RXf_PMf_KEEPCOPY) {
389 XPUSHs(sv_2mortal(newSVpvs("p")));
394 stash(re::engine::Plugin self, ...)
398 SvREFCNT_inc(self->stash);
405 minlen(re::engine::Plugin self, ...)
408 self->rx->minlen = (I32)SvIV(ST(1));
411 if (self->rx->minlen) {
412 XPUSHs(sv_2mortal(newSViv(self->rx->minlen)));
414 XPUSHs(sv_2mortal(&PL_sv_undef));
419 gofs(re::engine::Plugin self, ...)
422 self->rx->gofs = (U32)SvIV(ST(1));
425 if (self->rx->gofs) {
426 XPUSHs(sv_2mortal(newSVuv(self->rx->gofs)));
428 XPUSHs(sv_2mortal(&PL_sv_undef));
433 nparens(re::engine::Plugin self, ...)
436 self->rx->nparens = (U32)SvIV(ST(1));
439 if (self->rx->nparens) {
440 XPUSHs(sv_2mortal(newSVuv(self->rx->nparens)));
442 XPUSHs(sv_2mortal(&PL_sv_undef));
447 _num_capture_buff_FETCH(re::engine::Plugin self, ...)
450 self->cb_num_capture_buff_FETCH = ST(1);
451 SvREFCNT_inc(self->cb_num_capture_buff_FETCH);
455 _num_capture_buff_STORE(re::engine::Plugin self, ...)
458 self->cb_num_capture_buff_STORE = ST(1);
459 SvREFCNT_inc(self->cb_num_capture_buff_STORE);
463 _num_capture_buff_LENGTH(re::engine::Plugin self, ...)
466 self->cb_num_capture_buff_LENGTH = ST(1);
467 SvREFCNT_inc(self->cb_num_capture_buff_LENGTH);
473 XPUSHs(sv_2mortal(newSViv(PTR2IV(&engine_plugin))));