| 1 | package IO::Any; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||
| 3 | 2 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 4 | 2 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 5 | 2 | ▶ | use utf8; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||||||||||
| 7 | 2 | our $VERSION = '0.09'; | |||||||||||||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||||||||||||
| 9 | 2 | ▶ | use Carp 'confess'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 10 | 2 | ▶ | use Scalar::Util 'blessed'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 11 | 2 | ▶ | use IO::String; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 12 | 2 | ▶ | use IO::File; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 13 | 2 | ▶ | use IO::AtomicFile; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 14 | 2 | ▶ | use File::Spec; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 15 | 2 | ▶ | use Fcntl qw(:flock); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 16 | 2 | ▶ | use List::MoreUtils qw(none any); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||||||||||||
| 18 | 23 | ▶ | sub new { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=21 SCAR=32.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 19 | 23 | my $class = shift; | |||||||||||||||||||||||||||||||||||||||||
| 20 | 23 | my $what = shift; | |||||||||||||||||||||||||||||||||||||||||
| 21 | 23 | ▶ | my $how = shift || '<'; | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
shift() || '<'
MC/DC0%0/1
shift() || '<'
shift()
Truth table50%1/2
A
A= shift()
| |||||||||||||||||||||||||||||||||||||||||||
| 22 | 23 | ▶ | my $opt = shift || {}; | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
shift() || {}
MC/DC100%1/1
shift() || {}
shift()
Truth table100%2/2
A
A= shift()
| |||||||||||||||||||||||||||||||||||||||||||
| 23 | 23 | ▶ | confess 'too many arguments' | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 24 | if @_; | ||||||||||||||||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||||||||||||||||
| 26 | 23 | ▶ | confess '$what is missing' | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 27 | if not defined $what; | ||||||||||||||||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||||||||||||||||
| 29 | 21 | ▶ | confess 'expecting hash ref' | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 30 | if ref $opt ne 'HASH'; | ||||||||||||||||||||||||||||||||||||||||||
| 31 | 21 | foreach my $key (keys %$opt) { | |||||||||||||||||||||||||||||||||||||||||
| 32 | confess 'unknown option '.$key | ||||||||||||||||||||||||||||||||||||||||||
| 33 | 17 | ▶ | if (none { $key eq $_ } qw(atomic LOCK_SH LOCK_EX LOCK_NB)); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 34 | } | ||||||||||||||||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||||||||||||||||
| 36 | 19 | my ($type, $proper_what) = $class->_guess_what($what); | |||||||||||||||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||||||||||||||||
| 39 | 19 | ▶ | if ($type eq 'string') { return IO::String->new($proper_what) } | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 40 | 16 | ▶ | if ($type eq 'file') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 41 | 15 | ▶ | my $fh = $opt->{'atomic'} ? IO::AtomicFile->new() : IO::File->new(); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 42 | 15 | ▶ | $fh->open($proper_what, $how) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 43 | or confess 'error opening file "'.$proper_what.'" - '.$!; | ||||||||||||||||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||||||||||||||||
| 45 | # locking if requested | ||||||||||||||||||||||||||||||||||||||||||
| 46 | 15 | ▶ | if ($opt->{'LOCK_SH'} or $opt->{'LOCK_EX'}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$opt->{"LOCK_SH"} or $opt->{"LOCK_EX"}
MC/DC100%2/2
$opt->{"LOCK_SH"} or $opt->{"LOCK_EX"}
$opt->{"LOCK_SH"}
$opt->{"LOCK_EX"}
Truth table100%3/3
A or B
A= $opt->{"LOCK_SH"}B= $opt->{"LOCK_EX"}
| |||||||||||||||||||||||||||||||||||||||||||
| 47 | flock($fh, | ||||||||||||||||||||||||||||||||||||||||||
| 48 | ($opt->{'LOCK_SH'} ? LOCK_SH : 0) | ||||||||||||||||||||||||||||||||||||||||||
| 49 | | ($opt->{'LOCK_EX'} ? LOCK_EX : 0) | ||||||||||||||||||||||||||||||||||||||||||
| 50 | 8 | ▶ | | ($opt->{'LOCK_NB'} ? LOCK_NB : 0) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 4 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 51 | ) or confess 'flock failed - '.$!; | ||||||||||||||||||||||||||||||||||||||||||
| 52 | } | ||||||||||||||||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||||||||||||||||
| 54 | 11 | return $fh; | |||||||||||||||||||||||||||||||||||||||||
| 55 | } | ||||||||||||||||||||||||||||||||||||||||||
| 56 | 1 | ▶ | if ($type eq 'iofile') { return $proper_what } | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 57 | 0 | ▶ | if ($type eq 'iostring') { return $proper_what } | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 58 | 0 | ▶ | if ($type eq 'http') { die 'no http support yet :-|' } | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 59 | } | ||||||||||||||||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||||||||||||||||
| 61 | 31 | ▶ | sub _guess_what { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_guess_what: called CC=18 SCAR=29.5
| |||||||||||||||||||||||||||||||||||||||||||
| 62 | 31 | my $class = shift; | |||||||||||||||||||||||||||||||||||||||||
| 63 | 31 | my $what = shift; | |||||||||||||||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||||||||||||||||
| 65 | 31 | ▶ | if (!blessed($what)) { } # not blessed, do nothing | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 4 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 66 | 0 | elsif ($what->isa('Path::Class::File')) { $what = $what->stringify } | |||||||||||||||||||||||||||||||||||||||||
| 67 | 1 | ▶ | elsif (any { $what->isa($_) } qw(IO::File IO::AtomicFile IO::Uncompress::Bunzip2)) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 68 | 1 | ▶ | confess 'passed unopened IO::File' | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 69 | if not $what->opened; | ||||||||||||||||||||||||||||||||||||||||||
| 70 | 1 | return ('iofile', $what); | |||||||||||||||||||||||||||||||||||||||||
| 71 | } | ||||||||||||||||||||||||||||||||||||||||||
| 72 | 0 | elsif ($what->isa('IO::String')) { return ('iostring', $what) } | |||||||||||||||||||||||||||||||||||||||||
| 73 | 0 | else { confess 'no support for '.blessed($what) }; | |||||||||||||||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||||||||||||||||
| 75 | 30 | my $ref_what = ref($what); | |||||||||||||||||||||||||||||||||||||||||
| 76 | 30 | ▶ | if ($ref_what eq 'ARRAY') { return ('file', File::Spec->catfile(@{$what})) } | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 77 | 1 | elsif ($ref_what eq 'SCALAR') { return ('string', $what) } | |||||||||||||||||||||||||||||||||||||||||
| 78 | elsif ($ref_what eq '') {} # do nothing here if not reference | ||||||||||||||||||||||||||||||||||||||||||
| 79 | 0 | else { confess 'no support for ref '.(ref $what) } | |||||||||||||||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||||||||||||||||
| 81 | # check for typeglobs | ||||||||||||||||||||||||||||||||||||||||||
| 82 | 13 | ▶ | if ((ref \$what eq 'GLOB') and (my $fh = *{$what}{IO})) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%2/2
ref \$what eq "GLOB" and my $fh = *{$what;}{"IO"}
MC/DC100%1/1
ref \$what eq "GLOB" and my $fh = *{$what;}{"IO"}
ref \$what eq "GLOB"
Truth table100%2/2
A
A= ref \$what eq "GLOB"
| |||||||||||||||||||||||||||||||||||||||||||
| 83 | 1 | return ('iofile', $fh); | |||||||||||||||||||||||||||||||||||||||||
| 84 | } | ||||||||||||||||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||||||||||||||||
| 86 | 12 | ▶ | if ($what =~ m{^file://(.+)$}) { return ('file', $1) } # local file | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 87 | 11 | ▶ | if ($what =~ m{^https?://}) { return ('http', $what) } # http link | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 88 | 9 | ▶ | if ($what =~ m{^<}) { return ('string', $what) } # xml string | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 89 | 8 | ▶ | if ($what =~ m(^{)) { return ('string', $what) } # json string | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 90 | 6 | ▶ | if ($what =~ m{^\[}) { return ('string', $what) } # json string | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 91 | 5 | ▶ | if ($what =~ m{\n[\s\w]}) { return ('string', $what) } # multi-line string | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 92 | 4 | ▶ | if ($what eq '') { return ('string', '') } # empty string | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 93 | 2 | { return ('file', $what) } # default is filename | |||||||||||||||||||||||||||||||||||||||||
| 94 | } | ||||||||||||||||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||||||||||||||||
| 96 | 10 | ▶ | sub read { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
read: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 97 | 10 | my $class = shift; | |||||||||||||||||||||||||||||||||||||||||
| 98 | 10 | my $what = shift; | |||||||||||||||||||||||||||||||||||||||||
| 99 | 10 | my $opt = shift; | |||||||||||||||||||||||||||||||||||||||||
| 100 | 10 | ▶ | confess 'too many arguments' | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 101 | if @_; | ||||||||||||||||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||||||||||||||||
| 103 | 10 | return $class->new($what, '<', $opt); | |||||||||||||||||||||||||||||||||||||||||
| 104 | } | ||||||||||||||||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||||||||||||||||
| 106 | 2 | ▶ | sub write { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
write: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 107 | 2 | my $class = shift; | |||||||||||||||||||||||||||||||||||||||||
| 108 | 2 | my $what = shift; | |||||||||||||||||||||||||||||||||||||||||
| 109 | 2 | my $opt = shift; | |||||||||||||||||||||||||||||||||||||||||
| 110 | 2 | ▶ | confess 'too many arguments' | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 111 | if @_; | ||||||||||||||||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||||||||||||||||
| 113 | 2 | return $class->new($what, '>', $opt); | |||||||||||||||||||||||||||||||||||||||||
| 114 | } | ||||||||||||||||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||||||||||||||||
| 116 | 4 | ▶ | sub slurp { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
slurp: called CC=6 SCAR=25.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 117 | 4 | my $class = shift; | |||||||||||||||||||||||||||||||||||||||||
| 118 | 4 | my $what = shift; | |||||||||||||||||||||||||||||||||||||||||
| 119 | 4 | my $opt = shift; | |||||||||||||||||||||||||||||||||||||||||
| 120 | 4 | ▶ | confess 'too many arguments' | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 121 | if @_; | ||||||||||||||||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||||||||||||||||
| 123 | 4 | my $fh = $class->read($what, $opt); | |||||||||||||||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||||||||||||||||
| 125 | # use event loop when AnyEvent is loaded (skip IO::String, doesn't work and makes no sense) | ||||||||||||||||||||||||||||||||||||||||||
| 126 | # not supported under MSWin32 | ||||||||||||||||||||||||||||||||||||||||||
| 127 | 4 | ▶ | if ($INC{'AnyEvent.pm'} and not $fh->isa('IO::String') and ($^O ne 'MSWin32')) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%2/6
$INC{"AnyEvent.pm"} and not $fh->isa("IO::String") and $^O ne "MSWin32"
$INC{"AnyEvent.pm"} and not $fh->isa("IO::String")
MC/DC0%0/3
$INC{"AnyEvent.pm"} and not $fh->isa("IO::String") and $^O ne "MSWin32"
$INC{"AnyEvent.pm"}
not $fh->isa("IO::String")
$^O ne "MSWin32"
Truth table25%1/4
A and not(B) and C
A= $INC{"AnyEvent.pm"}B= not $fh->isa("IO::String")C= $^O ne "MSWin32"
| |||||||||||||||||||||||||||||||||||||||||||
| 128 | eval 'use AnyEvent::Handle' | ||||||||||||||||||||||||||||||||||||||||||
| 129 | 0 | ▶ | if not $INC{'AnyEvent/Handle.pm'}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 130 | 0 | my $eof = AnyEvent->condvar; | |||||||||||||||||||||||||||||||||||||||||
| 131 | 0 | my $content = ''; | |||||||||||||||||||||||||||||||||||||||||
| 132 | my $hdl = AnyEvent::Handle->new( | ||||||||||||||||||||||||||||||||||||||||||
| 133 | fh => $fh, | ||||||||||||||||||||||||||||||||||||||||||
| 134 | 0 | ▶ | on_read => sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 135 | 0 | $content .= delete $_[0]->{'rbuf'}; | |||||||||||||||||||||||||||||||||||||||||
| 136 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 137 | 0 | ▶ | on_eof => sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 138 | 0 | $eof->send; | |||||||||||||||||||||||||||||||||||||||||
| 139 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 140 | 0 | ▶ | on_error => sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 141 | 0 | my ($hdl, $fatal, $msg) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 142 | 0 | $hdl->destroy; | |||||||||||||||||||||||||||||||||||||||||
| 143 | 0 | $eof->croak($msg); | |||||||||||||||||||||||||||||||||||||||||
| 144 | } | ||||||||||||||||||||||||||||||||||||||||||
| 145 | 0 | ); | |||||||||||||||||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||||||||||||||||
| 147 | 0 | $eof->recv; | |||||||||||||||||||||||||||||||||||||||||
| 148 | 0 | $hdl->destroy; | |||||||||||||||||||||||||||||||||||||||||
| 149 | 0 | close $fh; | |||||||||||||||||||||||||||||||||||||||||
| 150 | 0 | return $content; | |||||||||||||||||||||||||||||||||||||||||
| 151 | } | ||||||||||||||||||||||||||||||||||||||||||
| 152 | |||||||||||||||||||||||||||||||||||||||||||
| 153 | 4 | my $content = do { local $/; <$fh> }; | |||||||||||||||||||||||||||||||||||||||||
| 154 | 4 | close $fh; | |||||||||||||||||||||||||||||||||||||||||
| 155 | 4 | return $content; | |||||||||||||||||||||||||||||||||||||||||
| 156 | } | ||||||||||||||||||||||||||||||||||||||||||
| 157 | |||||||||||||||||||||||||||||||||||||||||||
| 158 | 5 | ▶ | sub spew { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
spew: called CC=6 SCAR=24.6
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 159 | 5 | my $class = shift; | |||||||||||||||||||||||||||||||||||||||||
| 160 | 5 | my $what = shift; | |||||||||||||||||||||||||||||||||||||||||
| 161 | 5 | my $data = shift; | |||||||||||||||||||||||||||||||||||||||||
| 162 | 5 | my $opt = shift; | |||||||||||||||||||||||||||||||||||||||||
| 163 | 5 | ▶ | confess 'too many arguments' | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 164 | if @_; | ||||||||||||||||||||||||||||||||||||||||||
| 165 | |||||||||||||||||||||||||||||||||||||||||||
| 166 | # "parade" to allow safe locking | ||||||||||||||||||||||||||||||||||||||||||
| 167 | 5 | my $fh = $class->new($what, '+>>', $opt); | |||||||||||||||||||||||||||||||||||||||||
| 168 | 4 | $fh->seek(0,0); | |||||||||||||||||||||||||||||||||||||||||
| 169 | 4 | $fh->truncate(0); | |||||||||||||||||||||||||||||||||||||||||
| 170 | |||||||||||||||||||||||||||||||||||||||||||
| 171 | # use event loop when AnyEvent is loaded (skip IO::String, doesn't work and makes no sense) | ||||||||||||||||||||||||||||||||||||||||||
| 172 | 4 | ▶ | if ($INC{'AnyEvent.pm'} and not $fh->isa('IO::String')) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$INC{"AnyEvent.pm"} and not $fh->isa("IO::String")
MC/DC0%0/2
$INC{"AnyEvent.pm"} and not $fh->isa("IO::String")
$INC{"AnyEvent.pm"}
not $fh->isa("IO::String")
Truth table33%1/3
A and not(B)
A= $INC{"AnyEvent.pm"}B= not $fh->isa("IO::String")
| |||||||||||||||||||||||||||||||||||||||||||
| 173 | eval 'use AnyEvent::Handle' | ||||||||||||||||||||||||||||||||||||||||||
| 174 | 0 | ▶ | if not $INC{'AnyEvent/Handle.pm'}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 175 | |||||||||||||||||||||||||||||||||||||||||||
| 176 | 0 | my $eof = AnyEvent->condvar; | |||||||||||||||||||||||||||||||||||||||||
| 177 | my $hdl = AnyEvent::Handle->new( | ||||||||||||||||||||||||||||||||||||||||||
| 178 | fh => $fh, | ||||||||||||||||||||||||||||||||||||||||||
| 179 | 0 | ▶ | on_drain => sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 180 | 0 | $eof->send; | |||||||||||||||||||||||||||||||||||||||||
| 181 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 182 | 0 | ▶ | on_error => sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 183 | 0 | my ($hdl, $fatal, $msg) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 184 | 0 | $hdl->destroy; | |||||||||||||||||||||||||||||||||||||||||
| 185 | 0 | $eof->croak($msg); | |||||||||||||||||||||||||||||||||||||||||
| 186 | } | ||||||||||||||||||||||||||||||||||||||||||
| 187 | 0 | ); | |||||||||||||||||||||||||||||||||||||||||
| 188 | |||||||||||||||||||||||||||||||||||||||||||
| 189 | 0 | $hdl->push_write($data); | |||||||||||||||||||||||||||||||||||||||||
| 190 | |||||||||||||||||||||||||||||||||||||||||||
| 191 | 0 | $eof->recv; | |||||||||||||||||||||||||||||||||||||||||
| 192 | 0 | $hdl->destroy; | |||||||||||||||||||||||||||||||||||||||||
| 193 | 0 | close $fh; | |||||||||||||||||||||||||||||||||||||||||
| 194 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 195 | } | ||||||||||||||||||||||||||||||||||||||||||
| 196 | |||||||||||||||||||||||||||||||||||||||||||
| 197 | 4 | print $fh $data; | |||||||||||||||||||||||||||||||||||||||||
| 198 | 4 | ▶ | $fh->close || confess 'failed to close file - '.$!; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 199 | 4 | return; | |||||||||||||||||||||||||||||||||||||||||
| 200 | } | ||||||||||||||||||||||||||||||||||||||||||
| 201 | |||||||||||||||||||||||||||||||||||||||||||
| 202 | 2 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 203 | |||||||||||||||||||||||||||||||||||||||||||
| 204 | |||||||||||||||||||||||||||||||||||||||||||
| 205 | __END__ | ||||||||||||||||||||||||||||||||||||||||||