blib/lib/Net/FreeDB2/Response/SignOn.pm

filter: Statementstmt 32.0% 24 / 75 Branchbran 0.0% 0 / 18 Conditioncond 0.0% 0 / 19 MC/DCmcdc 0.0% 0 / 9 Subroutinesub 31.2% 5 / 16 Podpod 100% 10 / 10 totaltotal 26.5% 39 / 147 CC 17 SCAR 45.4
CC
17
Cov
21%
read
210.0
_initialize
12.0
new
6.0
CRAP 94.0
« blib/lib/Net/FreeDB2/Entry.pm ↑ Summary blib/lib/Net/FreeDB2/Response/Hello.pm »
1 package Net::FreeDB2::Response::SignOn;
2  
3 # Copyright 2002, Vincenzo Zocca.
4  
5 # See LICENSE section for usage and distribution rights.
6  
7 2 require 5.005_62;
8 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 2 require Exporter;
12 2 ▶use AutoLoader qw(AUTOLOAD);
Subroutine BEGIN: called CC=1 SCAR=0.0
13 2 ▶use Error qw (:try);
Subroutine BEGIN: called CC=1 SCAR=0.0
14 2 ▶use base qw (Net::FreeDB2::Response Exporter);
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 #our @ISA = qw(Exporter);
17  
18 # Items to export into callers namespace by default. Note: do not export
19 # names by default without a very good reason. Use EXPORT_OK instead.
20 # Do not simply export all your public functions/methods/constants.
21  
22 # This allows declaration use Net::FreeDB2::Response::SignOn ':all';
23 # If you do not need this, moving things directly into @EXPORT or @EXPORT_OK
24 # will save memory.
25 2 our %EXPORT_TAGS = ( 'all' => [ qw(
26
27 ) ] );
28  
29 2 our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } );
30  
31 2 our @EXPORT = qw(
32
33 );
34 2 our ( $VERSION ) = '$Revision: 0.8.2.4 $ ' =~ /\$Revision:\s+([^\s]+)/;
35  
36 2 my $CODE_RX = '^\s*(\d{3})\s+';
37  
38 0 ▶sub new {
Subroutine new: not called CC=2 SCAR=17.9
Pod documented
39 0 my $class = shift;
40  
41 0 my $self = {};
42 0 ▶ bless ($self, (ref($class) || $class));
Condition0%0/3
ref $class || $class
l!l&&r!l&&!r
000
MC/DC0%0/2
ref $class || $class
ref $class $class
Truth table0%0/3
A || B
A= ref $classB= $class
ABresult
1X1
011
000
43 0 return ($self->_initialize (@_));
44 }
45  
46 0 ▶sub _initialize {
Subroutine _initialize: not called CC=3 SCAR=24.8
47 0 my $self = shift;
48 0 ▶ my $opt = shift || {};
Condition0%0/2
shift() || {}
l!l
00
MC/DC0%0/1
shift() || {}
shift()
Truth table0%0/2
A
A= shift()
Aresult
11
00
49  
50 0 ▶ defined ($opt->{content_ref}) and $self->read ($opt);
Branch: 1 branch
BranchTrueFalseTotal
defined $opt->{"content_ref"} and $self->read($opt) 0 0 0
51 0 return ($self);
52 }
53  
54 0 ▶sub read {
Subroutine read: not called CC=14 SCAR=53.5
Pod documented
55 0 my $self = shift;
56 0 ▶ my $opt = shift || {};
Condition0%0/2
shift() || {}
l!l
00
MC/DC0%0/1
shift() || {}
shift()
Truth table0%0/2
A
A= shift()
Aresult
11
00
57  
58 # Check if content_ref is specified
59 0 ▶ exists ($opt->{content_ref}) || throw Error::Simple ('ERROR: Net::FreeDB2::Response::SignOn::read, option \'content_ref\' not defined.');
Branch: 1 branch
BranchTrueFalseTotal
exists $opt->{"content_ref"} or "Error::Simple"->throw("ERROR: Net::FreeDB2::Response::SignOn::read, option 'content_ref' not defined.") 0 0 0
60  
61 # Convert $opt->{content_ref} to @content_ref
62 0 my @content_ref = split (/[\n\r]+/, ${$opt->{content_ref}});
63  
64 # Parse first line
65 0 my $line = shift (@content_ref);
66 0 my ($code) = $line =~ /$CODE_RX/;
67 0 ▶ defined ($code) || throw Error::Simple ('ERROR: Net::FreeDB2::Response::SignOn::read, first line of specified \'content_ref\' does not contain a code.');
Branch: 1 branch
BranchTrueFalseTotal
defined $code or "Error::Simple"->throw("ERROR: Net::FreeDB2::Response::SignOn::read, first line of specified 'content_ref' does not contain a code.") 0 0 0
68 0 ▶ $code == 200 || $code == 201 || $code == 432 || $code == 433 || $code == 434 || throw Error::Simple ('ERROR: Net::FreeDB2::Response::SignOn::read, first line of specified \'content_ref\' does not contain a code.');
Branch: 1 branch
BranchTrueFalseTotal
$code == 200 or $code == 201 or $code == 432 or $code == 433 or $code == 434 or "Error::Simple"->throw("ERROR: Net::FreeDB2::Response::SignOn::read, first line of specified 'content_ref' does not contain a code.") 0 0 0
Condition0%0/12
$code == 200 or $code == 201 or $code == 432 or $code == 433 or $code == 434
l!l&&r!l&&!r
000
$code == 200 or $code == 201 or $code == 432 or $code == 433
l!l&&r!l&&!r
000
$code == 200 or $code == 201 or $code == 432
l!l&&r!l&&!r
000
$code == 200 or $code == 201
l!l&&r!l&&!r
000
MC/DC0%0/5
$code == 200 or $code == 201 or $code == 432 or $code == 433 or $code == 434
$code == 200 $code == 201 $code == 432 $code == 433 $code == 434
Truth table0%0/6
A or B or C or D or E
A= $code == 200B= $code == 201C= $code == 432D= $code == 433E= $code == 434
ABCDEresult
1XXXX1
01XXX1
001XX1
0001X1
000011
000000
69 0 $self->setWritePermission (1);
70 0 ▶ if ($code == 200) {
Branch: 5 branches
BranchTrueFalseTotal
if ($code == 200) { } 0 0 0
elsif ($code == 201) { } 0 0 0
elsif ($code == 432) { } 0 0 0
elsif ($code == 433) { } 0 0 0
elsif ($code == 434) { } 0 0 0
71 0 $self->setError (0);
72 0 $self->setResult ('OK, read/write allowed');
73 } elsif ($code == 201) {
74 0 $self->setError (0);
75 0 $self->setResult ('OK, read only');
76 0 $self->setWritePermission (0);
77 } elsif ($code == 432) {
78 0 $self->setError (0);
79 0 $self->setResult ('No connections allowed: permission denied');
80 } elsif ($code == 433) {
81 0 $self->setError (0);
82 0 $self->setResult ('No connections allowed: X users allowed, Y currently active');
83 } elsif ($code == 434) {
84 0 $self->setError (0);
85 0 $self->setResult ('No connections allowed: system load too high');
86 } else {
87 0 throw Error::Simple ("ERROR: Net::FreeDB2::Response::SignOn::read, unknown code '$code' returned.");
88 }
89  
90 # Parse the reats of the line
91 0 my ($code, $hostname, $version, $date) = split (/\s+/, $line, 4);
92 0 $self->setHostname ($hostname);
93 0 $self->setVersion ($version);
94 0 $self->setDate ($date);
95 }
96  
97 0 ▶sub setWritePermission {
Subroutine setWritePermission: not called CC=1 SCAR=6.9
Pod documented
98 0 my $self = shift;
99  
100 0 $self->{Net_FreeDB2_Response_SignOn}{write_permission} = shift;
101 }
102  
103 0 ▶sub hasWritePermission {
Subroutine hasWritePermission: not called CC=1 SCAR=6.9
Pod documented
104 0 my $self = shift;
105  
106 0 return ($self->{Net_FreeDB2_Response_SignOn}{write_permission});
107 }
108  
109 0 ▶sub setHostname {
Subroutine setHostname: not called CC=1 SCAR=6.9
Pod documented
110 0 my $self = shift;
111  
112 0 $self->{Net_FreeDB2_Response_SignOn}{hostname} = shift;
113 }
114  
115 0 ▶sub getHostname {
Subroutine getHostname: not called CC=1 SCAR=6.9
Pod documented
116 0 my $self = shift;
117  
118 0 return ($self->{Net_FreeDB2_Response_SignOn}{hostname});
119 }
120  
121 0 ▶sub setVersion {
Subroutine setVersion: not called CC=1 SCAR=6.9
Pod documented
122 0 my $self = shift;
123  
124 0 $self->{Net_FreeDB2_Response_SignOn}{version} = shift;
125 }
126  
127 0 ▶sub getVersion {
Subroutine getVersion: not called CC=1 SCAR=6.9
Pod documented
128 0 my $self = shift;
129  
130 0 return ($self->{Net_FreeDB2_Response_SignOn}{version});
131 }
132  
133 0 ▶sub setDate {
Subroutine setDate: not called CC=1 SCAR=6.9
Pod documented
134 0 my $self = shift;
135  
136 0 $self->{Net_FreeDB2_Response_SignOn}{date} = shift;
137 }
138  
139 0 ▶sub getDate {
Subroutine getDate: not called CC=1 SCAR=6.9
Pod documented
140 0 my $self = shift;
141  
142 0 return ($self->{Net_FreeDB2_Response_SignOn}{date});
143 }
144  
145 2 1;
146 __END__
« blib/lib/Net/FreeDB2/Entry.pm ↑ Summary blib/lib/Net/FreeDB2/Response/Hello.pm »