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 34     34   260 use strict;
  34         68  
  34         1006  
3 34     34   167 use warnings;
  34         72  
  34         833  
4 34     34   173 use Data::Printer::Filter;
  34         84  
  34         230  
5 34     34   188 use Data::Printer::Common;
  34         65  
  34         857  
6 34     34   217 use Scalar::Util ();
  34         77  
  34         655  
7 34     34   1059 use Fcntl;
  34         104  
  34         12824  
8              
9             filter 'GLOB' => \&parse;
10              
11              
12             sub parse {
13 10     10 0 19 my ($glob, $ddp) = @_;
14              
15 10         56 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         22 my $extra = '';
21 10         27 my $flags;
22 34     34   271 eval { no warnings qw( unopened closed ); $flags = fcntl($$glob, F_GETFL, 0) };
  34         86  
  34         12105  
  10         17  
  10         89  
23 10 50       38 if ($flags) {
24 10 100       41 $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         23 my %flags = ();
34 10         15 eval { $flags{'append'} = O_APPEND };
  10         23  
35 10         17 eval { $flags{'async'} = O_ASYNC }; # leont says this is the only one I should care for.
  10         17  
36 10         16 eval { $flags{'create'} = O_CREAT };
  10         19  
37 10         15 eval { $flags{'truncate'} = O_TRUNC };
  10         19  
38 10         14 eval { $flags{'nonblocking'} = O_NONBLOCK };
  10         19  
39              
40 10 100       59 if (my @flags = grep { $flags & $flags{$_} } sort keys %flags) {
  50         94  
41 2         7 $extra .= ", flags: @flags";
42             }
43 10         31 $extra .= ', ';
44             }
45 10         17 my @layers = ();
46             # TODO: try PerlIO::Layers::get_layers (leont)
47             my $error = Data::Printer::Common::_tryme(sub {
48 10     10   64 @layers = PerlIO::get_layers $$glob
49 10         66 });
50 10 50       59 $extra .= "layers: @layers" unless $error;
51 10 50       61 $string .= " ($extra)" if $extra;
52              
53 10 100 100     41 if ($ddp->show_tied and my $tie = ref tied *$$glob) {
54 1         4 $string .= " (tied to $tie)"
55             }
56 10         45 return $string;
57             };
58              
59             1;