Because the filepointer is in sync with the parsing phases of Perl
Not necessarily, no... Let's see
BEGIN {
print "BEGIN\n";
}
UNITCHECK {
print "UNITCHECK\n";
}
CHECK {
print "CHECK\n";
}
INIT {
print "INIT\n";
}
print "MAIN\n";
Let's strace it (Debian Jessie, Perl 5.22)
open("t.pl", O_RDONLY) = 3
...
read(3, "BEGIN {\n print \"BEGIN\\n\";\n}\nU"..., 8192) = 146
write(1, "BEGIN\n", 6) = 6
read(3, "", 8192) = 0
close(3) = 0
write(1, "UNITCHECK\n", 10) = 10
write(1, "CHECK\n", 6) = 6
write(1, "INIT\n", 5) = 5
write(1, "MAIN\n", 5) = 5
Note that the file is closed right after BEGIN (and before UNITCHECK). So no handle to it can exist. But, if we add
__DATA__
whatever
that it changes a bit...
open("t.pl", O_RDONLY) = 3
...
read(3, "BEGIN {\n print \"BEGIN\\n\";\n}\nU"..., 8192) = 165
write(1, "BEGIN\n", 6) = 6
fcntl(3, F_SETFD, FD_CLOEXEC) = 0
write(1, "UNITCHECK\n", 10) = 10
write(1, "CHECK\n", 6) = 6
write(1, "INIT\n", 5) = 5
write(1, "MAIN\n", 5) = 5
...
close(3) = 0
exit_group(0) = ?
Now the file isn't closed until exit. So without __DATA__ there is no handle to the file, and the only handle (that I can find :) is DATA.
Anyway, let us know if you'll find something in perl5db.pl or somewhere else. |