File Coverage

blib/lib/IO/Interactive/Tiny.pm
Criterion Covered Total %
statement 2 7 28.5
branch 1 8 12.5
condition 0 9 0.0
subroutine 1 1 100.0
pod 1 1 100.0
total 5 26 19.2


line stmt bran cond sub pod time code
1             package IO::Interactive::Tiny;
2              
3             # use strict;
4             # use warnings;
5              
6             $IO::Interactive::Tiny::VERSION = '0.2';
7              
8             sub is_interactive {
9 2     2 1 23 my ($out_handle) = (@_, select); # Default to default output handle
10              
11             # Not interactive if output is not to terminal...
12 2 50       22 return 0 if not -t $out_handle;
13              
14             # If *ARGV is opened, we're interactive if...
15 0 0 0       if ( tied(*ARGV) or defined(fileno(ARGV)) ) { # IO::Interactive::Tiny: this is the only relavent part of Scalar::Util::openhandle() for 'openhandle *ARGV'
16             # ...it's currently opened to the magic '-' file
17 0 0 0       return -t *STDIN if defined $ARGV && $ARGV eq '-';
18              
19             # ...it's at end-of-file and the next file is the magic '-' file
20 0 0 0       return @ARGV>0 && $ARGV[0] eq '-' && -t *STDIN if eof *ARGV;
21              
22             # ...it's directly attached to the terminal
23 0           return -t *ARGV;
24             }
25              
26             # If *ARGV isn't opened, it will be interactive if *STDIN is attached
27             # to a terminal.
28             else {
29 0           return -t *STDIN;
30             }
31             }
32              
33             1;