7 require Config; import Config;
8 keys %Config; # Silence warning
9 if ($Config{extensions} !~ /\bList\/Util\b/) {
10 print "1..0 # Skip: List::Util was not built\n";
18 use Test::More tests => 14;
19 use Scalar::Util qw(openhandle);
21 ok(defined &openhandle, 'defined');
25 is(openhandle($fh), $fh, 'STDERR');
27 is(fileno(openhandle(*STDERR)), fileno(STDERR), 'fileno(STDERR)');
32 is(openhandle(*CLOSED), undef, 'closed');
36 skip "3-arg open only on 5.6 or later", 1 if $]<5.006;
39 skip "could not open $0 for reading: $!", 1 unless $fh;
40 is(openhandle($fh), $fh, "works with indirect filehandles");
44 skip "in-memory files only on 5.8 or later", 1 if $]<5.008;
46 open my $fh, "<", \"in-memory file";
47 skip "could not open in-memory file: $!", 1 unless $fh;
48 is(openhandle($fh), $fh, "works with in-memory files");
51 ok(openhandle(\*DATA), "works for \*DATA");
52 ok(openhandle(*DATA), "works for *DATA");
53 ok(openhandle(*DATA{IO}), "works for *DATA{IO}");
57 my $fh = IO::Handle->new_from_fd(fileno(*STDERR), 'w');
58 skip "new_from_fd(fileno(*STDERR)) failed", 1 unless $fh;
59 ok(openhandle($fh), "works for IO::Handle objects");
61 ok(!openhandle(IO::Handle->new), "unopened IO::Handle");
66 my $fh = IO::File->new;
68 or skip "could not open $0: $!", 1;
69 ok(openhandle($fh), "works for IO::File objects");
71 ok(!openhandle(IO::File->new), "unopened IO::File" );
75 skip( "Tied handles only on 5.8 or later", 1) if $]<5.008;
81 @My::Tie::ISA = qw(Tie::Handle);
82 sub TIEHANDLE { bless {} }
86 ok(openhandle(*H), "tied handles are always ok");