Finger/Client.pm

filter: Statementstmt 88.6% 47 / 53 Branchbran 71.4% 10 / 14 Conditioncond 53.8% 7 / 13 MC/DCmcdc 12.5% 1 / 8 Subroutinesub 80.0% 12 / 15 Podpod 50.0% 1 / 2 totaltotal 74.2% 78 / 105 CC 14 SCAR 13.9
CC
14
Cov
80%
new
6.8
finger
6.5
__ANON__
4.6
CRAP 4.0
« Finger/Server.pm ↑ Summary Finger/Request.pm »
1 package AnyEvent::Finger::Client;
2  
3 6 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 6 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 6 ▶use AnyEvent::Socket qw( tcp_connect );
Subroutine BEGIN: called CC=1 SCAR=0.0
6 6 ▶use AnyEvent::Handle;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 6 ▶use Carp qw( carp );
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 # ABSTRACT: Simple asynchronous finger client
10 6 our $VERSION = '0.14'; # VERSION
11  
12  
13 sub new
14 8 ▶{
Subroutine new: called CC=6 SCAR=19.1
Pod undocumented
15 8 my $class = shift;
16 0 ▶ my $args = ref $_[0] eq 'HASH' ? (\%{$_[0]}) : ({@_});
Branch: 1 branch
BranchTrueFalseTotal
ref $_[0] eq 'HASH' ? : 0 8 8
17 8 my $port = $args->{port};
18 8 ▶ $port = 79 unless defined $port;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $port 3 5 8
19 bless {
20 hostname => $args->{hostname} || '127.0.0.1',
21 port => $port,
22 timeout => $args->{timeout} || 60,
23 0 ▶ on_error => $args->{on_error} || sub { carp $_[0] },
Subroutine __ANON__: not called CC=1 SCAR=6.9
24 8 ▶ }, $class;
Condition71%5/7
$args->{'hostname'} || '127.0.0.1'
l!l
26
$args->{'timeout'} || 60
l!l
08
$args->{'on_error'} || sub { carp($_[0]); }
l!l&&r!l&&!r
530
MC/DC100%1/1
$args->{'hostname'} || '127.0.0.1'
$args->{'hostname'}
MC/DC0%0/1
$args->{'timeout'} || 60
$args->{'timeout'}
MC/DC0%0/2
$args->{'on_error'} || sub { carp($_[0]); }
$args->{'on_error'} sub { carp($_[0]); }
Truth table100%2/2
A
A= $args->{'hostname'}
Aresult
11
00
Truth table50%1/2
A
A= $args->{'timeout'}
Aresult
11
00
Truth table66%2/3
A || B
A= $args->{'on_error'}B= sub { carp($_[0]); }
ABresult
1X1
011
000
25 }
26  
27  
28 sub finger
29 20 ▶{
Subroutine finger: called CC=6 SCAR=18.8
Pod documented
30 20 my $self = shift;
31 20 my $request = shift;
32 20 ▶ $request = '' unless defined $request;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $request 0 20 20
33 20 ▶ my $callback = shift || sub {};
Subroutine __ANON__: not called CC=1 SCAR=1.2
Condition33%1/3
shift() || sub { }
l!l&&r!l&&!r
2000
MC/DC0%0/2
shift() || sub { }
shift() sub { }
Truth table33%1/3
A || B
A= shift()B= sub { }
ABresult
1X1
011
000
34 20 ▶ my $args = ref $_[0] eq 'HASH' ? (\%{$_[0]}) : ({@_});
Branch: 1 branch
BranchTrueFalseTotal
ref $_[0] eq 'HASH' ? : 7 13 20
35  
36 20 for(qw( hostname port timeout on_error ))
37 {
38 80 ▶ next if defined $args->{$_};
Branch: 1 branch
BranchTrueFalseTotal
if defined $args->{$_} 9 71 80
39 71 $args->{$_} = $self->{$_};
40 }
41  
42 20 ▶ tcp_connect $args->{hostname}, $args->{port}, sub {
Subroutine __ANON__: called CC=4 SCAR=15.2
43  
44 20 my($fh) = @_;
45 20 ▶ return $args->{on_error}->("unable to connect: $!") unless $fh;
Branch: 1 branch
BranchTrueFalseTotal
unless $fh 0 20 20
46  
47 20 my @lines;
48  
49 my $handle;
50 $handle = AnyEvent::Handle->new(
51 fh => $fh,
52 0 ▶ on_error => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
53 0 my ($hdl, $fatal, $msg) = @_;
54 0 $args->{on_error}->($msg);
55 0 $_[0]->destroy;
56 },
57 20 ▶ on_eof => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
58 20 $handle->destroy;
59 20 $callback->(\@lines);
60 },
61 20 );
62  
63 20 ▶ if(ref $request && $request->isa('AnyEvent::Finger::Request'))
Branch: 1 branch
BranchTrueFalseTotal
if (ref $request and $request->isa("AnyEvent::Finger::Request")) 0 20 20
Condition33%1/3
ref $request and $request->isa("AnyEvent::Finger::Request")
!ll&&!rl&&r
2000
MC/DC0%0/2
ref $request and $request->isa("AnyEvent::Finger::Request")
ref $request $request->isa("AnyEvent::Finger::Request")
Truth table33%1/3
A and B
A= ref $requestB= $request->isa("AnyEvent::Finger::Request")
ABresult
0X0
100
111
64 0 { $request = $request->{raw} }
65 20 $handle->push_write("$request\015\012");
66  
67 45 ▶ $handle->on_read(sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
68 45 ▶ $handle->push_read( line => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
69 45 my($handle, $line) = @_;
70 45 $line =~ s/\015?\012//g;
71 45 push @lines, $line;
72 45 });
73 20 });
74  
75 20 ▶ }, sub { $args->{timeout} };
Subroutine __ANON__: called CC=1 SCAR=0.0
76  
77 20 $self;
78 }
79  
80 6 1;
81  
82 __END__
« Finger/Server.pm ↑ Summary Finger/Request.pm »