| 1 | package Data::Printer::Filter::GLOB; | ||||||||||||||||||||||||||||
| 2 | 35 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 3 | 35 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 35 | ▶ | use Data::Printer::Filter; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 35 | ▶ | use Data::Printer::Common; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | 35 | ▶ | use Scalar::Util (); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | 35 | ▶ | use Fcntl; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | 35 | filter 'GLOB' => \&parse; | |||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | 10 | ▶ | sub parse { | ||||||||||||||||||||||||||
|
Subroutine
parse: called CC=9 SCAR=22.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 13 | 10 | my ($glob, $ddp) = @_; | |||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | 10 | 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 | my $extra = ''; | |||||||||||||||||||||||||||
| 21 | 10 | my $flags; | |||||||||||||||||||||||||||
| 22 | 35 | ▶ | eval { no warnings qw( unopened closed ); $flags = fcntl($$glob, F_GETFL, 0) }; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 23 | 10 | ▶ | if ($flags) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 24 | 10 | ▶ | $extra .= ($flags & O_WRONLY) ? 'write-only' | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 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 | my %flags = (); | |||||||||||||||||||||||||||
| 34 | 10 | eval { $flags{'append'} = O_APPEND }; | |||||||||||||||||||||||||||
| 35 | 10 | eval { $flags{'async'} = O_ASYNC }; # leont says this is the only one I should care for. | |||||||||||||||||||||||||||
| 36 | 10 | eval { $flags{'create'} = O_CREAT }; | |||||||||||||||||||||||||||
| 37 | 10 | eval { $flags{'truncate'} = O_TRUNC }; | |||||||||||||||||||||||||||
| 38 | 10 | eval { $flags{'nonblocking'} = O_NONBLOCK }; | |||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||
| 40 | 10 | ▶ | if (my @flags = grep { $flags & $flags{$_} } sort keys %flags) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 41 | 2 | $extra .= ", flags: @flags"; | |||||||||||||||||||||||||||
| 42 | } | ||||||||||||||||||||||||||||
| 43 | 10 | $extra .= ', '; | |||||||||||||||||||||||||||
| 44 | } | ||||||||||||||||||||||||||||
| 45 | 10 | my @layers = (); | |||||||||||||||||||||||||||
| 46 | # TODO: try PerlIO::Layers::get_layers (leont) | ||||||||||||||||||||||||||||
| 47 | 10 | ▶ | my $error = Data::Printer::Common::_tryme(sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 48 | 10 | @layers = PerlIO::get_layers $$glob | |||||||||||||||||||||||||||
| 49 | 10 | }); | |||||||||||||||||||||||||||
| 50 | 10 | ▶ | $extra .= "layers: @layers" unless $error; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 51 | 10 | ▶ | $string .= " ($extra)" if $extra; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||
| 53 | 10 | ▶ | if ($ddp->show_tied and my $tie = ref tied *$$glob) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$ddp->show_tied and my $tie = ref tied *$$glob
MC/DC100%2/2
$ddp->show_tied and my $tie = ref tied *$$glob
$ddp->show_tied
my $tie = ref tied *$$glob
Truth table100%3/3
A and B
A= $ddp->show_tiedB= my $tie = ref tied *$$glob
| |||||||||||||||||||||||||||||
| 54 | 1 | $string .= " (tied to $tie)" | |||||||||||||||||||||||||||
| 55 | } | ||||||||||||||||||||||||||||
| 56 | 10 | return $string; | |||||||||||||||||||||||||||
| 57 | }; | ||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||
| 59 | 35 | 1; | |||||||||||||||||||||||||||