summaryrefslogtreecommitdiff
path: root/toke.c
diff options
context:
space:
mode:
authorDavid Golden <dagolden@cpan.org>2010-09-12 20:26:43 -0400
committerDavid Golden <dagolden@cpan.org>2010-10-21 09:23:58 -0400
commitc035a075a240f10383292128a8d3f3746c4ac857 (patch)
treea245d8f117b9636fe740448118a753e5457978c8 /toke.c
parent9061a8f72941979d02cbccb5cb18a2034813b6a7 (diff)
downloadperl-c035a075a240f10383292128a8d3f3746c4ac857.tar.gz
Add single-term prototype
The C<+> prototype is a special alternative to C<$> that will act like C<\[@%]> when given a literal array or hash variable, but will otherwise force scalar context on the argument. This is useful for functions which should accept either a literal array or an array reference as the argument: sub smartpush (+@) { my $aref = shift; die "Not an array or arrayref" unless ref $aref eq 'ARRAY'; push @$aref, @_; } When using the C<+> prototype, your function must check that the argument is of an acceptable type.
Diffstat (limited to 'toke.c')
-rw-r--r--toke.c4
1 files changed, 2 insertions, 2 deletions
diff --git a/toke.c b/toke.c
index ec2ac73c51..731c2b4d35 100644
--- a/toke.c
+++ b/toke.c
@@ -6523,7 +6523,7 @@ Perl_yylex(pTHX)
(
(
*proto == '$' || *proto == '_'
- || *proto == '*'
+ || *proto == '*' || *proto == '+'
)
&& proto[1] == '\0'
)
@@ -7735,7 +7735,7 @@ Perl_yylex(pTHX)
if (warnillegalproto) {
if (must_be_last)
proto_after_greedy_proto = TRUE;
- if (!strchr("$@%*;[]&\\_", *p)) {
+ if (!strchr("$@%*;[]&\\_+", *p)) {
bad_proto = TRUE;
}
else {