SMTP/Conn.pm

filter: Statementstmt 91.0% 102 / 112 Branchbran 51.6% 31 / 60 Conditioncond 33.3% 2 / 6 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 95.2% 20 / 21 Podpod 11.1% 1 / 9 totaltotal 73.5% 156 / 212 CC 36 SCAR 14.8
CC
36
Cov
76%
command
8.3
__ANON__
6.0
line
5.8
CRAP 4.4
« SMTP/Client.pm ↑ Summary SMTP.pm »
1 package AnyEvent::SMTP::Conn;
2  
3 12 ▶use AnyEvent;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 12 ▶use common::sense;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 12 m{# trying to cheat with cpants game ;)
6 use strict;
7 use warnings;
8 }x;
9 12 ▶use base 'Object::Event';
Subroutine BEGIN: called CC=1 SCAR=0.0
10 12 ▶use AnyEvent::Handle;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 12 ▶our $VERSION = $AnyEvent::SMTP::VERSION;use AnyEvent::SMTP ();
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 12 our $NL = "\015\012";
15 12 our $QRNL = qr<\015?\012>;
16  
17 88 ▶sub new {
Subroutine new: called CC=2 SCAR=8.1
Pod documented
18 88 my $pkg = shift;
19 88 my $self = bless { @_ }, $pkg;
20 $self->{h} = AnyEvent::Handle->new(
21 fh => $self->{fh},
22 0 ▶ on_eof => sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
23 0 local *__ANON__ = 'conn.on_eof';
24 0 warn "eof on handle";
25 0 ▶ $self->{h} and $self->{h}->destroy;
Branch: 1 branch
BranchTrueFalseTotal
$self->{"h"} and $self->{"h"}->destroy 0 0 0
26 0 delete $self->{h};
27 0 $self->event('disconnect');
28 },
29 46 ▶ on_error => sub {
Subroutine __ANON__: called CC=2 SCAR=7.0
30 46 local *__ANON__ = 'conn.on_error';
31 #warn "error on handle: $!";
32 46 ▶ $self->{h} and $self->{h}->destroy;
Branch: 1 branch
BranchTrueFalseTotal
$self->{"h"} and $self->{"h"}->destroy 46 0 46
33 46 delete $self->{h};
34 46 $self->event( disconnect => "Error: $!" );
35 },
36 88 );
37 88 ▶ $self->{h}->timeout($self->{timeout}) if $self->{timeout};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"timeout"} 41 47 88
38 88 $self;
39 }
40  
41 42 ▶sub close {
Subroutine close: called CC=2 SCAR=7.0
Pod undocumented
42 42 my $self = shift;
43 42 delete $self->{fh};
44 42 ▶ $self->{h} and $self->{h}->destroy;
Branch: 1 branch
BranchTrueFalseTotal
$self->{"h"} and $self->{"h"}->destroy 42 0 42
45 42 delete $self->{h};
46 42 $self->event( disconnect => () );
47 42 return;
48 }
49  
50 205 ▶sub command {
Subroutine command: called CC=7 SCAR=21.2
Pod undocumented
51 205 my $self = shift;
52 205 my $write = shift;
53 205 my %args = @_;
54 205 ▶ $args{ok} = '250' unless defined $args{ok};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $args{"ok"} 0 205 205
55 0 ▶ $args{cb} or return $self->event( error => "no cb for command at @{[ (caller)[1,2] ]}" );
Branch: 1 branch
BranchTrueFalseTotal
$args{"cb"} or return $self->event("error", "no cb for command at @{[(caller)[1, 2]];}") 205 0 205
56 205 ▶ $self->{h} or return $args{cb}->(undef,"Not connected");
Branch: 1 branch
BranchTrueFalseTotal
$self->{"h"} or return $args{"cb"}->(undef, "Not connected") 205 0 205
57 #my $i if 0;
58 #my $c = ++$i;
59 205 ▶ warn ">> $write " if $self->{debug};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"debug"} 0 205 205
60 205 $self->{h}->push_write("$write$NL");
61 #$self->{h}->timeout( $self->{select_timeout} );
62 205 ▶ warn "<? read " if $self->{debug} and $self->{debug} > 1;
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"debug"} and $self->{"debug"} > 1 0 205 205
Condition33%1/3
$self->{"debug"} and $self->{"debug"} > 1
!ll&&!rl&&r
20500
MC/DC0%0/2
$self->{"debug"} and $self->{"debug"} > 1
$self->{"debug"} $self->{"debug"} > 1
Truth table33%1/3
A and B
A= $self->{"debug"}B= $self->{"debug"} > 1
ABresult
0X0
100
111
63 205 ▶ $self->{h}->push_read( regex => $QRNL, sub {
Subroutine __ANON__: called CC=5 SCAR=16.8
64 205 local *__ANON__ = 'conn.command.read';
65 205 shift;
66 205 for (@_) {
67 205 chomp;
68 205 ▶ substr($_,-1,1) = '' if substr($_, -1,1) eq "\015";
Branch: 1 branch
BranchTrueFalseTotal
if substr($_, -1, 1) eq "\r" 205 0 205
69 }
70 205 ▶ warn "<< @_ " if $self->{debug};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"debug"} 0 205 205
71 205 my $line = join '',@_;
72 205 ▶ if ( substr( $line,0,length($args{ok})+1 ) eq $args{ok}.' ' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (substr($line, 0, length($args{'ok'}) + 1) eq $args{'ok'} . ' ') { } 205 0 205
73 205 $args{cb}($line);
74 } else {
75 0 $args{cb}(undef, $line);
76 }
77 205 } );
78 }
79  
80 41 ▶sub line {
Subroutine line: called CC=5 SCAR=17.5
Pod undocumented
81 41 my $self = shift;
82 41 my %args = @_;
83 41 ▶ $args{ok} = '250' unless defined $args{ok};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $args{"ok"} 0 41 41
84 0 ▶ $args{cb} or return $self->event( error => "no cb for command at @{[ (caller)[1,2] ]}" );
Branch: 1 branch
BranchTrueFalseTotal
$args{"cb"} or return $self->event("error", "no cb for command at @{[(caller)[1, 2]];}") 41 0 41
85 41 ▶ warn "<? read " if $self->{debug} and $self->{debug} > 1;
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"debug"} and $self->{"debug"} > 1 0 41 41
Condition33%1/3
$self->{"debug"} and $self->{"debug"} > 1
!ll&&!rl&&r
4100
MC/DC0%0/2
$self->{"debug"} and $self->{"debug"} > 1
$self->{"debug"} $self->{"debug"} > 1
Truth table33%1/3
A and B
A= $self->{"debug"}B= $self->{"debug"} > 1
ABresult
0X0
100
111
86 41 ▶ $self->{h}->push_read( regex => $QRNL, sub {
Subroutine __ANON__: called CC=5 SCAR=16.8
87 41 local *__ANON__ = 'conn.line.read';
88 41 shift;
89 41 for (@_) {
90 41 chomp;
91 41 ▶ substr($_,-1,1) = '' if substr($_, -1,1) eq "\015";
Branch: 1 branch
BranchTrueFalseTotal
if substr($_, -1, 1) eq "\r" 41 0 41
92 }
93 41 ▶ warn "<< @_ " if $self->{debug};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"debug"} 0 41 41
94 41 my $line = join '',@_;
95 41 ▶ if ( substr( $line,0,length($args{ok})+1 ) eq $args{ok}.' ' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (substr($line, 0, length($args{'ok'}) + 1) eq $args{'ok'} . ' ') { } 41 0 41
96 41 $args{cb}(1);
97 } else {
98 0 $args{cb}(undef, $line);
99 }
100 41 } );
101
102 }
103  
104 211 ▶sub want_command {
Subroutine want_command: called CC=2 SCAR=7.1
Pod undocumented
105 211 my $self = shift;
106 211 ▶ $self->{h} or return warn "Not connected";
Branch: 1 branch
BranchTrueFalseTotal
$self->{"h"} or return warn("Not connected") 211 0 211
107 164 ▶ $self->{h}->push_read( regex => $QRNL, sub {
Subroutine __ANON__: called CC=5 SCAR=16.6
108 164 local *__ANON__ = 'conn.want_command.read';
109 164 shift;
110 164 for (@_) {
111 164 chomp;
112 164 ▶ substr($_,-1,1) = '' if substr($_, -1,1) eq "\015";
Branch: 1 branch
BranchTrueFalseTotal
if substr($_, -1, 1) eq "\r" 164 0 164
113 }
114 164 ▶ warn "<< @_ " if $self->{debug};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"debug"} 0 164 164
115 164 $self->event(command => @_);
116 164 ▶ $self->want_command if $self->{h};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"h"} 164 0 164
117 211 });
118 }
119  
120 164 ▶sub ok {
Subroutine ok: called CC=4 SCAR=14.1
Pod undocumented
121 164 my $self = shift;
122 164 ▶ $self->{h} or return warn "Not connected";
Branch: 1 branch
BranchTrueFalseTotal
$self->{"h"} or return warn("Not connected") 164 0 164
123 164 ▶ @_ = ('Ok.') unless @_;
Branch: 1 branch
BranchTrueFalseTotal
unless @_ 82 82 164
124 164 $self->{h}->push_write("250 @_$NL");
125 164 ▶ warn ">> 250 @_ " if $self->{debug};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"debug"} 0 164 164
126 }
127  
128 129 ▶sub reply {
Subroutine reply: called CC=3 SCAR=11.4
Pod undocumented
129 129 my $self = shift;
130 129 ▶ $self->{h} or return warn "Not connected";
Branch: 1 branch
BranchTrueFalseTotal
$self->{"h"} or return warn("Not connected") 129 0 129
131 129 $self->{h}->push_write("@_$NL");
132 129 ▶ warn ">> @_ " if $self->{debug};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"debug"} 0 129 129
133 }
134  
135 41 ▶sub data {
Subroutine data: called CC=4 SCAR=14.3
Pod undocumented
136 41 my $self = shift;
137 41 my %args = @_;
138 0 ▶ $args{cb} or return $self->event( error => "no cb for command at @{[ (caller)[1,2] ]}" );
Branch: 1 branch
BranchTrueFalseTotal
$args{"cb"} or return $self->event("error", "no cb for command at @{[(caller)[1, 2]];}") 41 0 41
139 41 ▶ $self->{h} or return $args{cb}->(undef,"Not connected");
Branch: 1 branch
BranchTrueFalseTotal
$self->{"h"} or return $args{"cb"}->(undef, "Not connected") 41 0 41
140 41 ▶ warn '<+ read till \r\n.\r\n ' if $self->{debug};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"debug"} 0 41 41
141 41 ▶ $self->{h}->unshift_read( regex => qr/((?:\015?\012|^)\.\015?\012)/, sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
142 41 shift;
143 12 ▶ use bytes;
Subroutine BEGIN: called CC=1 SCAR=0.0
144 41 $args{cb}(substr($_[0],0,length($_[0]) - length ($1)))
145 41 } );
146  
147 }
148  
149 41 ▶sub new_m {
Subroutine new_m: called CC=1 SCAR=0.0
Pod undocumented
150 41 my $self = shift;
151 41 $self->{m} = { host => $self->{host}, port => $self->{port}, helo => $self->{helo}, @_ };
152 }
153 12 1;
« SMTP/Client.pm ↑ Summary SMTP.pm »