File Coverage

blib/lib/Music/KNRadio/NowPlaying.pm
Criterion Covered Total %
statement 21 37 56.7
branch 0 6 0.0
condition n/a
subroutine 7 8 87.5
pod 1 1 100.0
total 29 52 55.7


line stmt bran cond sub pod time code
1             package Music::KNRadio::NowPlaying;
2 1     1   55938 use strict;
  1         2  
  1         37  
3 1     1   4 use warnings;
  1         2  
  1         24  
4 1     1   447 use open qw(:utf8 :std);
  1         1328  
  1         4  
5              
6             BEGIN {
7 1     1   105 use Exporter;
  1         2  
  1         34  
8 1     1   4 use vars qw($VERSION @ISA @EXPORT_OK %EXPORT_TAGS);
  1         2  
  1         67  
9 1     1   16 @ISA = qw(Exporter);
10              
11 1         3 $VERSION = '0.008';
12 1         19 @EXPORT_OK = qw(knnp);
13             }
14              
15              
16              
17 1     1   373 use LWP::Simple;
  1         56081  
  1         7  
18              
19             my $url = 'http://www.knradio.se/latlist/exfile.php';
20              
21             sub knnp {
22 0     0 1   my @content = split(/\n/, get($url));
23 0           my %now_playing = (
24             artist => 'undef',
25             title => 'undef',
26             state => 'undef',
27             );
28              
29 0           for my $line(reverse(@content)) {
30 0 0         if($line =~ m/Spelas just nu:(.+)/) {
31 0 0         unless($1) {
32 0           $now_playing{state} = 'paused';
33 0           last;
34             }
35 0           ($now_playing{artist}, $now_playing{title}) = $1 =~ m/(.+) - (.+)/;
36              
37 0 0         last unless defined $now_playing{artist};
38 0           $now_playing{artist} =~ s/[^[:ascii:]]//g;
39 0           $now_playing{title} =~ s/[^[:ascii:]]//g;
40 0           $now_playing{title} =~ s/\r//g;
41              
42 0           $now_playing{state} = 'playing';
43 0           last;
44             }
45             else {
46 0           $now_playing{state} = 'paused';
47             }
48             }
49 0           return \%now_playing;
50             }
51              
52              
53              
54             1;
55              
56             __END__