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