: Used in op.c and toke.c
AMpdR |PADOFFSET|pad_findmy |NN const char* name|STRLEN len|U32 flags
Ap |PADOFFSET|find_rundefsvoffset |
+: Used in pp.c
+Ap |SV* |find_rundefsv |
: Used in perly.y
pR |OP* |oopsAV |NN OP* o
: Used in perly.y
#endif
#define pad_findmy Perl_pad_findmy
#define find_rundefsvoffset Perl_find_rundefsvoffset
+#define find_rundefsv Perl_find_rundefsv
#ifdef PERL_CORE
#define oopsAV Perl_oopsAV
#define oopsHV Perl_oopsHV
#endif
#define pad_findmy(a,b,c) Perl_pad_findmy(aTHX_ a,b,c)
#define find_rundefsvoffset() Perl_find_rundefsvoffset(aTHX)
+#define find_rundefsv() Perl_find_rundefsv(aTHX)
#ifdef PERL_CORE
#define oopsAV(a) Perl_oopsAV(aTHX_ a)
#define oopsHV(a) Perl_oopsHV(aTHX_ a)
Perl_op_free
Perl_pad_findmy
Perl_find_rundefsvoffset
+Perl_find_rundefsv
Perl_pad_sv
Perl_reentrant_size
Perl_reentrant_init
}
/*
+ * Returns a lexical $_, if there is one, at run time ; or the global one
+ * otherwise.
+ */
+
+SV *
+Perl_find_rundefsv(pTHX)
+{
+ SV *namesv;
+ int flags;
+ PADOFFSET po;
+
+ po = pad_findlex("$_", find_runcv(NULL), PL_curcop->cop_seq, 1,
+ NULL, &namesv, &flags);
+
+ if (po == NOT_IN_PAD
+ || (SvFLAGS(namesv) & (SVpad_NAME|SVpad_OUR)) == (SVpad_NAME|SVpad_OUR))
+ return DEFSV;
+
+ return PAD_SVl(po);
+}
+
+/*
=for apidoc pad_findlex
Find a named lexical anywhere in a chain of nested pads. Add fake entries
=item *
The following new functions or macros have been added to the public API:
-C<SvNV_nomg>, C<sv_2nv_flags>.
+C<SvNV_nomg>, C<sv_2nv_flags>, C<find_rundefsv>.
=back
register I32 tmp;
dTARGET;
STRLEN len;
- PADOFFSET padoff_du;
SvUTF8_off(TARG); /* decontaminate */
if (SP - MARK > 1)
do_join(TARG, &PL_sv_no, MARK, SP);
else {
- sv_setsv(TARG, (SP > MARK)
- ? *SP
- : (padoff_du = find_rundefsvoffset(),
- (padoff_du == NOT_IN_PAD
- || PAD_COMPNAME_FLAGS_isOUR(padoff_du))
- ? DEFSV : PAD_SVl(padoff_du)));
-
+ sv_setsv(TARG, SP > MARK ? *SP : find_rundefsv());
if (! SvOK(TARG) && ckWARN(WARN_UNINITIALIZED))
report_uninit(TARG);
}
assert(name)
PERL_CALLCONV PADOFFSET Perl_find_rundefsvoffset(pTHX);
+PERL_CALLCONV SV* Perl_find_rundefsv(pTHX);
PERL_CALLCONV OP* Perl_oopsAV(pTHX_ OP* o)
__attribute__warn_unused_result__
__attribute__nonnull__(pTHX_1);
require './test.pl';
}
-plan tests => 23;
+plan tests => 26;
is(reverse("abc"), "cba");
my $c = scalar reverse($b);
is($a, $c);
}
+
+{
+ # Lexical $_.
+ sub blurp { my $_ = shift; reverse }
+
+ is(blurp("foo"), "oof");
+ is(sub { my $_ = shift; reverse }->("bar"), "rab");
+ {
+ local $_ = "XXX";
+ is(blurp("paz"), "zap");
+ }
+}