| 1 | package Proc::Hevy::Writer; | ||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||
| 3 | 25 | ▶ | use strict; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 4 | 25 | ▶ | use warnings; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||||
| 6 | 25 | ▶ | use Carp; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 7 | 25 | ▶ | use Errno qw( EWOULDBLOCK ); | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 8 | 25 | ▶ | use IO::Pipe; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 9 | 25 | ▶ | use POSIX (); | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||
| 12 | 67 | ▶ | sub new { | ||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||
| 13 | 67 | my ( $class, $name, $buffer ) = @_; | |||||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||||||
| 15 | 67 | my $pipe; | |||||||||||||||||||||||||||||||
| 16 | 67 | ▶ | $pipe = IO::Pipe->new | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $buffer and ref $buffer ne "GLOB"
MC/DC50%1/2
defined $buffer and ref $buffer ne "GLOB"
defined $buffer
ref $buffer ne "GLOB"
Truth table66%2/3
A and B
A= defined $bufferB= ref $buffer ne "GLOB"
| |||||||||||||||||||||||||||||||||
| 17 | if defined $buffer and ref $buffer ne 'GLOB'; | ||||||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||||||
| 19 | 67 | bless { name => $name, buffer => $buffer, pipe => $pipe }, $class; | |||||||||||||||||||||||||||||||
| 20 | } | ||||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||||
| 22 | 20 | ▶ | sub child { | ||||||||||||||||||||||||||||||
|
Subroutine
child: called CC=6 SCAR=20.2
Pod
documented
| |||||||||||||||||||||||||||||||||
| 23 | 20 | my ( $self, $std_h, $fileno ) = @_; | |||||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||||||
| 25 | 20 | my $handle; | |||||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||||||
| 27 | 20 | ▶ | if( defined $self->{pipe} ) { | ||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||
| 28 | 4 | $handle = $self->{pipe}->reader; | |||||||||||||||||||||||||||||||
| 29 | } | ||||||||||||||||||||||||||||||||
| 30 | elsif( ref $self->{buffer} eq 'GLOB' ) { | ||||||||||||||||||||||||||||||||
| 31 | 0 | $handle = $self->{buffer}; | |||||||||||||||||||||||||||||||
| 32 | } | ||||||||||||||||||||||||||||||||
| 33 | else { | ||||||||||||||||||||||||||||||||
| 34 | 16 | ▶ | open $handle, '<', '/dev/null' | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 35 | or confess "$self->{name}: open: /dev/null: $!\n"; | ||||||||||||||||||||||||||||||||
| 36 | } | ||||||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||||||
| 38 | 20 | ▶ | POSIX::dup2( $handle->fileno, $fileno ) | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition40%2/5
$std_h != $handle && (POSIX::dup2($handle->fileno, $fileno) || confess("$self->{'name'}: dup2: $!\n"))
POSIX::dup2($handle->fileno, $fileno) or confess(qq[$self->{"name"}: dup2: $!\n])
MC/DC0%0/2
$std_h != $handle && (POSIX::dup2($handle->fileno, $fileno) || confess("$self->{'name'}: dup2: $!\n"))
$std_h != $handle
POSIX::dup2($handle->fileno, $fileno)
Truth table0%0/3
A && B
A= $std_h != $handleB= POSIX::dup2($handle->fileno, $fileno)
| |||||||||||||||||||||||||||||||||
| 39 | or confess "$self->{name}: dup2: $!\n" | ||||||||||||||||||||||||||||||||
| 40 | if $std_h != $handle; | ||||||||||||||||||||||||||||||||
| 41 | } | ||||||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||||||
| 43 | 47 | ▶ | sub parent { | ||||||||||||||||||||||||||||||
|
Subroutine
parent: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||
| 44 | 47 | my ( $self, $select ) = @_; | |||||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||||||
| 46 | 47 | ▶ | unless( defined $self->{pipe} ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 47 | delete $self->{buffer} | ||||||||||||||||||||||||||||||||
| 48 | 37 | ▶ | if defined $self->{buffer}; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||||||
| 50 | 37 | return; | |||||||||||||||||||||||||||||||
| 51 | } | ||||||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||||||
| 53 | 10 | $self->{scratch} = ''; | |||||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||||||
| 55 | 10 | my $handle = $self->{pipe}->writer; | |||||||||||||||||||||||||||||||
| 56 | 10 | $handle->blocking( 0 ); | |||||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||||||
| 58 | 10 | $select->add( $handle ); | |||||||||||||||||||||||||||||||
| 59 | 10 | $self->{select} = $select; | |||||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||||||
| 61 | 10 | return ( $handle, $self ); | |||||||||||||||||||||||||||||||
| 62 | } | ||||||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||||||
| 64 | 32 | ▶ | sub write { | ||||||||||||||||||||||||||||||
|
Subroutine
write: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||||||
| 65 | 32 | my ( $self ) = @_; | |||||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||||||
| 67 | 32 | my $handle = $self->{pipe}; | |||||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||||||
| 69 | 32 | ▶ | if( length( $self->{scratch} ) == 0 ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 70 | 32 | my $scratch = $self->_unpack; | |||||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||||||
| 72 | 32 | ▶ | unless( defined $scratch ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 73 | 10 | $self->{select}->remove( $handle ); | |||||||||||||||||||||||||||||||
| 74 | 10 | ▶ | $handle->close | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 75 | or confess "$self->{name}: close: $!\n"; | ||||||||||||||||||||||||||||||||
| 76 | 10 | return; | |||||||||||||||||||||||||||||||
| 77 | } | ||||||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||||||
| 79 | 22 | $self->{scratch} = $scratch; | |||||||||||||||||||||||||||||||
| 80 | } | ||||||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||||||
| 82 | 22 | $self->_flush; | |||||||||||||||||||||||||||||||
| 83 | } | ||||||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||||||
| 85 | 32 | ▶ | sub _unpack { | ||||||||||||||||||||||||||||||
|
Subroutine
_unpack: called CC=6 SCAR=18.0
| |||||||||||||||||||||||||||||||||
| 86 | 32 | my ( $self ) = @_; | |||||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||||||
| 88 | 32 | my $ref = ref $self->{buffer}; | |||||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||||||
| 90 | return delete $self->{buffer} | ||||||||||||||||||||||||||||||||
| 91 | 32 | ▶ | if $ref eq ''; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||||||
| 93 | 24 | my $data; | |||||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||||||
| 95 | 24 | ▶ | if( $ref eq 'ARRAY' ) { | ||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||
| 96 | 16 | $data = shift @{ $self->{buffer} }; | |||||||||||||||||||||||||||||||
| 97 | } | ||||||||||||||||||||||||||||||||
| 98 | elsif( $ref eq 'CODE' ) { | ||||||||||||||||||||||||||||||||
| 99 | 8 | $data = $self->{buffer}->(); | |||||||||||||||||||||||||||||||
| 100 | } | ||||||||||||||||||||||||||||||||
| 101 | else { | ||||||||||||||||||||||||||||||||
| 102 | 0 | confess "$self->{name}: API error\n"; | |||||||||||||||||||||||||||||||
| 103 | } | ||||||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||||||
| 105 | 24 | ▶ | $data .= defined $\ ? $\ : "\n" | ||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||
| 106 | if defined $data; | ||||||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||||||
| 108 | 24 | return $data; | |||||||||||||||||||||||||||||||
| 109 | } | ||||||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||||||
| 111 | 22 | ▶ | sub _flush { | ||||||||||||||||||||||||||||||
|
Subroutine
_flush: called CC=4 SCAR=15.9
| |||||||||||||||||||||||||||||||||
| 112 | 22 | my ( $self ) = @_; | |||||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||||||
| 114 | return | ||||||||||||||||||||||||||||||||
| 115 | 22 | ▶ | unless length $self->{scratch}; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||||||
| 117 | 22 | my $handle = $self->{pipe}; | |||||||||||||||||||||||||||||||
| 118 | 22 | my $rc = $handle->syswrite( $self->{scratch} ); | |||||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||||||
| 120 | 22 | ▶ | if( not defined $rc ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 121 | 0 | ▶ | confess "$self->{name}: syswrite: $!\n" | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 122 | if $! != EWOULDBLOCK; | ||||||||||||||||||||||||||||||||
| 123 | } | ||||||||||||||||||||||||||||||||
| 124 | else { | ||||||||||||||||||||||||||||||||
| 125 | 22 | substr( $self->{scratch}, 0, $rc ) = ''; | |||||||||||||||||||||||||||||||
| 126 | } | ||||||||||||||||||||||||||||||||
| 127 | } | ||||||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||||||
| 130 | 25 | 1 | |||||||||||||||||||||||||||||||
| 131 | __END__ | ||||||||||||||||||||||||||||||||