blib/lib/Net/Finger.pm

filter: Statementstmt 31.0% 18 / 58 Branchbran 0.0% 0 / 26 Conditioncond 0.0% 0 / 5 MC/DCmcdc 0.0% 0 / 3 Subroutinesub 80.0% 4 / 5 Podpod 0.0% 0 / 1 totaltotal 22.4% 22 / 98 CC 16 SCAR 53.8
CC
16
Cov
20%
finger
272.0
BEGIN
1.0
BEGIN
1.0
CRAP 217.8
↑ Summary
1 ##################################################################
2 # #
3 # Net::Finger, a Perl implementation of a finger client. #
4 # #
5 # By Dennis "FIMM" Taylor, <corbeau@execpc.com> #
6 # #
7 # This module may be used and distributed under the same terms #
8 # as Perl itself. See your Perl distribution for details. #
9 # #
10 ##################################################################
11 # $Id$
12  
13 package Net::Finger;
14  
15 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 1 ▶use Socket;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 1 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 1 ▶use vars qw($VERSION @ISA @EXPORT $error $debug);
Subroutine BEGIN: called CC=1 SCAR=0.0
19  
20 1 require Exporter;
21 1 @ISA = qw(Exporter);
22 1 @EXPORT = qw( &finger );
23  
24 1 $VERSION = '1.06';
25 1 $debug = 0;
26  
27  
28 # I know the if ($debug) crap gets in the way of the code a bit, but
29 # it's a worthy sacrifice as far as I'm concerned.
30  
31 0 ▶sub finger {
Subroutine finger: not called CC=16 SCAR=56.1
Pod undocumented
32 0 my ($addr, $verbose) = @_;
33 0 my ($host, $port, $request, @lines, $line);
34  
35 0 ▶ unless (@_) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@_) 0 0 0
36 0 carp "Not enough arguments to Net::Finger::finger()";
37 }
38  
39 # Set the error indicator to something innocuous.
40 0 $error = "";
41  
42 0 ▶ $addr ||= '';
Condition0%0/2
$addr ||= ""
l!l
00
MC/DC0%0/1
$addr ||= ""
$addr
Truth table0%0/2
A
A= $addr
Aresult
11
00
43 0 ▶ if (index( $addr, '@' ) >= 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (index($addr, '@') != -1) { } 0 0 0
44 0 my @tokens = split /\@/, $addr;
45 0 $host = pop @tokens;
46 0 $request = join '@', @tokens;
47
48 } else {
49 0 $host = 'localhost';
50 0 $request = $addr;
51 }
52  
53 0 ▶ if ($verbose) {
Branch: 1 branch
BranchTrueFalseTotal
if ($verbose) 0 0 0
54 0 $request = "/W $request";
55 }
56  
57 0 ▶ if ($debug) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Net::Finger::debug) 0 0 0
58 0 warn "Creating a new socket.\n";
59 }
60  
61 0 ▶ unless (socket( SOCK, PF_INET, SOCK_STREAM, getprotobyname('tcp'))) {
Branch: 1 branch
BranchTrueFalseTotal
unless (socket SOCK, 2, 1, getprotobyname "tcp") 0 0 0
62 0 $error = "Can\'t create a new socket: $!";
63 0 return;
64 }
65 0 select SOCK; $| = 1; select STDOUT;
66  
67 0 ▶ $port = ($host =~ s/:([0-9]*)$// && $1) ? $1 :
Branch: 1 branch
BranchTrueFalseTotal
$host =~ s/:([0-9]*)$// && $1 ? : 0 0 0
Condition0%0/3
$host =~ s/:([0-9]*)$// and $1
!ll&&!rl&&r
000
MC/DC0%0/2
$host =~ s/:([0-9]*)$// and $1
$host =~ s/:([0-9]*)$// $1
Truth table0%0/3
A and B
A= $host =~ s/:([0-9]*)$//B= $1
ABresult
0X0
100
111
68 (getservbyname('finger', 'tcp'))[2];
69
70 0 ▶ if ($debug) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Net::Finger::debug) 0 0 0
71 0 warn "Connecting to $host, port $port.\n";
72 }
73  
74 0 ▶ unless (connect( SOCK, sockaddr_in($port, inet_aton($host)) ))
Branch: 1 branch
BranchTrueFalseTotal
unless (connect SOCK, sockaddr_in($port, inet_aton($host))) 0 0 0
75 {
76 0 $error = "Can\'t connect to $host: $!";
77 0 return;
78 }
79  
80 0 ▶ if ($debug) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Net::Finger::debug) 0 0 0
81 0 warn "Sending request: \"$request\"\n";
82 }
83  
84 0 print SOCK "$request\015\012";
85  
86 0 ▶ if ($debug) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Net::Finger::debug) 0 0 0
87 0 warn "Waiting for response.\n";
88 }
89  
90 0 ▶ while (defined( $line = <SOCK> )) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($line = readline SOCK)) 0 0 0
91 0 $line =~ s/\015?\012/\n/g; # thanks (again), Pudge!
92 0 push @lines, $line;
93 }
94  
95 0 ▶ if ($debug) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Net::Finger::debug) 0 0 0
96 0 warn "Response received. Closing connection.\n";
97 }
98  
99 0 close SOCK;
100 0 ▶ return( wantarray ? @lines : join('', @lines) );
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 0 0
101 }
102  
103  
104  
105 1 1;
106 __END__
↑ Summary