| 1 | package Net::IMAP::Simple::PipeSocket; | ||||||||||
| 2 | |||||||||||
| 3 | 20 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 20 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | 20 | ▶ | use Carp; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | 20 | ▶ | use IPC::Open3; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | 20 | ▶ | use IO::Select; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 8 | 20 | ▶ | use Symbol 'gensym'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 9 | 20 | ▶ | use base 'Tie::Handle'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 10 | |||||||||||
| 11 | 0 | ▶ | sub new { | ||||||||
|
Subroutine
new: not called CC=5 SCAR=34.0
Pod
undocumented
| |||||||||||
| 12 | 0 | my $class = shift; | |||||||||
| 13 | 0 | my %args = @_; | |||||||||
| 14 | |||||||||||
| 15 | 0 | ▶ | croak "command (e.g. 'ssh hostname dovecot') argument required" unless $args{cmd}; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 16 | |||||||||||
| 17 | 0 | ▶ | open my $fake, "+>", undef or die "initernal error dealing with blarg: $!"; ## no critic | ||||||||
|
Branch: 1 branch
| |||||||||||
| 18 | |||||||||||
| 19 | 0 | my($wtr, $rdr, $err); $err = gensym; | |||||||||
| 20 | 0 | ▶ | my $pid = eval { open3($wtr, $rdr, $err, $args{cmd}) } or croak $@; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 21 | 0 | my $sel = IO::Select->new($err); | |||||||||
| 22 | |||||||||||
| 23 | # my $orig = select $wtr; $|=1; | ||||||||||
| 24 | # select $rdr; $|=1; | ||||||||||
| 25 | # select $orig; | ||||||||||
| 26 | |||||||||||
| 27 | 0 | ▶ | my $this = tie *{$fake}, $class, | ||||||||
|
Branch: 1 branch
| |||||||||||
| 28 | (%args, pid=>$pid, wtr=>$wtr, rdr=>$rdr, err=>$err, sel=>$sel, ) | ||||||||||
| 29 | or croak $!; | ||||||||||
| 30 | |||||||||||
| 31 | 0 | return $fake; | |||||||||
| 32 | } | ||||||||||
| 33 | |||||||||||
| 34 | 0 | ▶ | sub UNTIE { return $_[0]->_waitpid } | ||||||||
|
Subroutine
UNTIE: not called CC=1 SCAR=6.9
| |||||||||||
| 35 | 0 | ▶ | sub DESTROY { return $_[0]->_waitpid } | ||||||||
|
Subroutine
DESTROY: not called CC=1 SCAR=6.9
| |||||||||||
| 36 | |||||||||||
| 37 | 0 | ▶ | sub FILENO { | ||||||||
|
Subroutine
FILENO: not called CC=1 SCAR=6.9
| |||||||||||
| 38 | 0 | my $this = shift; | |||||||||
| 39 | 0 | my $rdr = $this->{rdr}; | |||||||||
| 40 | |||||||||||
| 41 | # do we mean rdr or wtr? meh? | ||||||||||
| 42 | 0 | return fileno($rdr); # probably need this for select() on the read handle | |||||||||
| 43 | } | ||||||||||
| 44 | |||||||||||
| 45 | 0 | ▶ | sub TIEHANDLE { | ||||||||
|
Subroutine
TIEHANDLE: not called CC=1 SCAR=6.9
| |||||||||||
| 46 | 0 | my $class = shift; | |||||||||
| 47 | 0 | my $this = bless {@_}, $class; | |||||||||
| 48 | |||||||||||
| 49 | 0 | return $this; | |||||||||
| 50 | } | ||||||||||
| 51 | |||||||||||
| 52 | 0 | ▶ | sub _chkerr { | ||||||||
|
Subroutine
_chkerr: not called CC=4 SCAR=30.0
| |||||||||||
| 53 | 0 | my $this = shift; | |||||||||
| 54 | 0 | my $sel = $this->{sel}; | |||||||||
| 55 | |||||||||||
| 56 | 0 | ▶ | while( my @rdy = $sel->can_read(0) ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 57 | 0 | for my $fh (@rdy) { | |||||||||
| 58 | 0 | ▶ | if( eof($fh) ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 59 | 0 | $sel->remove($fh); | |||||||||
| 60 | 0 | next; | |||||||||
| 61 | } | ||||||||||
| 62 | 0 | my $line = <$fh>; | |||||||||
| 63 | 0 | warn "PIPE ERR: $line"; | |||||||||
| 64 | } | ||||||||||
| 65 | } | ||||||||||
| 66 | |||||||||||
| 67 | return | ||||||||||
| 68 | 0 | } | |||||||||
| 69 | |||||||||||
| 70 | 0 | ▶ | sub PRINT { | ||||||||
|
Subroutine
PRINT: not called CC=1 SCAR=6.9
| |||||||||||
| 71 | 0 | my $this = shift; | |||||||||
| 72 | 0 | my $wtr = $this->{wtr}; | |||||||||
| 73 | |||||||||||
| 74 | 0 | $this->_chkerr; | |||||||||
| 75 | 0 | return print $wtr @_; | |||||||||
| 76 | } | ||||||||||
| 77 | |||||||||||
| 78 | 0 | ▶ | sub READLINE { | ||||||||
|
Subroutine
READLINE: not called CC=1 SCAR=6.9
| |||||||||||
| 79 | 0 | my $this = shift; | |||||||||
| 80 | 0 | my $rdr = $this->{rdr}; | |||||||||
| 81 | |||||||||||
| 82 | 0 | $this->_chkerr; | |||||||||
| 83 | 0 | my $line = <$rdr>; | |||||||||
| 84 | 0 | return $line; | |||||||||
| 85 | } | ||||||||||
| 86 | |||||||||||
| 87 | 0 | ▶ | sub _waitpid { | ||||||||
|
Subroutine
_waitpid: not called CC=4 SCAR=30.0
| |||||||||||
| 88 | 0 | my $this = shift; | |||||||||
| 89 | |||||||||||
| 90 | 0 | ▶ | if( my $pid = delete $this->{pid} ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 91 | 0 | for my $key (qw(wtr rdr err)) { | |||||||||
| 92 | 0 | ▶ | close delete $this->{$key} if exists $this->{$key}; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 93 | } | ||||||||||
| 94 | |||||||||||
| 95 | 0 | kill 1, $pid; | |||||||||
| 96 | # doesn't really matter if this works... we hung up all the | ||||||||||
| 97 | # filehandles, so ... it's probably dead anyway. | ||||||||||
| 98 | |||||||||||
| 99 | 0 | waitpid( $pid, 0 ); | |||||||||
| 100 | 0 | my $child_exit_status = $? >> 8; | |||||||||
| 101 | 0 | return $child_exit_status; | |||||||||
| 102 | } | ||||||||||
| 103 | |||||||||||
| 104 | 0 | return; | |||||||||
| 105 | } | ||||||||||
| 106 | |||||||||||
| 107 | 0 | ▶ | sub CLOSE { | ||||||||
|
Subroutine
CLOSE: not called CC=3 SCAR=24.8
| |||||||||||
| 108 | 0 | my $this = shift; | |||||||||
| 109 | 0 | my $rdr = $this->{rdr}; | |||||||||
| 110 | 0 | my $wtr = $this->{wtr}; | |||||||||
| 111 | |||||||||||
| 112 | 0 | ▶ | close $rdr or warn "PIPE ERR (close-r): $!"; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 113 | 0 | ▶ | close $wtr or warn "PIPE ERR (close-w): $!"; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 114 | |||||||||||
| 115 | 0 | return; | |||||||||
| 116 | } | ||||||||||
| 117 | |||||||||||
| 118 | 20 | 1; | |||||||||
| 119 | |||||||||||
| 120 | __END__ | ||||||||||