Admin/Song.pm

filter: Statementstmt 42.4% 14 / 33 Branchbran 0.0% 0 / 4 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 57.1% 4 / 7 Podpod 100% 3 / 3 totaltotal 44.6% 21 / 47 CC 4 SCAR 21.7
CC
4
Cov
38%
new
20.0
title
2.0
played_at
2.0
CRAP 8.8
« Admin.pm ↑ Summary Admin/Listener.pm »
1 package Net::Shoutcast::Admin::Song;
2 # $Id: Song.pm 315 2008-03-19 00:07:39Z davidp $
3  
4 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 3 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 3 ▶use vars qw($VERSION);
Subroutine BEGIN: called CC=1 SCAR=0.0
9 3 $VERSION = '0.02';
10  
11  
12 =head1 NAME
13  
14 Net::Shoutcast::Admin::Song - object to represent a song
15  
16  
17 =head1 DESCRIPTION
18  
19 An object representing a song (either the current song, or an entry in the
20 song history). Barely justifies being an object rather than a hashref
21 at the moment, but at some point I may be able to add other useful methods,
22 perhaps $song->lyrics to attempt to fetch lyrics.
23  
24  
25 =head1 SYNOPSIS
26  
27 use Net::Shoutcast::Admin;
28  
29 my $shoutcast = Net::Shoutcast::Admin->new(
30 host => 'server hostname',
31 port => 8000,
32 admin_password => 'mypassword',
33 );
34
35 if ($shoutcast->source_connected) {
36 my $song = $shoutcast->current_song;
37
38 print "Current song is: " . $song->title;
39 } else {
40 print "No source is currently connected.";
41 }
42
43
44 =head1 DESCRIPTION
45  
46 Object representing a song, returned by Net::Shoutcast::Admin
47  
48  
49 =head1 INTERFACE
50  
51 =over 4
52  
53 =item new
54  
55 There's no reason to create instances of Net::Shoutcast::Admin::Song directly;
56 Net::Shoutcast::Admin creates and returns instances for you.
57  
58 Having said that:
59  
60 $song = Net::Shoutcast::Admin::Song->new( %params );
61  
62 Creates a new Net::Shoutcast::Admin object. Takes a hash of options
63 as follows:
64  
65 =over 4
66  
67 =item I<title>
68  
69 The title of the song
70  
71 =item I<played_at>
72  
73 The timestamp this song started playing.
74  
75 =back
76  
77 =cut
78  
79 0 ▶sub new {
Subroutine new: not called CC=4 SCAR=30.0
Pod documented
80  
81 0 my ($class, %params) = @_;
82
83 0 my $self = bless {}, $class;
84
85 0 $self->{last_update} = 0;
86
87 0 my %acceptable_params = map { $_ => 1 }
88 qw(title played_at);
89 0 my %required_params = map { $_ => 1 }
90 qw(title);
91
92
93 # make sure we haven't been given any bogus parameters:
94 0 ▶ if (my @bad_params = grep { ! $acceptable_params{$_} } keys %params) {
Branch: 1 branch
BranchTrueFalseTotal
if (my(@bad_params) = grep({not $acceptable_params{$_};} keys %params)) 0 0 0
95 0 carp "Net::Shoutcast::Admin::Song does not recognise param(s) "
96 . join ',', @bad_params;
97 0 return;
98 }
99
100 0 $self->{$_} = $params{$_} for keys %acceptable_params;
101
102 0 ▶ if (my @missing_params = grep { ! $self->{$_} } keys %required_params) {
Branch: 1 branch
BranchTrueFalseTotal
if (my(@missing_params) = grep({not $self->{$_};} keys %required_params)) 0 0 0
103 0 carp "Net::Shoutcast::Admin->new() must be supplied with params: "
104 . join ',', @missing_params;
105 0 return;
106 }
107
108 0 return $self;
109  
110 }
111  
112  
113 =item title
114  
115 Returns the artist
116  
117 =cut
118  
119 0 ▶sub title {
Subroutine title: not called CC=1 SCAR=6.9
Pod documented
120 0 return shift->{title};
121 }
122  
123 0 ▶sub played_at {
Subroutine played_at: not called CC=1 SCAR=6.9
Pod documented
124 0 return shift->{played_at};
125 }
126  
127  
128  
129 3 1; # Magic true value required at end of module
130 __END__
« Admin.pm ↑ Summary Admin/Listener.pm »