Add prototypes for __FILE__ &c.
authorFather Chrysostomos <sprout@cpan.org>
Fri, 8 Jul 2011 15:39:58 +0000 (08:39 -0700)
committerFather Chrysostomos <sprout@cpan.org>
Fri, 8 Jul 2011 16:10:46 +0000 (09:10 -0700)
Before this commit, prototype("CORE::__FILE__") would die with ‘Can’t
find an op number...’.

That __FILE__ does not have an op number whereas time() does is an
implementation detail that should not be exposed to the user.

So this commit adds prototypes for __FILE__, __LINE__ and __PACKAGE__.

pod/perldelta.pod
pp.c
t/op/cproto.t

index 6ee5362..4eb3581 100644 (file)
@@ -487,6 +487,13 @@ A minor memory leak, introduced in 5.15.0, has been fixed.  It would occur
 when a hash is freed that has had its current iterator deleted
 [perl #93454].
 
+=item *
+
+The C<prototype> function now returns a prototype (the empty string) for
+the C<__FILE__>, C<__LINE__> and C<__PACKAGE__> directives, instead of
+dying, as they are indistinguishable syntactically from nullary functions
+like C<time>.
+
 =back
 
 =head1 Known Problems
diff --git a/pp.c b/pp.c
index 98d6482..3c46fc3 100644 (file)
--- a/pp.c
+++ b/pp.c
@@ -466,6 +466,11 @@ PP(pp_prototype)
                    ret = newSVpvs_flags("\\[$@%*]$@", SVs_TEMP);
                    goto set;
                }
+               if (code == -KEY___FILE__ || code == -KEY___LINE__
+                || code == -KEY___PACKAGE__) {
+                   ret = newSVpvs_flags("", SVs_TEMP);
+                   goto set;
+               }
                if (code == -KEY_readpipe) {
                    s = "CORE::backtick";
                }
index b1a4944..9338dda 100644 (file)
@@ -7,7 +7,7 @@ BEGIN {
 }
 
 BEGIN { require './test.pl'; }
-plan tests => 237;
+plan tests => 240;
 
 while (<DATA>) {
     chomp;
@@ -27,6 +27,9 @@ while (<DATA>) {
 # the keyword list :
 
 __DATA__
+__FILE__ ()
+__LINE__ ()
+__PACKAGE__ ()
 abs (_)
 accept (**)
 alarm (_)