File Coverage

blib/lib/Data/Printer/Filter/GLOB.pm
Criterion Covered Total %
statement 52 52 100.0
branch 11 14 78.5
condition 3 3 100.0
subroutine 9 9 100.0
pod 0 1 0.0
total 75 79 94.9


line stmt bran cond sub pod time code
1             package Data::Printer::Filter::GLOB;
2 32     32   189 use strict;
  32         58  
  32         801  
3 32     32   137 use warnings;
  32         58  
  32         640  
4 32     32   131 use Data::Printer::Filter;
  32         71  
  32         179  
5 32     32   148 use Data::Printer::Common;
  32         56  
  32         661  
6 32     32   153 use Scalar::Util ();
  32         87  
  32         523  
7 32     32   908 use Fcntl;
  32         94  
  32         10172  
8              
9             filter 'GLOB' => \&parse;
10              
11              
12             sub parse {
13 10     10 0 29 my ($glob, $ddp) = @_;
14              
15 10         45 my $string = $ddp->maybe_colorize("$$glob", 'glob');
16              
17             # unfortunately, some systems (like Win32) do not
18             # implement some of these flags (maybe not even
19             # fcntl() itself, so we must wrap it.
20 10         19 my $extra = '';
21 10         12 my $flags;
22 32     32   216 eval { no warnings qw( unopened closed ); $flags = fcntl($$glob, F_GETFL, 0) };
  32         72  
  32         10037  
  10         15  
  10         87  
23 10 50       34 if ($flags) {
24 10 100       33 $extra .= ($flags & O_WRONLY) ? 'write-only'
    100          
25             : ($flags & O_RDWR) ? 'read/write'
26             : 'read-only'
27             ;
28              
29             # How to avoid croaking when the system
30             # doesn't implement one of those, without skipping
31             # the whole thing? Maybe there's a better way.
32             # Solaris, for example, doesn't have O_ASYNC :(
33 10         17 my %flags = ();
34 10         14 eval { $flags{'append'} = O_APPEND };
  10         20  
35 10         13 eval { $flags{'async'} = O_ASYNC }; # leont says this is the only one I should care for.
  10         17  
36 10         12 eval { $flags{'create'} = O_CREAT };
  10         14  
37 10         13 eval { $flags{'truncate'} = O_TRUNC };
  10         14  
38 10         13 eval { $flags{'nonblocking'} = O_NONBLOCK };
  10         16  
39              
40 10 100       56 if (my @flags = grep { $flags & $flags{$_} } sort keys %flags) {
  50         76  
41 2         7 $extra .= ", flags: @flags";
42             }
43 10         24 $extra .= ', ';
44             }
45 10         19 my @layers = ();
46             # TODO: try PerlIO::Layers::get_layers (leont)
47             my $error = Data::Printer::Common::_tryme(sub {
48 10     10   55 @layers = PerlIO::get_layers $$glob
49 10         52 });
50 10 50       47 $extra .= "layers: @layers" unless $error;
51 10 50       30 $string .= " ($extra)" if $extra;
52              
53 10 100 100     32 if ($ddp->show_tied and my $tie = ref tied *$$glob) {
54 1         3 $string .= " (tied to $tie)"
55             }
56 10         37 return $string;
57             };
58              
59             1;