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 /* Store a precompiled regexp 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 re__engine__Plugin self;
297 SELF_FROM_PPRIVATE(self,rx->pprivate);
299 callback = self->cb_num_capture_buff_LENGTH;
306 XPUSHs(rx->pprivate);
307 XPUSHs(sv_2mortal(newSViv(paren)));
310 call_sv(callback, G_SCALAR);
322 /* TODO: call FETCH and get the length on that value */
329 Plugin_named_buff (pTHX_ REGEXP * const rx, SV * const key, SV * const value,
336 Plugin_named_buff_iter (pTHX_ REGEXP * const rx, const SV * const lastkey,
343 Plugin_package(pTHX_ REGEXP * const rx)
346 return newSVpvs("re::engine::Plugin");
349 MODULE = re::engine::Plugin PACKAGE = re::engine::Plugin
353 pattern(re::engine::Plugin self, ...)
355 SvREFCNT_inc(self->pattern);
356 RETVAL = self->pattern;
361 str(re::engine::Plugin self, ...)
363 SvREFCNT_inc(self->str);
369 mod(re::engine::Plugin self, ...)
372 if (self->rx->intflags & PMf_FOLD) {
373 XPUSHs(sv_2mortal(newSVpvs("i")));
378 if (self->rx->intflags & PMf_MULTILINE) {
379 XPUSHs(sv_2mortal(newSVpvs("m")));
384 if (self->rx->intflags & PMf_SINGLELINE) {
385 XPUSHs(sv_2mortal(newSVpvs("s")));
390 if (self->rx->intflags & PMf_EXTENDED) {
391 XPUSHs(sv_2mortal(newSVpvs("x")));
396 if (self->rx->intflags & RXf_PMf_KEEPCOPY) {
397 XPUSHs(sv_2mortal(newSVpvs("p")));
402 stash(re::engine::Plugin self, ...)
407 self->stash = sv_mortalcopy(ST(1));
408 SvREFCNT_inc(self->stash);
410 SvREFCNT_inc(self->stash);
411 RETVAL = self->stash;
416 minlen(re::engine::Plugin self, ...)
419 self->rx->minlen = (I32)SvIV(ST(1));
422 RETVAL = self->rx->minlen ? newSViv(self->rx->minlen) : &PL_sv_undef;
427 gofs(re::engine::Plugin self, ...)
430 self->rx->gofs = (U32)SvIV(ST(1));
432 RETVAL = self->rx->gofs ? newSVuv(self->rx->gofs) : &PL_sv_undef;
437 nparens(re::engine::Plugin self, ...)
440 self->rx->nparens = (U32)SvIV(ST(1));
442 RETVAL = self->rx->nparens ? newSVuv(self->rx->nparens) : &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))));