| 1 | package Dancer::Plugin::MPD; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 2 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 2 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 2 | ▶ | use Dancer::Plugin; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | 2 | ▶ | use Audio::MPD; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | 2 | our $VERSION = '0.03'; | |||||||||||||||||||||||||||
| 9 | 2 | my $mpd; | |||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | 0 | ▶ | register mpd => sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | 0 | ▶ | if ($mpd && $mpd->ping) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$mpd and $mpd->ping
MC/DC0%0/2
$mpd and $mpd->ping
$mpd
$mpd->ping
Truth table0%0/3
A and B
A= $mpdB= $mpd->ping
| |||||||||||||||||||||||||||||
| 14 | 0 | return $mpd; | |||||||||||||||||||||||||||
| 15 | } else { | ||||||||||||||||||||||||||||
| 16 | 0 | return $mpd = _connect(); | |||||||||||||||||||||||||||
| 17 | } | ||||||||||||||||||||||||||||
| 18 | 2 | }; | |||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||
| 20 | 0 | ▶ | sub _connect { | ||||||||||||||||||||||||||
|
Subroutine
_connect: not called CC=4 SCAR=30.0
| |||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||
| 22 | 0 | my $conf = plugin_setting; | |||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||
| 24 | # Only pass settings to Audio::MPD if they're specified in the config; | ||||||||||||||||||||||||||||
| 25 | # Audio::MPD does sensible things by default, so in the majority of cases | ||||||||||||||||||||||||||||
| 26 | # (MPD listening on localhost, on port 6600, with no password set), no | ||||||||||||||||||||||||||||
| 27 | # configuration will be needed at all. | ||||||||||||||||||||||||||||
| 28 | 0 | my %mpd_conf; | |||||||||||||||||||||||||||
| 29 | 0 | for my $setting (qw(host port password conntype)) { | |||||||||||||||||||||||||||
| 30 | 0 | ▶ | $mpd_conf{$setting} = $conf->{$setting} if exists $conf->{$setting}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 31 | } | ||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||
| 33 | # Audio::MPD's default conntype is 'once', which re-establishes a connection | ||||||||||||||||||||||||||||
| 34 | # for every request. For performance, we probably want to re-use a | ||||||||||||||||||||||||||||
| 35 | # connection. | ||||||||||||||||||||||||||||
| 36 | 0 | ▶ | $mpd_conf{conntype} ||= 'reuse'; | ||||||||||||||||||||||||||
|
Condition0%0/2
$mpd_conf{"conntype"} ||= "reuse"
MC/DC0%0/1
$mpd_conf{"conntype"} ||= "reuse"
$mpd_conf{"conntype"}
Truth table0%0/2
A
A= $mpd_conf{"conntype"}
| |||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||
| 38 | 0 | my $mpd = Audio::MPD->new(\%mpd_conf); | |||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||
| 40 | 0 | Dancer::Factory::Hook->instance->execute_hooks('mpd_connected', $mpd); | |||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||
| 42 | 0 | return $mpd; | |||||||||||||||||||||||||||
| 43 | } | ||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||
| 46 | 2 | Dancer::Factory::Hook->instance->install_hooks(qw(mpd_connected)); | |||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||
| 48 | 2 | register_plugin; | |||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||
| 50 | =head1 NAME | ||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||
| 52 | Dancer::Plugin::MPD - easy connection to MPD from Dancer apps | ||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||
| 54 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||
| 56 | Provides an easy way to connect to MPD (L<www.musicpd.org>) from a L<Dancer> | ||||||||||||||||||||||||||||
| 57 | app. Handles obtaining the connection, making sure the connection is still | ||||||||||||||||||||||||||||
| 58 | alive, and reconnecting if not. | ||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||
| 62 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||
| 64 | In your L<Dancer> app, calling the C<mpd> keyword will get you an MPD | ||||||||||||||||||||||||||||
| 65 | connection. | ||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||
| 67 | use Dancer::Plugin::MPD; | ||||||||||||||||||||||||||||
| 68 | my $current_song = mpd->current; | ||||||||||||||||||||||||||||
| 69 | mpd->next; | ||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||
| 72 | =head1 CONFIGURATION | ||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||
| 74 | L<Audio::MPD> does sensible things by default, so in the majority of cases (MPD | ||||||||||||||||||||||||||||
| 75 | running on the same host as the app, no password needed, and happy to reuse the | ||||||||||||||||||||||||||||
| 76 | connection for performance), no configuration will be required at all. | ||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||
| 78 | However, the following config settings can be used in your app's C<config.yml>: | ||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||
| 80 | plugins: | ||||||||||||||||||||||||||||
| 81 | MPD: | ||||||||||||||||||||||||||||
| 82 | host: localhost | ||||||||||||||||||||||||||||
| 83 | port: 6600 | ||||||||||||||||||||||||||||
| 84 | password: verysecret | ||||||||||||||||||||||||||||
| 85 | conntype: reuse | ||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||
| 88 | =head1 HOOKS | ||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||
| 90 | =over 4 | ||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||
| 92 | =item * C<mpd_connected> | ||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||
| 94 | Called when a connection is established, and receives the L<Audio::MPD> object | ||||||||||||||||||||||||||||
| 95 | as its parameter. | ||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||
| 97 | hook 'mpd_connected' => sub { | ||||||||||||||||||||||||||||
| 98 | my $mpd = shift; | ||||||||||||||||||||||||||||
| 99 | $mpd->repeat(1); | ||||||||||||||||||||||||||||
| 100 | $mpd->random(1); | ||||||||||||||||||||||||||||
| 101 | $mpd->play; | ||||||||||||||||||||||||||||
| 102 | }; | ||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||
| 104 | =back | ||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||
| 106 | =head1 AUTHOR | ||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||
| 108 | David Precious, C<< <davidp at preshweb.co.uk> >> | ||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||
| 110 | =head1 ACKNOWLEDGEMENTS | ||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||
| 112 | Alan Berndt | ||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||
| 115 | =head1 BUGS | ||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||
| 117 | Please report any bugs or feature requests to C<bug-dancer-plugin-mpd at rt.cpan.org>, or through | ||||||||||||||||||||||||||||
| 118 | the web interface at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Dancer-Plugin-MPD>. I will be notified, and then you'll | ||||||||||||||||||||||||||||
| 119 | automatically be notified of progress on your bug as I make changes. | ||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||
| 124 | =head1 SUPPORT | ||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||
| 126 | You can find documentation for this module with the perldoc command. | ||||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||
| 128 | perldoc Dancer::Plugin::MPD | ||||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||
| 131 | You can also look for information at: | ||||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||
| 133 | =over 4 | ||||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||
| 135 | =item * RT: CPAN's request tracker | ||||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||
| 137 | L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=Dancer-Plugin-MPD> | ||||||||||||||||||||||||||||
| 138 | |||||||||||||||||||||||||||||
| 139 | =item * AnnoCPAN: Annotated CPAN documentation | ||||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||
| 141 | L<http://annocpan.org/dist/Dancer-Plugin-MPD> | ||||||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||||
| 143 | =item * CPAN Ratings | ||||||||||||||||||||||||||||
| 144 | |||||||||||||||||||||||||||||
| 145 | L<http://cpanratings.perl.org/d/Dancer-Plugin-MPD> | ||||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||
| 147 | =item * Search CPAN | ||||||||||||||||||||||||||||
| 148 | |||||||||||||||||||||||||||||
| 149 | L<http://search.cpan.org/dist/Dancer-Plugin-MPD/> | ||||||||||||||||||||||||||||
| 150 | |||||||||||||||||||||||||||||
| 151 | =back | ||||||||||||||||||||||||||||
| 152 | |||||||||||||||||||||||||||||
| 153 | |||||||||||||||||||||||||||||
| 154 | |||||||||||||||||||||||||||||
| 155 | =head1 LICENSE AND COPYRIGHT | ||||||||||||||||||||||||||||
| 156 | |||||||||||||||||||||||||||||
| 157 | Copyright 2010-12 David Precious. | ||||||||||||||||||||||||||||
| 158 | |||||||||||||||||||||||||||||
| 159 | This program is free software; you can redistribute it and/or modify it | ||||||||||||||||||||||||||||
| 160 | under the terms of either: the GNU General Public License as published | ||||||||||||||||||||||||||||
| 161 | by the Free Software Foundation; or the Artistic License. | ||||||||||||||||||||||||||||
| 162 | |||||||||||||||||||||||||||||
| 163 | See http://dev.perl.org/licenses/ for more information. | ||||||||||||||||||||||||||||
| 164 | |||||||||||||||||||||||||||||
| 165 | |||||||||||||||||||||||||||||
| 166 | =cut | ||||||||||||||||||||||||||||
| 167 | |||||||||||||||||||||||||||||
| 168 | 2 | 1; # End of Dancer::Plugin::MPD | |||||||||||||||||||||||||||