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_FETCH(pTHX_ REGEXP * const rx, SV * const key, U32 flags)
332 PERL_UNUSED_ARG(key);
333 PERL_UNUSED_ARG(flags);
339 Plugin_package(pTHX_ REGEXP * const rx)
342 return newSVpvs("re::engine::Plugin");
345 MODULE = re::engine::Plugin PACKAGE = re::engine::Plugin
349 pattern(re::engine::Plugin self, ...)
351 SvREFCNT_inc(self->pattern);
352 RETVAL = self->pattern;
357 str(re::engine::Plugin self, ...)
359 SvREFCNT_inc(self->str);
365 mod(re::engine::Plugin self, ...)
368 if (self->rx->intflags & PMf_FOLD) {
369 XPUSHs(sv_2mortal(newSVpvs("i")));
374 if (self->rx->intflags & PMf_MULTILINE) {
375 XPUSHs(sv_2mortal(newSVpvs("m")));
380 if (self->rx->intflags & PMf_SINGLELINE) {
381 XPUSHs(sv_2mortal(newSVpvs("s")));
386 if (self->rx->intflags & PMf_EXTENDED) {
387 XPUSHs(sv_2mortal(newSVpvs("x")));
392 if (self->rx->intflags & RXf_PMf_KEEPCOPY) {
393 XPUSHs(sv_2mortal(newSVpvs("p")));
398 stash(re::engine::Plugin self, ...)
403 self->stash = sv_mortalcopy(ST(1));
404 SvREFCNT_inc(self->stash);
406 SvREFCNT_inc(self->stash);
407 RETVAL = self->stash;
412 minlen(re::engine::Plugin self, ...)
415 self->rx->minlen = (I32)SvIV(ST(1));
418 RETVAL = self->rx->minlen ? newSViv(self->rx->minlen) : &PL_sv_undef;
423 gofs(re::engine::Plugin self, ...)
426 self->rx->gofs = (U32)SvIV(ST(1));
428 RETVAL = self->rx->gofs ? newSVuv(self->rx->gofs) : &PL_sv_undef;
433 nparens(re::engine::Plugin self, ...)
436 self->rx->nparens = (U32)SvIV(ST(1));
438 RETVAL = self->rx->nparens ? newSVuv(self->rx->nparens) : &PL_sv_undef;
443 _num_capture_buff_FETCH(re::engine::Plugin self, ...)
446 self->cb_num_capture_buff_FETCH = ST(1);
447 SvREFCNT_inc(self->cb_num_capture_buff_FETCH);
451 _num_capture_buff_STORE(re::engine::Plugin self, ...)
454 self->cb_num_capture_buff_STORE = ST(1);
455 SvREFCNT_inc(self->cb_num_capture_buff_STORE);
459 _num_capture_buff_LENGTH(re::engine::Plugin self, ...)
462 self->cb_num_capture_buff_LENGTH = ST(1);
463 SvREFCNT_inc(self->cb_num_capture_buff_LENGTH);
469 XPUSHs(sv_2mortal(newSViv(PTR2IV(&engine_plugin))));