| line | stmt | bran | cond | sub | pod | time | code | 
| 1 |  |  |  |  |  |  | package WebService::Audioscrobbler::Track; | 
| 2 | 1 |  |  | 1 |  | 5 | use warnings; | 
|  | 1 |  |  |  |  | 2 |  | 
|  | 1 |  |  |  |  | 44 |  | 
| 3 | 1 |  |  | 1 |  | 5 | use strict; | 
|  | 1 |  |  |  |  | 2 |  | 
|  | 1 |  |  |  |  | 19 |  | 
| 4 | 1 |  |  | 1 |  | 4 | use CLASS; | 
|  | 1 |  |  |  |  | 2 |  | 
|  | 1 |  |  |  |  | 4 |  | 
| 5 |  |  |  |  |  |  |  | 
| 6 | 1 |  |  | 1 |  | 33 | use base 'WebService::Audioscrobbler::Base'; | 
|  | 1 |  |  |  |  | 2 |  | 
|  | 1 |  |  |  |  | 353 |  | 
| 7 |  |  |  |  |  |  |  | 
| 8 |  |  |  |  |  |  | =head1 NAME | 
| 9 |  |  |  |  |  |  |  | 
| 10 |  |  |  |  |  |  | WebService::Audioscrobbler::Track - An object-oriented interface to the Audioscrobbler WebService API | 
| 11 |  |  |  |  |  |  |  | 
| 12 |  |  |  |  |  |  | =cut | 
| 13 |  |  |  |  |  |  |  | 
| 14 |  |  |  |  |  |  | our $VERSION = '0.08'; | 
| 15 |  |  |  |  |  |  |  | 
| 16 |  |  |  |  |  |  | # postfix related accessors | 
| 17 |  |  |  |  |  |  | CLASS->mk_classaccessor("base_resource_path"  => "track"); | 
| 18 |  |  |  |  |  |  |  | 
| 19 |  |  |  |  |  |  | # requiring stuff | 
| 20 |  |  |  |  |  |  | CLASS->tags_class->require or die($@); | 
| 21 |  |  |  |  |  |  |  | 
| 22 |  |  |  |  |  |  | # object accessors | 
| 23 |  |  |  |  |  |  | CLASS->mk_accessors(qw/artist name mbid url streamable/); | 
| 24 |  |  |  |  |  |  |  | 
| 25 |  |  |  |  |  |  | *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. | 
| 49 |  |  |  |  |  |  |  | 
| 50 |  |  |  |  |  |  | =head1 FIELDS | 
| 51 |  |  |  |  |  |  |  | 
| 52 |  |  |  |  |  |  | =head2 C | 
| 53 |  |  |  |  |  |  |  | 
| 54 |  |  |  |  |  |  | The track's performing artist. | 
| 55 |  |  |  |  |  |  |  | 
| 56 |  |  |  |  |  |  | =head2 C | 
| 57 |  |  |  |  |  |  | =head2 C | 
| 58 |  |  |  |  |  |  |  | 
| 59 |  |  |  |  |  |  | The name (title) of a given track. | 
| 60 |  |  |  |  |  |  |  | 
| 61 |  |  |  |  |  |  | =head2 C | 
| 62 |  |  |  |  |  |  |  | 
| 63 |  |  |  |  |  |  | MusicBrainz ID as provided by the Audioscrobbler database. | 
| 64 |  |  |  |  |  |  |  | 
| 65 |  |  |  |  |  |  | =head2 C | 
| 66 |  |  |  |  |  |  |  | 
| 67 |  |  |  |  |  |  | URL for aditional info about the track. | 
| 68 |  |  |  |  |  |  |  | 
| 69 |  |  |  |  |  |  | =cut | 
| 70 |  |  |  |  |  |  |  | 
| 71 |  |  |  |  |  |  | =head1 METHODS | 
| 72 |  |  |  |  |  |  |  | 
| 73 |  |  |  |  |  |  | =cut | 
| 74 |  |  |  |  |  |  |  | 
| 75 |  |  |  |  |  |  | =head2 C | 
| 76 |  |  |  |  |  |  |  | 
| 77 |  |  |  |  |  |  | =head2 C | 
| 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 |  |  | 0 | 1 |  | my $class = shift; | 
| 87 | 0 |  |  |  |  |  | my ($artist_or_fields, $title, $data_fetcher) = @_; | 
| 88 |  |  |  |  |  |  |  | 
| 89 | 0 | 0 |  |  |  |  | my $self = $class->SUPER::new( | 
| 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 | 0 |  |  |  |  | $class->croak("No data fetcher provided") | 
| 95 |  |  |  |  |  |  | unless $self->data_fetcher; | 
| 96 |  |  |  |  |  |  |  | 
| 97 | 0 |  |  |  |  |  | return $self; | 
| 98 |  |  |  |  |  |  | } | 
| 99 |  |  |  |  |  |  |  | 
| 100 |  |  |  |  |  |  | =head2 C | 
| 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 objects by default. | 
| 107 |  |  |  |  |  |  |  | 
| 108 |  |  |  |  |  |  | =cut | 
| 109 |  |  |  |  |  |  |  | 
| 110 |  |  |  |  |  |  | sub tracks { | 
| 111 | 0 |  |  | 0 | 1 |  | shift->croak("Audioscrobbler doesn't provide data regarding tracks which are related to other tracks"); | 
| 112 |  |  |  |  |  |  | } | 
| 113 |  |  |  |  |  |  |  | 
| 114 |  |  |  |  |  |  | sub artists { | 
| 115 | 0 |  |  | 0 | 1 |  | shift->croak("Audioscrobbler doesn't provide data regarding artists related to specific tracks"); | 
| 116 |  |  |  |  |  |  | } | 
| 117 |  |  |  |  |  |  |  | 
| 118 |  |  |  |  |  |  | =head2 C | 
| 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 |  |  | 0 | 1 |  | my $self = shift; | 
| 127 | 0 |  |  |  |  |  | $self->uri_builder( $self->artist->name, $self->name ); | 
| 128 |  |  |  |  |  |  | } | 
| 129 |  |  |  |  |  |  |  | 
| 130 |  |  |  |  |  |  | =head1 AUTHOR | 
| 131 |  |  |  |  |  |  |  | 
| 132 |  |  |  |  |  |  | Nilson Santos Figueiredo Junior, C<<  >> | 
| 133 |  |  |  |  |  |  |  | 
| 134 |  |  |  |  |  |  | =head1 COPYRIGHT & LICENSE | 
| 135 |  |  |  |  |  |  |  | 
| 136 |  |  |  |  |  |  | Copyright 2006-2007 Nilson Santos Figueiredo Junior, 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 |  |  |  |  |  |  | 1; # End of WebService::Audioscrobbler::Track |