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;
49 /* exp/xend version of the pattern & length */
51 char* exp = SvPV((SV*)pattern, plen);
53 /* The REGEXP structure to return to perl */
56 /* Our blessed object */
59 Newxz(re, 1, struct replug);
60 sv_setref_pv(obj, "re::engine::Plugin", (void*)re);
62 re->rx = rx; /* Make the rx accessible from self->rx */
63 rx->refcnt = 1; /* Refcount so we won' be destroyed */
64 rx->intflags = flags; /* Flags for internal use */
65 rx->extflags = flags; /* Flags for perl to use */
66 rx->engine = RE_ENGINE_PLUGIN; /* Compile to use this engine */
68 /* Precompiled pattern for pp_regcomp to use */
70 rx->precomp = savepvn(exp, rx->prelen);
72 /* Set up qr// stringification to be equivalent to the supplied
73 * pattern, this should be done via overload eventually.
75 rx->wraplen = rx->prelen;
76 Newx(rx->wrapped, rx->wraplen, char);
77 Copy(rx->precomp, rx->wrapped, rx->wraplen, char);
79 /* Store our private object */
82 /* Store the pattern for ->pattern */
83 re->pattern = (SV*)pattern;
84 SvREFCNT_inc(re->pattern);
87 * Call our callback function if one was defined, if not we've
88 * already set up all the stuff we're going to to need for
89 * subsequent exec and other calls
91 SV * callback = get_H_callback("comp");
101 call_sv(callback, G_DISCARD);
107 /* If any of the comp-time accessors were called we'll have to
108 * update the regexp struct with the new info.
111 buffers = rx->nparens;
113 Newxz(rx->offs, buffers, regexp_paren_pair);
119 Plugin_exec(pTHX_ REGEXP * const rx, char *stringarg, char *strend,
120 char *strbeg, I32 minend, SV *sv, void *data, U32 flags)
124 SV * callback = get_H_callback("exec");
125 GET_SELF_FROM_PPRIVATE(rx->pprivate);
128 /* Store the current str for ->str */
130 SvREFCNT_inc(self->str);
136 XPUSHs(rx->pprivate);
140 call_sv(callback, G_SCALAR);
162 Plugin_intuit(pTHX_ REGEXP * const rx, SV *sv, char *strpos,
163 char *strend, U32 flags, re_scream_pos_data *data)
167 PERL_UNUSED_ARG(strpos);
168 PERL_UNUSED_ARG(strend);
169 PERL_UNUSED_ARG(flags);
170 PERL_UNUSED_ARG(data);
175 Plugin_checkstr(pTHX_ REGEXP * const rx)
182 Plugin_free(pTHX_ REGEXP * const rx)
188 GET_SELF_FROM_PPRIVATE(rx->pprivate);
190 callback = self->cb_free;
197 XPUSHs(rx->pprivate);
200 call_sv(callback, G_DISCARD);
211 Plugin_dupe(pTHX_ REGEXP * const rx, CLONE_PARAMS *param)
213 Perl_croak(aTHX_ "dupe not supported yet");
219 Plugin_numbered_buff_FETCH(pTHX_ REGEXP * const rx, const I32 paren,
225 GET_SELF_FROM_PPRIVATE(rx->pprivate);
227 callback = self->cb_num_capture_buff_FETCH;
234 XPUSHs(rx->pprivate);
235 XPUSHs(sv_2mortal(newSViv(paren)));
238 items = call_sv(callback, G_SCALAR);
246 sv_setsv(sv, &PL_sv_undef);
253 sv_setsv(sv, &PL_sv_undef);
258 Plugin_numbered_buff_STORE(pTHX_ REGEXP * const rx, const I32 paren,
259 SV const * const value)
263 GET_SELF_FROM_PPRIVATE(rx->pprivate);
265 callback = self->cb_num_capture_buff_STORE;
272 XPUSHs(rx->pprivate);
273 XPUSHs(sv_2mortal(newSViv(paren)));
274 XPUSHs(SvREFCNT_inc(value));
277 call_sv(callback, G_DISCARD);
286 Plugin_numbered_buff_LENGTH(pTHX_ REGEXP * const rx, const SV * const sv,
291 GET_SELF_FROM_PPRIVATE(rx->pprivate);
293 callback = self->cb_num_capture_buff_LENGTH;
300 XPUSHs(rx->pprivate);
301 XPUSHs(sv_2mortal(newSViv(paren)));
304 call_sv(callback, G_SCALAR);
316 /* TODO: call FETCH and get the length on that value */
323 Plugin_named_buff (pTHX_ REGEXP * const rx, SV * const key, SV * const value,
330 Plugin_named_buff_iter (pTHX_ REGEXP * const rx, const SV * const lastkey,
337 Plugin_package(pTHX_ REGEXP * const rx)
340 return newSVpvs("re::engine::Plugin");
343 MODULE = re::engine::Plugin PACKAGE = re::engine::Plugin
347 pattern(re::engine::Plugin self, ...)
349 XPUSHs(self->pattern);
352 str(re::engine::Plugin self, ...)
357 mod(re::engine::Plugin self, ...)
360 if (self->rx->intflags & PMf_FOLD) {
361 XPUSHs(sv_2mortal(newSVpvs("i")));
366 if (self->rx->intflags & PMf_MULTILINE) {
367 XPUSHs(sv_2mortal(newSVpvs("m")));
372 if (self->rx->intflags & PMf_SINGLELINE) {
373 XPUSHs(sv_2mortal(newSVpvs("s")));
378 if (self->rx->intflags & PMf_EXTENDED) {
379 XPUSHs(sv_2mortal(newSVpvs("x")));
384 if (self->rx->intflags & RXf_PMf_KEEPCOPY) {
385 XPUSHs(sv_2mortal(newSVpvs("p")));
390 stash(re::engine::Plugin self, ...)
394 SvREFCNT_inc(self->stash);
401 minlen(re::engine::Plugin self, ...)
404 self->rx->minlen = (I32)SvIV(ST(1));
407 if (self->rx->minlen) {
408 XPUSHs(sv_2mortal(newSViv(self->rx->minlen)));
410 XPUSHs(sv_2mortal(&PL_sv_undef));
415 gofs(re::engine::Plugin self, ...)
418 self->rx->gofs = (U32)SvIV(ST(1));
421 if (self->rx->gofs) {
422 XPUSHs(sv_2mortal(newSVuv(self->rx->gofs)));
424 XPUSHs(sv_2mortal(&PL_sv_undef));
429 nparens(re::engine::Plugin self, ...)
432 self->rx->nparens = (U32)SvIV(ST(1));
435 if (self->rx->nparens) {
436 XPUSHs(sv_2mortal(newSVuv(self->rx->nparens)));
438 XPUSHs(sv_2mortal(&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))));