| 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
| |||||||||||||||||||||||||||||||||||||||||
| 17 | 8 | my $port = $args->{port}; | |||||||||||||||||||||||||||||||||||||||
| 18 | 8 | ▶ | $port = 79 unless defined $port; | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 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'
$args->{'timeout'} || 60
$args->{'on_error'} || sub {
carp($_[0]);
}
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'}
Truth table50%1/2
A
A= $args->{'timeout'}
Truth table66%2/3
A || B
A= $args->{'on_error'}B= sub {
carp($_[0]);
}
| |||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||
| 33 | 20 | ▶ | my $callback = shift || sub {}; | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=1.2
Condition33%1/3
shift() || sub {
}
MC/DC0%0/2
shift() || sub {
}
shift()
sub {
}
Truth table33%1/3
A || B
A= shift()B= sub {
}
| |||||||||||||||||||||||||||||||||||||||||
| 34 | 20 | ▶ | my $args = ref $_[0] eq 'HASH' ? (\%{$_[0]}) : ({@_}); | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||||||||||||||
| 36 | 20 | for(qw( hostname port timeout on_error )) | |||||||||||||||||||||||||||||||||||||||
| 37 | { | ||||||||||||||||||||||||||||||||||||||||
| 38 | 80 | ▶ | next if defined $args->{$_}; | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||
| 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
Condition33%1/3
ref $request and $request->isa("AnyEvent::Finger::Request")
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")
| |||||||||||||||||||||||||||||||||||||||||
| 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__ | ||||||||||||||||||||||||||||||||||||||||