const char *p = proto;
const char *const end = proto;
contextclass = 0;
- while (*--p != '[') {}
+ while (*--p != '[')
+ /* \[$] accepts any scalar lvalue */
+ if (*p == '$'
+ && Perl_op_lvalue_flags(aTHX_
+ scalar(o3),
+ OP_READ, /* not entersub */
+ OP_LVALUE_NO_CROAK
+ )) goto wrapref;
bad_type(arg, Perl_form(aTHX_ "one of %.*s",
(int)(end - p), p),
gv_ename(namegv), o3);
o3->op_type == OP_HELEM ||
o3->op_type == OP_AELEM)
goto wrapref;
- if (!contextclass)
+ if (!contextclass) {
+ /* \$ accepts any scalar lvalue */
+ if (Perl_op_lvalue_flags(aTHX_
+ scalar(o3),
+ OP_READ, /* not entersub */
+ OP_LVALUE_NO_CROAK
+ )) goto wrapref;
bad_type(arg, "scalar", gv_ename(namegv), o3);
+ }
break;
case '@':
if (o3->op_type == OP_RV2AV ||
You can now limit the size of an array using C<splice(@a,MAX_LEN)> without
worrying about warnings.
+=head2 The C<\$> prototype accepts any scalar lvalue
+
+The C<\$> and C<\[$]> subroutine prototypes now accept any scalar lvalue
+argument. Previously they only accepted scalars beginning with C<$> and
+hash and array elements. This change makes them consistent with the way
+the built-in C<read> and C<recv> functions (among others) parse their
+arguments. This means that one can override the built-in functions with
+custom subroutines that parse their arguments the same way.
+
=head1 Security
XXX Any security-related notices go here. In particular, any security
# strict
use strict;
-print "1..171\n";
+print "1..174\n";
my $i = 1;
sreftest($helem{$i}, $i++);
sreftest $aelem[0], $i++;
sreftest sub { [0] }->()[0], $i++;
+ sreftest my $a = 'quidgley', $i++;
+ print "not " if eval 'return 1; sreftest(3+4)';
+ print "ok ", $i++, ' - \$ with invalid argument', "\n";
}
# test single term
print "not " unless myref($myvar) =~ /^SCALAR\(/;
print "ok ", $i++, "\n";
+ print "not " unless myref($myvar=7) =~ /^SCALAR\(/;
+ print "ok ", $i++, "\n";
print "not " unless myref(@myarray) =~ /^ARRAY\(/;
print "ok ", $i++, "\n";
print "not " unless myref(%myhash) =~ /^HASH\(/;