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

filter: Statementstmt 44.4% 28 / 63 Branchbran 0.0% 0 / 16 Conditioncond 0.0% 0 / 7 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 54.5% 6 / 11 Podpod 100% 4 / 4 totaltotal 36.1% 38 / 105 CC 12 SCAR 34.9
CC
12
Cov
33%
read
73.9
_initialize
12.0
new
6.0
CRAP 32.8
« blib/lib/Net/FreeDB2.pm ↑ Summary blib/lib/Net/FreeDB2/Response/Sites.pm »
1 package Net::FreeDB2::Response::Read;
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::Read ':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  
39 0 ▶sub new {
Subroutine new: not called CC=2 SCAR=17.9
Pod documented
40 0 my $class = shift;
41  
42 0 my $self = {};
43 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
44 0 return ($self->_initialize (@_));
45 }
46  
47 0 ▶sub _initialize {
Subroutine _initialize: not called CC=3 SCAR=24.8
48 0 my $self = shift;
49 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
50  
51 0 ▶ defined ($opt->{content_ref}) and $self->read ($opt);
Branch: 1 branch
BranchTrueFalseTotal
defined $opt->{"content_ref"} and $self->read($opt) 0 0 0
52 0 return ($self);
53 }
54  
55 0 ▶sub read {
Subroutine read: not called CC=9 SCAR=43.0
Pod documented
56 0 my $self = shift;
57 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
58  
59 # Check if content_ref is specified
60 0 ▶ exists ($opt->{content_ref}) || throw Error::Simple ('ERROR: Net::FreeDB2::Response::Read::read, option \'content_ref\' not defined.');
Branch: 1 branch
BranchTrueFalseTotal
exists $opt->{"content_ref"} or "Error::Simple"->throw("ERROR: Net::FreeDB2::Response::Read::read, option 'content_ref' not defined.") 0 0 0
61  
62 # Convert $opt->{content_ref} to @content_ref
63 0 my @content_ref = split (/[\n\r]+/, ${$opt->{content_ref}});
64  
65 # Parse first line
66 0 my $line = shift (@content_ref);
67 0 my ($code) = $line =~ /$CODE_RX/;
68 0 ▶ defined ($code) || throw Error::Simple ('ERROR: Net::FreeDB2::Response::Read::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::Read::read, first line of specified 'content_ref' does not contain a code.") 0 0 0
69 0 ▶ if ($code == 210) {
Branch: 5 branches
BranchTrueFalseTotal
if ($code == 210) { } 0 0 0
elsif ($code == 401) { } 0 0 0
elsif ($code == 402) { } 0 0 0
elsif ($code == 403) { } 0 0 0
elsif ($code == 409) { } 0 0 0
70 0 my ($code, $categ, $discid, $dtitle) = $line =~ /$EXACT_MATCH_RX/;
71 3 ▶ use Net::FreeDB2::Match;
Subroutine BEGIN: called CC=1 SCAR=0.0
72 0 $self->setEntry (Net::FreeDB2::Entry->new ({
73 array_ref => \@content_ref,
74 }));
75 0 $self->setError (0);
76 0 $self->setResult ('OK');
77 } elsif ($code == 401) {
78 0 $self->setEntry ();
79 0 $self->setError (0);
80 0 $self->setResult ('Specified CDDB entry not found');
81 } elsif ($code == 402) {
82 0 $self->setError (1);
83 0 $self->setResult ('Server error');
84 } elsif ($code == 403) {
85 0 $self->setError (1);
86 0 $self->setResult ('Database entry is corrupt');
87 } elsif ($code == 409) {
88 0 $self->setError (1);
89 0 $self->setResult ('No handshake');
90 } else {
91 0 throw Error::Simple ("ERROR: Net::FreeDB2::Response::Read::read, unknown code '$code' returned.");
92 }
93 }
94  
95 0 ▶sub setEntry {
Subroutine setEntry: not called CC=1 SCAR=6.9
Pod documented
96 0 my $self = shift;
97  
98 0 $self->{Net_FreeDB2_Response_Read}{entry} = shift;
99 }
100  
101 0 ▶sub getEntry {
Subroutine getEntry: not called CC=1 SCAR=6.9
Pod documented
102 0 my $self = shift;
103  
104 0 return ($self->{Net_FreeDB2_Response_Read}{entry});
105 }
106  
107 3 1;
108 __END__
« blib/lib/Net/FreeDB2.pm ↑ Summary blib/lib/Net/FreeDB2/Response/Sites.pm »