Subprocess/Handle.pm

filter: Statementstmt 98.0% 51 / 52 Branchbran 81.2% 13 / 16 Conditioncond 70.5% 12 / 17 MC/DCmcdc 40.0% 4 / 10 Subroutinesub 100% 15 / 15 Podpod 66.6% 4 / 6 totaltotal 85.3% 99 / 116 CC 15 SCAR 13.8
CC
15
Cov
89%
on_finalize
7.3
new
7.0
name
2.1
CRAP 4.0
↑ Summary Subprocess/DefaultDelegates.pm »
1 package AnyEvent::Subprocess::Handle;
2 48 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
3 48 $AnyEvent::Subprocess::Handle::VERSION = '1.102912';
4 }
5 # ABSTRACT: AnyEvent::Handle subclass with some additional methods for AnyEvent::Subprocess
6 48 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 48 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 48 ▶use AnyEvent;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 48 ▶use base 'AnyEvent::Handle';
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 145 ▶sub new {
Subroutine new: called CC=7 SCAR=19.5
Pod documented
12 145 my ($class, @args) = @_;
13 145 my %args = @args;
14  
15 145 my $is_read = 0;
16 145 my $is_write = 0;
17 145 ▶ if(my $d = $args{_direction}){
Branch: 1 branch
BranchTrueFalseTotal
if (my $d = $args{"_direction"}) 145 0 145
18 145 ▶ $is_read = 1 if $d eq 'r' || $d eq 'rw';
Branch: 1 branch
BranchTrueFalseTotal
if $d eq "r" or $d eq "rw" 103 42 145
Condition100%3/3
$d eq "r" or $d eq "rw"
l!l&&r!l&&!r
94942
MC/DC100%2/2
$d eq "r" or $d eq "rw"
$d eq "r" $d eq "rw"
Truth table100%3/3
A or B
A= $d eq "r"B= $d eq "rw"
ABresult
1X1
011
000
19 145 ▶ $is_write = 1 if $d eq 'w' || $d eq 'rw';
Branch: 1 branch
BranchTrueFalseTotal
if $d eq "w" or $d eq "rw" 51 94 145
Condition100%3/3
$d eq "w" or $d eq "rw"
l!l&&r!l&&!r
42994
MC/DC100%2/2
$d eq "w" or $d eq "rw"
$d eq "w" $d eq "rw"
Truth table100%3/3
A or B
A= $d eq "w"B= $d eq "rw"
ABresult
1X1
011
000
20 }
21  
22 45 ▶ my $send = sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
23 45 my $handle = shift;
24 # warn "handle error: $$ @_ ($!) -- ". $handle->name
25 # if $ENV{PERL_ANYEVENT_VERBOSE} && @_;
26  
27 45 $handle->_do_finalize;
28 45 return 0;
29 145 };
30  
31 145 push @args, on_error => $send, on_eof => $send;
32  
33 # if the on_read is not provided, we never get notified of handle
34 # close (presumably because no watchers are ever created)
35 145 ▶ push @args, on_read => sub { } if $is_read;
Subroutine __ANON__: called CC=1 SCAR=0.0
Branch: 1 branch
BranchTrueFalseTotal
if $is_read 103 42 145
36  
37 145 my $self = $class->SUPER::new(@args);
38  
39 145 return $self;
40 }
41  
42 192 ▶sub on_finalize {
Subroutine on_finalize: called CC=6 SCAR=19.9
Pod undocumented
43 192 my ($self, $cb) = @_;
44 192 ▶ $self->{__on_finalize} = $cb if $cb;
Branch: 1 branch
BranchTrueFalseTotal
if $cb 94 98 192
45  
46 192 ▶ if($cb && $self->{destroyed} && !$self->{finalized}){
Branch: 1 branch
BranchTrueFalseTotal
if ($cb and $self->{"destroyed"} and not $self->{"finalized"}) 0 192 192
Condition50%3/6
$cb and $self->{"destroyed"} and not $self->{"finalized"}
!ll&&!rl&&r
19200
$cb and $self->{"destroyed"}
!ll&&!rl&&r
98940
MC/DC0%0/3
$cb and $self->{"destroyed"} and not $self->{"finalized"}
$cb $self->{"destroyed"} not $self->{"finalized"}
Truth table50%2/4
A and B and not(C)
A= $cbB= $self->{"destroyed"}C= not $self->{"finalized"}
ABCresult
0XX0
10X0
1100
1111
47 0 $cb->($self);
48 }
49  
50 192 ▶ return $self->{__on_finalize} || sub { };
Subroutine __ANON__: called CC=1 SCAR=0.2
Condition66%2/3
$self->{'__on_finalize'} || sub { }
l!l&&r!l&&!r
168240
MC/DC0%0/2
$self->{'__on_finalize'} || sub { }
$self->{'__on_finalize'} sub { }
Truth table66%2/3
A || B
A= $self->{'__on_finalize'}B= sub { }
ABresult
1X1
011
000
51 }
52  
53 105 ▶sub _do_finalize {
Subroutine _do_finalize: called CC=2 SCAR=6.9
54 105 my ($self) = @_;
55 105 ▶ return if $self->{finalized}++;
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"finalized"}++ 7 98 105
56 98 $self->_drain_rbuf;
57 98 $self->on_finalize->();
58 }
59  
60 50 ▶sub name {
Subroutine name: called CC=2 SCAR=7.2
Pod documented
61 50 my $self = shift;
62 50 ▶ return $self->{_name} || "<fd ". fileno($self->fh). ">";
Condition50%1/2
$self->{'_name'} || '<fd ' . fileno($self->fh) . '>'
l!l
500
MC/DC0%0/1
$self->{'_name'} || '<fd ' . fileno($self->fh) . '>'
$self->{'_name'}
Truth table50%1/2
A
A= $self->{'_name'}
Aresult
11
00
63 }
64  
65 53 ▶sub do_not_want {
Subroutine do_not_want: called CC=2 SCAR=7.1
Pod undocumented
66 53 my $self = shift;
67 53 ▶ close $self->fh if $self->fh; # sometimes people close too soon
Branch: 1 branch
BranchTrueFalseTotal
if $self->fh 53 0 53
68 53 $self->destroy;
69 }
70  
71 # not push_close, since I am not sure what the semantics of that would
72 # be. use "on_drain( close_fh )" to close after your last write (or
73 # push_shutdown).
74 7 ▶sub close_fh {
Subroutine close_fh: called CC=1 SCAR=0.0
Pod documented
75 7 my $self = shift;
76 7 close $self->fh;
77 }
78  
79 60 ▶sub destroy {
Subroutine destroy: called CC=1 SCAR=0.0
Pod documented
80 60 my ($self, @args) = @_;
81 60 my $rbuf = $self->{rbuf};
82 60 $self->_do_finalize;
83 60 $self->SUPER::destroy(@args);
84 60 $self->{rbuf} = $rbuf;
85 60 $self->{destroyed} = 1;
86 60 return;
87 }
88  
89 47 1;
90  
91  
92  
93 =pod
94  
95 =head1 NAME
96  
97 AnyEvent::Subprocess::Handle - AnyEvent::Handle subclass with some additional methods for AnyEvent::Subprocess
98  
99 =head1 VERSION
100  
101 version 1.102912
102  
103 =head1 DESCRIPTION
104  
105 Assume this acts like a normal L<AnyEvent::Handle|AnyEvent::Handle>.
106 It just has some extra code to make the handle delegate's life easier.
107  
108 =head1 EXTRA METHODS
109  
110 =head2 name
111  
112 Returns the name of the filehandle, or "<fd #>" if no name was passed
113 to the constructor.
114  
115 =head2 close_fh
116  
117 Closes the underlying filehandle, sending EOF to the child process.
118  
119 =head1 AUTHOR
120  
121 Jonathan Rockway <jrockway@cpan.org>
122  
123 =head1 COPYRIGHT AND LICENSE
124  
125 This software is copyright (c) 2011 by Jonathan Rockway.
126  
127 This is free software; you can redistribute it and/or modify it under
128 the same terms as the Perl 5 programming language system itself.
129  
130 =cut
131  
132  
133 __END__
↑ Summary Subprocess/DefaultDelegates.pm »