line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Net::FreeDB2::Response::Sites; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
# Copyright 2002, Vincenzo Zocca. |
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
# See LICENSE section for usage and distribution rights. |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
require 5.005_62; |
8
|
3
|
|
|
3
|
|
16
|
use strict; |
|
3
|
|
|
|
|
5
|
|
|
3
|
|
|
|
|
110
|
|
9
|
3
|
|
|
3
|
|
15
|
use warnings; |
|
3
|
|
|
|
|
16
|
|
|
3
|
|
|
|
|
119
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
require Exporter; |
12
|
3
|
|
|
3
|
|
745
|
use AutoLoader qw(AUTOLOAD); |
|
3
|
|
|
|
|
2150
|
|
|
3
|
|
|
|
|
24
|
|
13
|
3
|
|
|
3
|
|
1215
|
use Error qw (:try); |
|
3
|
|
|
|
|
12807
|
|
|
3
|
|
|
|
|
27
|
|
14
|
3
|
|
|
3
|
|
741
|
use base qw (Net::FreeDB2::Response Exporter); |
|
3
|
|
|
|
|
7
|
|
|
3
|
|
|
|
|
7888
|
|
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
|
|
|
|
|
|
|
our %EXPORT_TAGS = ( 'all' => [ qw( |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
) ] ); |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } ); |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
our @EXPORT = qw( |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
); |
34
|
|
|
|
|
|
|
our $VERSION = '0.01'; |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
my $CODE_RX = '^\s*(\d{3})\s+'; |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
sub new { |
39
|
0
|
|
|
0
|
1
|
|
my $class = shift; |
40
|
|
|
|
|
|
|
|
41
|
0
|
|
|
|
|
|
my $self = {}; |
42
|
0
|
|
0
|
|
|
|
bless ($self, (ref($class) || $class)); |
43
|
0
|
|
|
|
|
|
return ($self->_initialize (@_)); |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
sub _initialize { |
47
|
0
|
|
|
0
|
|
|
my $self = shift; |
48
|
0
|
|
0
|
|
|
|
my $opt = shift || {}; |
49
|
|
|
|
|
|
|
|
50
|
0
|
0
|
|
|
|
|
defined ($opt->{content_ref}) and $self->read ($opt); |
51
|
0
|
|
|
|
|
|
return ($self); |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
sub read { |
55
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
56
|
0
|
|
0
|
|
|
|
my $opt = shift || {}; |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
# Check if content_ref is specified |
59
|
0
|
0
|
|
|
|
|
exists ($opt->{content_ref}) || throw Error::Simple ('ERROR: Net::FreeDB2::Response::Sites::read, option \'content_ref\' not defined.'); |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
# Convert $opt->{content_ref} to @content_ref |
62
|
0
|
|
|
|
|
|
my @content_ref = split (/[\n\r]+/, ${$opt->{content_ref}}); |
|
0
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
# Parse first line |
65
|
0
|
|
|
|
|
|
my $line = shift (@content_ref); |
66
|
0
|
|
|
|
|
|
my ($code) = $line =~ /$CODE_RX/; |
67
|
0
|
0
|
|
|
|
|
defined ($code) || throw Error::Simple ('ERROR: Net::FreeDB2::Response::Sites::read, first line of specified \'content_ref\' does not contain a code.'); |
68
|
0
|
0
|
|
|
|
|
if ($code == 210) { |
|
|
0
|
|
|
|
|
|
69
|
0
|
|
|
|
|
|
my @sites = (); |
70
|
0
|
|
|
|
|
|
while (my $line = shift (@content_ref)) { |
71
|
0
|
0
|
|
|
|
|
$line eq '.' && last; |
72
|
0
|
0
|
|
|
|
|
$line =~ /^\s*.\s*$/ && last; |
73
|
0
|
|
|
|
|
|
my @line = split (/\s/, $line, 5); |
74
|
3
|
|
|
3
|
|
1755
|
use Net::FreeDB2::Site; |
|
3
|
|
|
|
|
8
|
|
|
3
|
|
|
|
|
1312
|
|
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
|
|
|
|
|
|
|
sub setSites { |
96
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
97
|
|
|
|
|
|
|
|
98
|
0
|
|
|
|
|
|
@{$self->{Net_FreeDB2_Response_Sites}{sites}} = @_; |
|
0
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
} |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
sub pushSites { |
102
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
103
|
|
|
|
|
|
|
|
104
|
0
|
|
|
|
|
|
push (@{$self->{Net_FreeDB2_Response_Sites}{sites}}, @_); |
|
0
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
} |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
sub getSites { |
108
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
109
|
|
|
|
|
|
|
|
110
|
0
|
|
|
|
|
|
return (@{$self->{Net_FreeDB2_Response_Sites}{sites}}); |
|
0
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
} |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
1; |
114
|
|
|
|
|
|
|
__END__ |