1*b39c5158Smillert#!/usr/bin/perl -w 2*b39c5158Smillert 3*b39c5158Smillertpackage main; 4*b39c5158Smillert 5*b39c5158Smillertuse strict; 6*b39c5158Smillertuse Test::More; 7*b39c5158Smillert 8*b39c5158Smillert# We may see failures with package filehandles if Fatal/autodie 9*b39c5158Smillert# incorrectly pulls out a cached subroutine from a different package. 10*b39c5158Smillert 11*b39c5158Smillert# We're using Fatal because package filehandles are likely to 12*b39c5158Smillert# see more use with Fatal than autodie. 13*b39c5158Smillert 14*b39c5158Smillertuse Fatal qw(open); 15*b39c5158Smillert 16*b39c5158Smillerteval { 17*b39c5158Smillert open(FILE, '<', $0); 18*b39c5158Smillert}; 19*b39c5158Smillert 20*b39c5158Smillert 21*b39c5158Smillertif ($@) { 22*b39c5158Smillert # Holy smokes! We couldn't even open our own file, bail out... 23*b39c5158Smillert 24*b39c5158Smillert plan skip_all => q{Can't open $0 for filehandle tests} 25*b39c5158Smillert} 26*b39c5158Smillert 27*b39c5158Smillertplan tests => 4; 28*b39c5158Smillert 29*b39c5158Smillertmy $line = <FILE>; 30*b39c5158Smillert 31*b39c5158Smillertlike($line, qr{perl}, 'Looks like we opened $0 correctly'); 32*b39c5158Smillert 33*b39c5158Smillertclose(FILE); 34*b39c5158Smillert 35*b39c5158Smillertpackage autodie::test; 36*b39c5158Smillertuse Test::More; 37*b39c5158Smillert 38*b39c5158Smillertuse Fatal qw(open); 39*b39c5158Smillert 40*b39c5158Smillerteval { 41*b39c5158Smillert open(FILE2, '<', $0); 42*b39c5158Smillert}; 43*b39c5158Smillert 44*b39c5158Smillertis($@,"",'Opened $0 in autodie::test'); 45*b39c5158Smillert 46*b39c5158Smillertmy $line2 = <FILE2>; 47*b39c5158Smillert 48*b39c5158Smillertlike($line2, qr{perl}, '...and we can read from $0 fine'); 49*b39c5158Smillert 50*b39c5158Smillertclose(FILE2); 51*b39c5158Smillert 52*b39c5158Smillertpackage main; 53*b39c5158Smillert 54*b39c5158Smillert# This shouldn't read anything, because FILE2 should be inside 55*b39c5158Smillert# autodie::test 56*b39c5158Smillert 57*b39c5158Smillertno warnings; # Otherwise we see problems with FILE2 58*b39c5158Smillertmy $wrong_line = <FILE2>; 59*b39c5158Smillert 60*b39c5158Smillertok(! defined($wrong_line),q{Filehandles shouldn't leak between packages}); 61