Audioscrobbler/Track.pm

filter: Statementstmt 66.6% 18 / 27 Branchbran 16.6% 1 / 6 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 50.0% 4 / 8 Podpod 100% 4 / 4 totaltotal 60.0% 27 / 45 CC 3 SCAR 15.3
CC
3
Cov
58%
new
12.0
tracks
2.0
artists
2.0
CRAP 4.6
« Audioscrobbler/Tag.pm ↑ Summary Audioscrobbler.pm »
1 package WebService::Audioscrobbler::Track;
2 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use CLASS;
Subroutine BEGIN: called CC=1 SCAR=0.0
5
6 2 ▶use base 'WebService::Audioscrobbler::Base';
Subroutine BEGIN: called CC=1 SCAR=0.0
7
8 =head1 NAME
9
10 WebService::Audioscrobbler::Track - An object-oriented interface to the Audioscrobbler WebService API
11
12 =cut
13
14 2 our $VERSION = '0.07';
15
16 # postfix related accessors
17 2 CLASS->mk_classaccessor("base_resource_path" => "track");
18
19 # requiring stuff
20 2 ▶CLASS->tags_class->require or die($@);
Branch: 1 branch
BranchTrueFalseTotal
&CLASS()->tags_class->require or die $@ 0 2 2
21
22 # object accessors
23 2 CLASS->mk_accessors(qw/artist name mbid url streamable/);
24
25 2 *title = \&name;
26
27 =head1 SYNOPSIS
28
29 This module implements an object oriented abstraction of a track within the
30 Audioscrobbler database.
31
32 use WebService::Audioscrobbler::Track;
33
34 my $ws = WebService::Audioscrobbler->new;
35
36 # get a track object for the track titled 'bar' by 'foo'
37 my $track = $ws->track('foo', 'bar');
38
39 # retrieves the track's tags
40 my @tags = $track->tags;
41
42 # prints url for viewing aditional tag info
43 print $track->url;
44
45 # prints the tag's artist name
46 print $track->artist->name;
47
48 This module inherits from L<WebService::Audioscrobbler::Base>.
49
50 =head1 FIELDS
51
52 =head2 C<artist>
53
54 The track's performing artist.
55
56 =head2 C<name>
57 =head2 C<title>
58
59 The name (title) of a given track.
60
61 =head2 C<mbid>
62
63 MusicBrainz ID as provided by the Audioscrobbler database.
64
65 =head2 C<url>
66
67 URL for aditional info about the track.
68
69 =cut
70
71 =head1 METHODS
72
73 =cut
74
75 =head2 C<new($artist, $title, $data_fetcher)>
76
77 =head2 C<new(\%fields)>
78
79 Creates a new object using either the given C<$artist> and C<$title> or the
80 C<\%fields> hashref. The data fetcher object is a mandatory parameter and must
81 be provided either as the second parameter or inside the C<\%fields> hashref.
82
83 =cut
84
85 sub new {
86 0 ▶ my $class = shift;
Subroutine new: not called CC=3 SCAR=24.8
Pod documented
87 0 my ($artist_or_fields, $title, $data_fetcher) = @_;
88
89 0 ▶ my $self = $class->SUPER::new(
Branch: 1 branch
BranchTrueFalseTotal
ref $artist_or_fields eq 'HASH' ? : 0 0 0
90 ref $artist_or_fields eq 'HASH' ?
91 $artist_or_fields : { artist => $artist_or_fields, name => $title, data_fetcher => $data_fetcher }
92 );
93
94 0 ▶ $class->croak("No data fetcher provided")
Branch: 1 branch
BranchTrueFalseTotal
unless $self->data_fetcher 0 0 0
95 unless $self->data_fetcher;
96
97 0 return $self;
98 }
99
100 =head2 C<tags>
101
102 Retrieves the track's top tags as available on Audioscrobbler's database.
103
104 Returns either a list of tags or a reference to an array of tags when called
105 in list context or scalar context, respectively. The tags are returned as
106 L<WebService::Audioscrobbler::Tag> objects by default.
107
108 =cut
109
110 sub tracks {
111 0 ▶ shift->croak("Audioscrobbler doesn't provide data regarding tracks which are related to other tracks");
Subroutine tracks: not called CC=1 SCAR=6.9
Pod documented
112 }
113
114 sub artists {
115 0 ▶ shift->croak("Audioscrobbler doesn't provide data regarding artists related to specific tracks");
Subroutine artists: not called CC=1 SCAR=6.9
Pod documented
116 }
117
118 =head2 C<resource_path>
119
120 Returns the URL from which other URLs used for fetching track info will be
121 derived from.
122
123 =cut
124
125 sub resource_path {
126 0 ▶ my $self = shift;
Subroutine resource_path: not called CC=1 SCAR=6.9
Pod documented
127 0 $self->uri_builder( $self->artist->name, $self->name );
128 }
129
130 =head1 AUTHOR
131
132 Nilson Santos Figueiredo Júnior, C<< <nilsonsfj at cpan.org> >>
133
134 =head1 COPYRIGHT & LICENSE
135
136 Copyright 2006-2007 Nilson Santos Figueiredo Júnior, all rights reserved.
137
138 This program is free software; you can redistribute it and/or modify it
139 under the same terms as Perl itself.
140
141 =cut
142
143 2 1; # End of WebService::Audioscrobbler::Track
« Audioscrobbler/Tag.pm ↑ Summary Audioscrobbler.pm »