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);
129 /* Store the current str for ->str */
131 SvREFCNT_inc(self->str);
137 XPUSHs(rx->pprivate);
141 call_sv(callback, G_SCALAR);
160 Plugin_intuit(pTHX_ REGEXP * const rx, SV *sv, char *strpos,
161 char *strend, U32 flags, re_scream_pos_data *data)
165 PERL_UNUSED_ARG(strpos);
166 PERL_UNUSED_ARG(strend);
167 PERL_UNUSED_ARG(flags);
168 PERL_UNUSED_ARG(data);
173 Plugin_checkstr(pTHX_ REGEXP * const rx)
180 Plugin_free(pTHX_ REGEXP * const rx)
186 GET_SELF_FROM_PPRIVATE(rx->pprivate);
188 callback = self->cb_free;
195 XPUSHs(rx->pprivate);
198 call_sv(callback, G_DISCARD);
209 Plugin_dupe(pTHX_ const REGEXP * rx, CLONE_PARAMS *param)
211 Perl_croak("dupe not supported yet");
217 Plugin_numbered_buff_FETCH(pTHX_ REGEXP * const rx, const I32 paren,
223 GET_SELF_FROM_PPRIVATE(rx->pprivate);
225 callback = self->cb_num_capture_buff_FETCH;
232 XPUSHs(rx->pprivate);
233 XPUSHs(sv_2mortal(newSViv(paren)));
236 items = call_sv(callback, G_SCALAR);
244 sv_setsv(sv, &PL_sv_undef);
251 sv_setsv(sv, &PL_sv_undef);
256 Plugin_numbered_buff_STORE(pTHX_ REGEXP * const rx, const I32 paren,
257 SV const * const value)
262 GET_SELF_FROM_PPRIVATE(rx->pprivate);
264 callback = self->cb_num_capture_buff_STORE;
271 XPUSHs(rx->pprivate);
272 XPUSHs(sv_2mortal(newSViv(paren)));
273 XPUSHs(SvREFCNT_inc(value));
276 call_sv(callback, G_DISCARD);
285 Plugin_numbered_buff_LENGTH(pTHX_ REGEXP * const rx, const SV * const sv,
291 re__engine__Plugin self;
293 SELF_FROM_PPRIVATE(self,rx->pprivate);
295 callback = self->cb_num_capture_buff_LENGTH;
302 XPUSHs(rx->pprivate);
303 XPUSHs(sv_2mortal(newSViv(paren)));
306 call_sv(callback, G_SCALAR);
318 /* TODO: call FETCH and get the length on that value */
325 Plugin_named_buff_FETCH(pTHX_ REGEXP * const rx, SV * const key, U32 flags)
328 PERL_UNUSED_ARG(key);
329 PERL_UNUSED_ARG(flags);
335 Plugin_package(pTHX_ REGEXP * const rx)
338 return newSVpvs("re::engine::Plugin");
341 MODULE = re::engine::Plugin PACKAGE = re::engine::Plugin
345 pattern(re::engine::Plugin self, ...)
347 SvREFCNT_inc(self->pattern);
348 RETVAL = self->pattern;
353 str(re::engine::Plugin self, ...)
355 SvREFCNT_inc(self->str);
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, ...)
399 self->stash = sv_mortalcopy(ST(1));
400 SvREFCNT_inc(self->stash);
402 SvREFCNT_inc(self->stash);
403 RETVAL = self->stash;
408 minlen(re::engine::Plugin self, ...)
411 self->rx->minlen = (I32)SvIV(ST(1));
414 RETVAL = self->rx->minlen ? newSViv(self->rx->minlen) : &PL_sv_undef;
419 gofs(re::engine::Plugin self, ...)
422 self->rx->gofs = (U32)SvIV(ST(1));
424 RETVAL = self->rx->gofs ? newSVuv(self->rx->gofs) : &PL_sv_undef;
429 nparens(re::engine::Plugin self, ...)
432 self->rx->nparens = (U32)SvIV(ST(1));
434 RETVAL = self->rx->nparens ? newSVuv(self->rx->nparens) : &PL_sv_undef;
439 _num_capture_buff_FETCH(re::engine::Plugin self, ...)
442 self->cb_num_capture_buff_FETCH = ST(1);
443 SvREFCNT_inc(self->cb_num_capture_buff_FETCH);
447 _num_capture_buff_STORE(re::engine::Plugin self, ...)
450 self->cb_num_capture_buff_STORE = ST(1);
451 SvREFCNT_inc(self->cb_num_capture_buff_STORE);
455 _num_capture_buff_LENGTH(re::engine::Plugin self, ...)
458 self->cb_num_capture_buff_LENGTH = ST(1);
459 SvREFCNT_inc(self->cb_num_capture_buff_LENGTH);
465 XPUSHs(sv_2mortal(newSViv(PTR2IV(&engine_plugin))));