summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZefram <zefram@fysh.org>2010-10-03 18:04:08 +0100
committerZefram <zefram@fysh.org>2010-10-03 18:04:08 +0100
commite33873a090fb0dcd67df9a41ec9ff90c11749d01 (patch)
treecb1f1dc443f8b49f5b79ca89566142b54321ea93
parentc02ee425ec16ba1c726d4eba2a70720102f63280 (diff)
downloadperl-zefram/fake_first_line.tar.gz
deprecate #! and csh : on fake line 1zefram/fake_first_line
"#line 1" yields a fake line 1, on which switches can be acquired from a #! and a csh-style : will be ignored. Deprecate this interpretation.
-rw-r--r--MANIFEST2
-rw-r--r--parser.h1
-rw-r--r--pod/perldiag.pod20
-rw-r--r--t/lib/warnings/1global17
-rw-r--r--t/run/fake_shebang.aux12
-rw-r--r--t/run/fake_shebang.t15
-rw-r--r--toke.c10
7 files changed, 59 insertions, 18 deletions
diff --git a/MANIFEST b/MANIFEST
index dce1738604..7198827c6a 100644
--- a/MANIFEST
+++ b/MANIFEST
@@ -4750,6 +4750,8 @@ t/re/subst_wamp.t See if substitution works with $& present
t/re/uniprops.t Test unicode \p{} regex constructs
t/run/cloexec.t Test close-on-exec.
t/run/exit.t Test perl's exit status.
+t/run/fake_shebang.aux Data for fake_shebang.t
+t/run/fake_shebang.t Test fake-line-1 deprecation.
t/run/fresh_perl.t Tests that require a fresh perl.
t/run/noswitch.t Test aliasing ARGV for other switch tests
t/run/runenv.t Test if perl honors its environment variables.
diff --git a/parser.h b/parser.h
index 4ef460836c..165a7eff95 100644
--- a/parser.h
+++ b/parser.h
@@ -105,6 +105,7 @@ typedef struct yy_parser {
COP *saved_curcop; /* the previous PL_curcop */
char tokenbuf[256];
+ bool seen_sheline; /* seen #line directive */
} yy_parser;
/* flags for lexer API */
diff --git a/pod/perldiag.pod b/pod/perldiag.pod
index c6806c1c13..77f3dcee44 100644
--- a/pod/perldiag.pod
+++ b/pod/perldiag.pod
@@ -4939,6 +4939,16 @@ you can write it as C<push(@tied_array,())> to avoid this warning.
(F) The "use" keyword is recognized and executed at compile time, and
returns no useful value. See L<perlmod>.
+=item Use of #! on fake line 1 is deprecated
+
+(D deprecated) You have a C<#!> line that is numbered 1 due to a preceding
+"C<#line 1>". This isn't really the first line of the script, where
+such an interpreter-invoking line belongs, and so it doesn't take effect
+to actually tell the kernel which interpreter to use. However, perl
+has historically treated such a line as if it were an effective C<#!>
+line, allowing you to set command-line switches. This interpretation
+is deprecated. Put your C<#!> line on the real first line only.
+
=item Use of assignment to $[ is deprecated
(D deprecated) The C<$[> variable (index of the first element in an array)
@@ -4964,6 +4974,16 @@ will simply fail.
Be careful to check that what you pass to chdir() is defined and not
blank, else you might find yourself in your home directory.
+=item Use of csh : on fake line 1 is deprecated
+
+(D deprecated) You have a C<:> line that is numbered 1 due to a preceding
+"C<#line 1>". This isn't really the first line of the script, where
+such an interpreter-invoking line belongs, and so it doesn't take
+effect to actually tell csh which interpreter to use. However, perl has
+historically treated such a line as if it were an effective C<:> line,
+and therefore ignored the colon. This interpretation is deprecated.
+Put your C<:> line on the real first line only.
+
=item Use of /c modifier is meaningless in s///
(W regexp) You used the /c modifier in a substitution. The /c
diff --git a/t/lib/warnings/1global b/t/lib/warnings/1global
index 9de457da0f..20f4ca03d0 100644
--- a/t/lib/warnings/1global
+++ b/t/lib/warnings/1global
@@ -15,13 +15,6 @@ EXPECT
Reversed += operator at - line 3.
Name "main::a" used only once: possible typo at - line 3.
########
-#! perl -w
-# warnable code, warnings enabled via #! line
-$a =+ 3 ;
-EXPECT
-Reversed += operator at - line 3.
-Name "main::a" used only once: possible typo at - line 3.
-########
# warnable code, warnings enabled via compile time $^W
BEGIN { $^W = 1 }
@@ -75,16 +68,6 @@ Use of uninitialized value $b in scalar chop at ./abcd line 1.
my $b ; chop $b ;
1 ;
--FILE--
-#! perl -w
-require "./abcd";
-EXPECT
-Use of uninitialized value $b in scalar chop at ./abcd line 1.
-########
-
---FILE-- abcd
-my $b ; chop $b ;
-1 ;
---FILE--
$^W =1 ;
require "./abcd";
EXPECT
diff --git a/t/run/fake_shebang.aux b/t/run/fake_shebang.aux
new file mode 100644
index 0000000000..edfb4079dc
--- /dev/null
+++ b/t/run/fake_shebang.aux
@@ -0,0 +1,12 @@
+#!./perl -w
+
+BEGIN { print STDERR $^W ? "ok 1" : "not ok 1", "\n"; }
+
+#!./perl -X
+
+BEGIN { print STDERR $^W ? "ok 2" : "not ok 2", "\n"; }
+
+#line 1
+#!./perl -X
+
+BEGIN { print STDERR !$^W ? "ok 3" : "not ok 3", "\n"; }
diff --git a/t/run/fake_shebang.t b/t/run/fake_shebang.t
new file mode 100644
index 0000000000..b37ce5b0ea
--- /dev/null
+++ b/t/run/fake_shebang.t
@@ -0,0 +1,15 @@
+#!./perl
+
+BEGIN {
+ chdir 't' if -d 't';
+ @INC = '../lib';
+}
+
+BEGIN { require './test.pl'; }
+use File::Spec::Functions;
+
+plan(tests => 1);
+
+like runperl(stderr => 1,
+ progfile => catfile(curdir(), 'run', 'fake_shebang.aux')),
+ qr/\Aok 1\nok 2\nUse of #! on fake line 1 is deprecated [^\n]+\nok 3\n\z/;
diff --git a/toke.c b/toke.c
index dd49c3cdba..d6375f2815 100644
--- a/toke.c
+++ b/toke.c
@@ -724,6 +724,8 @@ Perl_lex_start(pTHX_ SV *line, PerlIO *rsfp, bool new_filter)
parser->linestart = SvPVX(parser->linestr);
parser->bufend = parser->bufptr + SvCUR(parser->linestr);
parser->last_lop = parser->last_uni = NULL;
+
+ parser->seen_sheline = 0;
}
@@ -1525,6 +1527,7 @@ S_incline(pTHX_ const char *s)
s += 4;
else
return;
+ PL_parser->seen_sheline = 1;
if (SPACE_OR_TAB(*s))
s++;
else
@@ -4729,8 +4732,11 @@ Perl_yylex(pTHX)
if (CopLINE(PL_curcop) == 1) {
while (s < PL_bufend && isSPACE(*s))
s++;
- if (*s == ':' && s[1] != ':') /* for csh execing sh scripts */
+ if (*s == ':' && s[1] != ':') { /* for csh execing sh scripts */
+ if (PL_parser->seen_sheline)
+ deprecate("csh : on fake line 1");
s++;
+ }
#ifdef PERL_MAD
if (PL_madskills)
PL_thiswhite = newSVpvn(PL_linestart, s - PL_linestart);
@@ -4751,6 +4757,8 @@ Perl_yylex(pTHX)
char *ipath;
char *ipathend;
+ if (PL_parser->seen_sheline)
+ deprecate("#! on fake line 1");
while (isSPACE(*d))
d++;
ipath = d;