I32 flags;
I32 minlen = 0;
U32 rx_flags;
- SV *pat;
+ SV *pat = NULL;
SV *code_blocksv = NULL;
/* these are all flags - maybe they should be turned
/* handle a list of SVs */
SV **svp;
+ OP *o = NULL;
+ int n = 0;
+ bool utf8 = 0;
+ STRLEN orig_patlen = 0;
/* apply magic and RE overloading to each arg */
for (svp = patternp; svp < patternp + pat_count; svp++) {
}
}
- if (pat_count > 1) {
- /* concat multiple args and find any code block indexes */
-
- OP *o = NULL;
- int n = 0;
- bool utf8 = 0;
- STRLEN orig_patlen = 0;
+ /* process args, concat them if there are multiple ones,
+ * and find any code block indexes */
+ if (pat_count > 1) {
if (pRExC_state->num_code_blocks) {
o = cLISTOPx(expr)->op_first;
assert( o->op_type == OP_PUSHMARK
}
if (utf8)
SvUTF8_on(pat);
+ }
for (svp = patternp; svp < patternp + pat_count; svp++) {
SV *sv, *msv = *svp;
- SV *rx;
+ SV *rx = NULL;
bool code = 0;
/* we make the assumption here that each op in the list of
* op_siblings maps to one SV pushed onto the stack,
o = o->op_sibling;;
}
- if ((SvAMAGIC(pat) || SvAMAGIC(msv)) &&
+ /* try concatenation overload ... */
+ if (pat && (SvAMAGIC(pat) || SvAMAGIC(msv)) &&
(sv = amagic_call(pat, msv, concat_amg, AMGf_assign)))
{
sv_setsv(pat, sv);
* code. Pretend we haven't seen it */
pRExC_state->num_code_blocks -= n;
n = 0;
- rx = NULL;
-
}
else {
+ /* ... or failing that, try "" overload */
while (SvAMAGIC(msv)
&& (sv = AMG_CALLunary(msv, string_amg))
&& sv != msv
}
if (SvROK(msv) && SvTYPE(SvRV(msv)) == SVt_REGEXP)
msv = SvRV(msv);
+ if (pat) {
orig_patlen = SvCUR(pat);
sv_catsv_nomg(pat, msv);
rx = msv;
+ }
+ else
+ pat = msv;
if (code)
pRExC_state->code_blocks[n-1].end = SvCUR(pat)-1;
}
}
}
}
- SvSETMAGIC(pat);
- }
- else {
- SV *sv;
- pat = *patternp;
- while (SvAMAGIC(pat)
- && (sv = AMG_CALLunary(pat, string_amg))
- && sv != pat)
- {
- pat = sv;
- SvGETMAGIC(pat);
- }
- }
+ if (pat_count > 1)
+ SvSETMAGIC(pat);
- /* handle bare regex: foo =~ $re */
+ /* handle bare (possibly after overloading) regex: foo =~ $re */
{
SV *re = pat;
if (SvROK(re))
is $1, $TAG, "void context //g against overloaded object";
}
+{
+ # an overloaded stringify returning itself shouldn't loop indefinitely
+
+
+ {
+ package Self;
+ use overload q{""} => sub {
+ return shift;
+ },
+ fallback => 1;
+ }
+
+ my $obj = bless [], 'Self';
+ my $r = qr/$obj/;
+ pass("self object, 1 arg");
+ $r = qr/foo$obj/;
+ pass("self object, 2 args");
+}
+
+
done_testing();