AnyEvent/FTP/Client/Role/RequestBuffer.pm

filter: Statementstmt 95.0% 76 / 80 Branchbran 90.9% 20 / 22 Conditioncond 62.5% 5 / 8 MC/DCmcdc 20.0% 1 / 5 Subroutinesub 100% 11 / 11 Podpod 0.0% 0 / 4 totaltotal 86.9% 113 / 130 SCAR 27.2
CC
15
Cov
92%
__ANON__
6.1
pop_command
6.0
unshift_command
3.1
CRAP 15.1
« AnyEvent/FTP/Server/Context/FS.pm ↑ Summary AnyEvent/FTP/Server/OS/UNIX.pm »
1 package AnyEvent::FTP::Client::Role::RequestBuffer;
2  
3 24 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 24 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 24 ▶use 5.010;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 24 ▶use Moo::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 24 ▶use AnyEvent;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 # ABSTRACT: Request buffer role for asynchronous ftp client
10 24 our $VERSION = '0.19'; # VERSION
11  
12  
13 has request_buffer => (
14 is => 'ro',
15 63 ▶ default => sub { [] },
Subroutine __ANON__: called CC=1 SCAR=0.0
16 24 );
17  
18 sub push_command
19 {
20 500 ▶ my $cv;
Subroutine push_command: called CC=3 SCAR=11.0
Pod undocumented
21  
22 500 ▶ $cv = pop if (ref $_[-1]) eq 'AnyEvent::CondVar';
Branch: 1 branch
BranchTrueFalseTotal
if ref $_[-1] eq "AnyEvent::CondVar" 25 475 500
23 500 ▶ $cv //= AnyEvent->condvar;
Condition66%2/3
$cv //= "AnyEvent"->condvar
l!l&&r!l&&!r
254750
MC/DC0%0/2
$cv //= "AnyEvent"->condvar
$cv "AnyEvent"->condvar
Truth table66%2/3
A //= B
A= $cvB= "AnyEvent"->condvar
ABresult
1X1
011
000
24  
25 500 my($self, @commands) = @_;
26  
27 500 push @{ $self->request_buffer }, { cmd => \@commands, cv => $cv };
28  
29 500 $self->pop_command;
30  
31 500 $cv;
32 }
33  
34 sub unshift_command
35 {
36 31 ▶ my $cv;
Subroutine unshift_command: called CC=3 SCAR=11.3
Pod undocumented
37  
38 31 ▶ $cv = pop if (ref $_[-1]) eq 'AnyEvent::CondVar';
Branch: 1 branch
BranchTrueFalseTotal
if ref $_[-1] eq "AnyEvent::CondVar" 31 0 31
39 31 ▶ $cv //= AnyEvent->condvar;
Condition33%1/3
$cv //= "AnyEvent"->condvar
l!l&&r!l&&!r
3100
MC/DC0%0/2
$cv //= "AnyEvent"->condvar
$cv "AnyEvent"->condvar
Truth table33%1/3
A //= B
A= $cvB= "AnyEvent"->condvar
ABresult
1X1
011
000
40  
41 31 my($self, @commands) = @_;
42  
43 31 unshift @{ $self->request_buffer }, { cmd => \@commands, cv => $cv };
44  
45 31 $self->pop_command;
46  
47 31 $cv;
48 }
49  
50 sub pop_command
51 {
52 1243 ▶ my($self) = @_;
Subroutine pop_command: called CC=6 SCAR=17.9
Pod undocumented
53  
54 1243 ▶ $self->{ready} //= 1;
Condition100%2/2
$self->{"ready"} //= 1
l!l
118063
MC/DC100%1/1
$self->{"ready"} //= 1
$self->{"ready"}
Truth table100%2/2
A
A= $self->{"ready"}
Aresult
11
00
55  
56 1243 ▶ return $self unless defined $self->{handle};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->{"handle"} 3 1240 1243
57  
58 1240 ▶ unless(@{ $self->request_buffer } > 0)
Branch: 1 branch
BranchTrueFalseTotal
unless (@{$self->request_buffer;} > 0) 565 675 1240
59 {
60 565 $self->{ready} = 1;
61 565 return $self;
62 }
63  
64 675 ▶ return unless $self->{ready};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"ready"} 1 674 675
65  
66 674 my($cmd, $args, $cb) = @{ shift @{ $self->request_buffer->[0]->{cmd} } };
67 674 ▶ my $line = defined $args ? join(' ', $cmd, $args) : $cmd;
Branch: 1 branch
BranchTrueFalseTotal
defined $args ? : 483 191 674
68  
69 674 my $handler;
70 $handler = sub {
71 744 ▶ my $res = shift;
Subroutine __ANON__: called CC=6 SCAR=18.1
72 744 ▶ if(defined $cb)
Branch: 1 branch
BranchTrueFalseTotal
if (defined $cb) 47 697 744
73 {
74 47 my $error = $cb->($res);
75 47 ▶ if(defined $error)
Branch: 1 branch
BranchTrueFalseTotal
if (defined $error) 0 47 47
76 {
77 0 my $batch = shift @{ $self->request_buffer };
78 0 $batch->{cv}->croak($error);
79 0 return;
80 }
81 }
82 744 ▶ if($res->is_preliminary)
Branch: 1 branch
BranchTrueFalseTotal
if ($res->is_preliminary) { } 70 674 744
83 {
84 70 $self->on_next_response($handler);
85 }
86 else
87 {
88 674 $self->{ready} = 1;
89 674 ▶ if($res->is_success)
Branch: 1 branch
BranchTrueFalseTotal
if ($res->is_success) { } 591 83 674
90 {
91 591 ▶ if(@{ $self->request_buffer->[0]->{cmd} } > 0)
Branch: 1 branch
BranchTrueFalseTotal
if (@{$self->request_buffer->[0]{'cmd'};} > 0) { } 143 448 591
92 {
93 143 $self->pop_command;
94 }
95 else
96 {
97 448 my $batch = shift @{ $self->request_buffer };
98 448 $batch->{cv}->send($res);
99 448 $self->pop_command;
100 }
101 }
102 else
103 {
104 83 my $batch = shift @{ $self->request_buffer };
105 83 $batch->{cv}->croak($res);
106 83 $self->pop_command;
107 }
108 }
109 674 };
110  
111 674 $self->on_next_response($handler);
112  
113 674 $self->{ready} = 0;
114 674 $self->emit('send', $cmd, $args);
115 674 $self->{handle}->push_write("$line\015\012");
116  
117 674 $self;
118 }
119  
120 sub clear_command
121 {
122 41 ▶ my($self) = @_;
Subroutine clear_command: called CC=1 SCAR=0.0
Pod undocumented
123 41 @{ $self->request_buffer } = ();
124 41 $self->{ready} = 1;
125 }
126  
127 24 1;
128  
129 __END__
« AnyEvent/FTP/Server/Context/FS.pm ↑ Summary AnyEvent/FTP/Server/OS/UNIX.pm »