Audioscrobbler/Tag.pm

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