line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Net::FreeDB2::Response::Hello; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
# Copyright 2002, Vincenzo Zocca. |
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
# See LICENSE section for usage and distribution rights. |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
require 5.005_62; |
8
|
2
|
|
|
2
|
|
57
|
use strict; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
113
|
|
9
|
2
|
|
|
2
|
|
11
|
use warnings; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
89
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
require Exporter; |
12
|
2
|
|
|
2
|
|
1135
|
use AutoLoader qw(AUTOLOAD); |
|
2
|
|
|
|
|
1788
|
|
|
2
|
|
|
|
|
14
|
|
13
|
2
|
|
|
2
|
|
1233
|
use Error qw (:try); |
|
2
|
|
|
|
|
7812
|
|
|
2
|
|
|
|
|
15
|
|
14
|
2
|
|
|
2
|
|
425
|
use base qw (Net::FreeDB2::Response Exporter); |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
1275
|
|
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::Hello ':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 ) = '$Revision: 0.8.2.3 $ ' =~ /\$Revision:\s+([^\s]+)/; |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
sub new { |
37
|
0
|
|
|
0
|
1
|
|
my $class = shift; |
38
|
|
|
|
|
|
|
|
39
|
0
|
|
|
|
|
|
my $self = {}; |
40
|
0
|
|
0
|
|
|
|
bless ($self, (ref($class) || $class)); |
41
|
0
|
|
|
|
|
|
return ($self->_initialize (@_)); |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
sub _initialize { |
45
|
0
|
|
|
0
|
|
|
my $self = shift; |
46
|
0
|
|
0
|
|
|
|
my $opt = shift || {}; |
47
|
|
|
|
|
|
|
|
48
|
0
|
0
|
|
|
|
|
defined ($opt->{content_ref}) and $self->read ($opt); |
49
|
0
|
|
|
|
|
|
return ($self); |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
sub read { |
53
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
54
|
0
|
|
0
|
|
|
|
my $opt = shift || {}; |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
# Check if content_ref is specified |
57
|
0
|
0
|
|
|
|
|
exists ($opt->{content_ref}) || throw Error::Simple ('ERROR: Net::FreeDB2::Response::Hello::read, option \'content_ref\' not defined.'); |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
# Convert $opt->{content_ref} to @content_ref |
60
|
0
|
|
|
|
|
|
my @content_ref = split (/[\n\r]+/, ${$opt->{content_ref}}); |
|
0
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
# Parse first line |
63
|
0
|
|
|
|
|
|
my $line = shift (@content_ref); |
64
|
0
|
|
|
|
|
|
my ($code) = $line =~ /^\s*(\d{3})\s+/; |
65
|
0
|
0
|
|
|
|
|
defined ($code) || throw Error::Simple ('ERROR: Net::FreeDB2::Response::Hello::read, first line of specified \'content_ref\' does not contain a code.'); |
66
|
0
|
0
|
0
|
|
|
|
$code == 200 || $code == 431 || $code == 431 || throw Error::Simple ('ERROR: Net::FreeDB2::Response::Hello::read, first line of specified \'content_ref\' does not contain a code.'); |
|
|
|
0
|
|
|
|
|
67
|
0
|
0
|
|
|
|
|
if ($code == 200) { |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
68
|
0
|
|
|
|
|
|
$self->setError (0); |
69
|
0
|
|
|
|
|
|
$self->setResult ('Handshake successful'); |
70
|
|
|
|
|
|
|
} elsif ($code == 402) { |
71
|
0
|
|
|
|
|
|
$self->setError (0); |
72
|
0
|
|
|
|
|
|
$self->setResult ('Already shook hands'); |
73
|
|
|
|
|
|
|
} elsif ($code == 431) { |
74
|
0
|
|
|
|
|
|
$self->setError (1); |
75
|
0
|
|
|
|
|
|
$self->setResult ('Handshake not successful, closing connection'); |
76
|
|
|
|
|
|
|
} else { |
77
|
0
|
|
|
|
|
|
throw Error::Simple ("ERROR: Net::FreeDB2::Response::Hello::read, unknown code '$code' returned."); |
78
|
|
|
|
|
|
|
} |
79
|
|
|
|
|
|
|
} |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
1; |
82
|
|
|
|
|
|
|
__END__ |