| 1 | package Net::FreeDB2::Response::Query; | ||||||||||||||||||||||||||
| 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::Query ':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 ) = '$Revision: 0.8.2.3 $ ' =~ /\$Revision:\s+([^\s]+)/; | |||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||
| 36 | 3 | my $CODE_RX = '^\s*(\d{3})\s+'; | |||||||||||||||||||||||||
| 37 | 3 | my $EXACT_MATCH_RX = $CODE_RX . '(\S+)\s+(\S+)\s+(.*)\s*$'; | |||||||||||||||||||||||||
| 38 | 3 | my $INEXACT_MATCH_RX = '^\s*(\S+)\s+(\S+)\s+(.*)\s*$'; | |||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||
| 40 | 0 | ▶ | sub new { | ||||||||||||||||||||||||
|
Subroutine
new: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||
| 41 | 0 | my $class = shift; | |||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||
| 43 | 0 | my $self = {}; | |||||||||||||||||||||||||
| 44 | 0 | ▶ | bless ($self, (ref($class) || $class)); | ||||||||||||||||||||||||
|
Condition0%0/3
ref $class || $class
MC/DC0%0/2
ref $class || $class
ref $class
$class
Truth table0%0/3
A || B
A= ref $classB= $class
| |||||||||||||||||||||||||||
| 45 | 0 | return ($self->_initialize (@_)); | |||||||||||||||||||||||||
| 46 | } | ||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||
| 48 | 0 | ▶ | sub _initialize { | ||||||||||||||||||||||||
|
Subroutine
_initialize: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||
| 49 | 0 | my $self = shift; | |||||||||||||||||||||||||
| 50 | 0 | ▶ | my $opt = shift || {}; | ||||||||||||||||||||||||
|
Condition0%0/2
shift() || {}
MC/DC0%0/1
shift() || {}
shift()
Truth table0%0/2
A
A= shift()
| |||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||
| 52 | 0 | ▶ | defined ($opt->{content_ref}) and $self->read ($opt); | ||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||
| 53 | 0 | return ($self); | |||||||||||||||||||||||||
| 54 | } | ||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||
| 56 | 0 | ▶ | sub read { | ||||||||||||||||||||||||
|
Subroutine
read: not called CC=12 SCAR=47.5
Pod
documented
| |||||||||||||||||||||||||||
| 57 | 0 | my $self = shift; | |||||||||||||||||||||||||
| 58 | 0 | ▶ | my $opt = shift || {}; | ||||||||||||||||||||||||
|
Condition0%0/2
shift() || {}
MC/DC0%0/1
shift() || {}
shift()
Truth table0%0/2
A
A= shift()
| |||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||
| 60 | # Check if content_ref is specified | ||||||||||||||||||||||||||
| 61 | 0 | ▶ | exists ($opt->{content_ref}) || throw Error::Simple ('ERROR: Net::FreeDB2::Response::Query::read, option \'content_ref\' not defined.'); | ||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||
| 63 | # Convert $opt->{content_ref} to @content_ref | ||||||||||||||||||||||||||
| 64 | 0 | my @content_ref = split (/[\n\r]+/, ${$opt->{content_ref}}); | |||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||
| 66 | # Parse first line | ||||||||||||||||||||||||||
| 67 | 0 | my $line = shift (@content_ref); | |||||||||||||||||||||||||
| 68 | 0 | my ($code) = $line =~ /$CODE_RX/; | |||||||||||||||||||||||||
| 69 | 0 | ▶ | defined ($code) || throw Error::Simple ('ERROR: Net::FreeDB2::Response::Query::read, first line of specified \'content_ref\' does not contain a code.'); | ||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||
| 70 | 0 | ▶ | if ($code == 200) { | ||||||||||||||||||||||||
|
Branch: 5 branches
| |||||||||||||||||||||||||||
| 71 | 0 | my ($code, $categ, $discid, $dtitle) = $line =~ /$EXACT_MATCH_RX/; | |||||||||||||||||||||||||
| 72 | 3 | ▶ | use Net::FreeDB2::Match; | ||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||
| 73 | 0 | $self->setMatches (Net::FreeDB2::Match->new ({ | |||||||||||||||||||||||||
| 74 | categ => $categ, | ||||||||||||||||||||||||||
| 75 | discid => $discid, | ||||||||||||||||||||||||||
| 76 | dtitle => $dtitle, | ||||||||||||||||||||||||||
| 77 | })); | ||||||||||||||||||||||||||
| 78 | 0 | $self->setError (0); | |||||||||||||||||||||||||
| 79 | 0 | $self->setResult ('Found exact match'); | |||||||||||||||||||||||||
| 80 | } elsif ($code == 211) { | ||||||||||||||||||||||||||
| 81 | 0 | my @matches = (); | |||||||||||||||||||||||||
| 82 | 0 | ▶ | while (my $line = shift (@content_ref)) { | ||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||
| 83 | 0 | ▶ | $line eq '.' && last; | ||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||
| 84 | 0 | ▶ | $line =~ /^\s*.\s*$/ && last; | ||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||
| 85 | 0 | my ($categ, $discid, $dtitle) = $line =~ /$INEXACT_MATCH_RX/; | |||||||||||||||||||||||||
| 86 | 3 | ▶ | use Net::FreeDB2::Match; | ||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||
| 87 | 0 | push (@matches, Net::FreeDB2::Match->new ({ | |||||||||||||||||||||||||
| 88 | categ => $categ, | ||||||||||||||||||||||||||
| 89 | discid => $discid, | ||||||||||||||||||||||||||
| 90 | dtitle => $dtitle, | ||||||||||||||||||||||||||
| 91 | })); | ||||||||||||||||||||||||||
| 92 | } | ||||||||||||||||||||||||||
| 93 | 0 | $self->setMatches (@matches); | |||||||||||||||||||||||||
| 94 | 0 | $self->setError (0); | |||||||||||||||||||||||||
| 95 | 0 | $self->setResult ('Found inexact matches'); | |||||||||||||||||||||||||
| 96 | } elsif ($code == 202) { | ||||||||||||||||||||||||||
| 97 | 0 | $self->setMatches (); | |||||||||||||||||||||||||
| 98 | 0 | $self->setError (0); | |||||||||||||||||||||||||
| 99 | 0 | $self->setResult ('No match found'); | |||||||||||||||||||||||||
| 100 | } elsif ($code == 403) { | ||||||||||||||||||||||||||
| 101 | 0 | $self->setError (1); | |||||||||||||||||||||||||
| 102 | 0 | $self->setResult ('Database entry is corrupt'); | |||||||||||||||||||||||||
| 103 | } elsif ($code == 409) { | ||||||||||||||||||||||||||
| 104 | 0 | $self->setError (1); | |||||||||||||||||||||||||
| 105 | 0 | $self->setResult ('No handshake'); | |||||||||||||||||||||||||
| 106 | } else { | ||||||||||||||||||||||||||
| 107 | 0 | throw Error::Simple ("ERROR: Net::FreeDB2::Response::Query::read, unknown code '$code' returned."); | |||||||||||||||||||||||||
| 108 | } | ||||||||||||||||||||||||||
| 109 | } | ||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||
| 111 | 0 | ▶ | sub setMatches { | ||||||||||||||||||||||||
|
Subroutine
setMatches: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||
| 112 | 0 | my $self = shift; | |||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||
| 114 | 0 | @{$self->{Net_FreeDB2_Response_Query}{matches}} = @_; | |||||||||||||||||||||||||
| 115 | } | ||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||
| 117 | 0 | ▶ | sub pushMatches { | ||||||||||||||||||||||||
|
Subroutine
pushMatches: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||
| 118 | 0 | my $self = shift; | |||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||
| 120 | 0 | push (@{$self->{Net_FreeDB2_Response_Query}{matches}}, @_); | |||||||||||||||||||||||||
| 121 | } | ||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||
| 123 | 0 | ▶ | sub getMatches { | ||||||||||||||||||||||||
|
Subroutine
getMatches: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||
| 124 | 0 | my $self = shift; | |||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||
| 126 | 0 | return (@{$self->{Net_FreeDB2_Response_Query}{matches}}); | |||||||||||||||||||||||||
| 127 | } | ||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||
| 129 | 3 | 1; | |||||||||||||||||||||||||
| 130 | __END__ | ||||||||||||||||||||||||||