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

filter: Statementstmt 40.9% 27 / 66 Branchbran 0.0% 0 / 16 Conditioncond 0.0% 0 / 7 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 50.0% 6 / 12 Podpod 100% 5 / 5 totaltotal 34.5% 38 / 110 CC 12 SCAR 34.5
CC
12
Cov
30%
read
73.5
_initialize
12.0
new
6.0
CRAP 31.4
« blib/lib/Net/FreeDB2/Response/Read.pm ↑ Summary blib/lib/Net/FreeDB2/Site.pm »
1 package Net::FreeDB2::Response::Sites;
2  
3 # Copyright 2002, Vincenzo Zocca.
4  
5 # See LICENSE section for usage and distribution rights.
6  
7 3 require 5.005_62;
8 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 3 require Exporter;
12 3 ▶use AutoLoader qw(AUTOLOAD);
Subroutine BEGIN: called CC=1 SCAR=0.0
13 3 ▶use Error qw (:try);
Subroutine BEGIN: called CC=1 SCAR=0.0
14 3 ▶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::Sites ':all';
23 # If you do not need this, moving things directly into @EXPORT or @EXPORT_OK
24 # will save memory.
25 3 our %EXPORT_TAGS = ( 'all' => [ qw(
26
27 ) ] );
28  
29 3 our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } );
30  
31 3 our @EXPORT = qw(
32
33 );
34 3 our $VERSION = '0.01';
35  
36 3 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=9 SCAR=43.0
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::Sites::read, option \'content_ref\' not defined.');
Branch: 1 branch
BranchTrueFalseTotal
exists $opt->{"content_ref"} or "Error::Simple"->throw("ERROR: Net::FreeDB2::Response::Sites::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::Sites::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::Sites::read, first line of specified 'content_ref' does not contain a code.") 0 0 0
68 0 ▶ if ($code == 210) {
Branch: 2 branches
BranchTrueFalseTotal
if ($code == 210) { } 0 0 0
elsif ($code == 401) { } 0 0 0
69 0 my @sites = ();
70 0 ▶ while (my $line = shift (@content_ref)) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $line = shift @content_ref) 0 0 0
71 0 ▶ $line eq '.' && last;
Branch: 1 branch
BranchTrueFalseTotal
$line eq "." and last 0 0 0
72 0 ▶ $line =~ /^\s*.\s*$/ && last;
Branch: 1 branch
BranchTrueFalseTotal
$line =~ /^\s*.\s*$/ and last 0 0 0
73 0 my @line = split (/\s/, $line, 5);
74 3 ▶ use Net::FreeDB2::Site;
Subroutine BEGIN: called CC=1 SCAR=0.0
75 0 push (@sites, Net::FreeDB2::Site->new ({
76 site => $line[0],
77 port => $line[1],
78 latitude => $line[2],
79 longitude => $line[3],
80 description => $line[4],
81 }));
82 }
83 0 $self->setSites (@sites);
84 0 $self->setError (0);
85 0 $self->setResult ('OK');
86 } elsif ($code == 401) {
87 0 $self->setSites ();
88 0 $self->setError (0);
89 0 $self->setResult ('No site information available');
90 } else {
91 0 throw Error::Simple ("ERROR: Net::FreeDB2::Response::Sites::read, unknown code '$code' returned.");
92 }
93 }
94  
95 0 ▶sub setSites {
Subroutine setSites: not called CC=1 SCAR=6.9
Pod documented
96 0 my $self = shift;
97  
98 0 @{$self->{Net_FreeDB2_Response_Sites}{sites}} = @_;
99 }
100  
101 0 ▶sub pushSites {
Subroutine pushSites: not called CC=1 SCAR=6.9
Pod documented
102 0 my $self = shift;
103  
104 0 push (@{$self->{Net_FreeDB2_Response_Sites}{sites}}, @_);
105 }
106  
107 0 ▶sub getSites {
Subroutine getSites: not called CC=1 SCAR=6.9
Pod documented
108 0 my $self = shift;
109  
110 0 return (@{$self->{Net_FreeDB2_Response_Sites}{sites}});
111 }
112  
113 3 1;
114 __END__
« blib/lib/Net/FreeDB2/Response/Read.pm ↑ Summary blib/lib/Net/FreeDB2/Site.pm »