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 35     35   254 use strict;
  35         70  
  35         1403  
3 35     35   190 use warnings;
  35         75  
  35         1803  
4 35     35   2339 use Data::Printer::Filter;
  35         58  
  35         1406  
5 35     35   188 use Data::Printer::Common;
  35         69  
  35         1009  
6 35     35   199 use Scalar::Util ();
  35         82  
  35         803  
7 35     35   193 use Fcntl;
  35         78  
  35         14560  
8              
9             filter 'GLOB' => \&parse;
10              
11              
12             sub parse {
13 10     10 0 21 my ($glob, $ddp) = @_;
14              
15 10         60 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         25 my $extra = '';
21 10         15 my $flags;
22 35     35   266 eval { no warnings qw( unopened closed ); $flags = fcntl($$glob, F_GETFL, 0) };
  35         81  
  35         14829  
  10         18  
  10         91  
23 10 50       32 if ($flags) {
24 10 100       37 $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         19 my %flags = ();
34 10         14 eval { $flags{'append'} = O_APPEND };
  10         47  
35 10         16 eval { $flags{'async'} = O_ASYNC }; # leont says this is the only one I should care for.
  10         18  
36 10         16 eval { $flags{'create'} = O_CREAT };
  10         18  
37 10         12 eval { $flags{'truncate'} = O_TRUNC };
  10         24  
38 10         15 eval { $flags{'nonblocking'} = O_NONBLOCK };
  10         19  
39              
40 10 100       56 if (my @flags = grep { $flags & $flags{$_} } sort keys %flags) {
  50         101  
41 2         6 $extra .= ", flags: @flags";
42             }
43 10         82 $extra .= ', ';
44             }
45 10         20 my @layers = ();
46             # TODO: try PerlIO::Layers::get_layers (leont)
47             my $error = Data::Printer::Common::_tryme(sub {
48 10     10   66 @layers = PerlIO::get_layers $$glob
49 10         72 });
50 10 50       98 $extra .= "layers: @layers" unless $error;
51 10 50       36 $string .= " ($extra)" if $extra;
52              
53 10 100 100     36 if ($ddp->show_tied and my $tie = ref tied *$$glob) {
54 1         5 $string .= " (tied to $tie)"
55             }
56 10         52 return $string;
57             };
58              
59             1;