blib/lib/Bot/BasicBot/Pluggable/Module/Spotify.pm

filter: Statementstmt 48.7% 19 / 39 Branchbran 0.0% 0 / 14 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 62.5% 5 / 8 Podpod 100% 3 / 3 totaltotal 42.1% 27 / 64 CC 9 SCAR 30.5
CC
9
Cov
36%
parse_spotify_uris
42.0
said
20.0
help
2.0
CRAP 21.2
↑ Summary
1 package Bot::BasicBot::Pluggable::Module::Spotify;
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  
6 2 ▶use Net::Spotify ();
Subroutine BEGIN: called CC=1 SCAR=0.0
7 2 ▶use XML::TreePP ();
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 2 ▶use base 'Bot::BasicBot::Pluggable::Module::Base';
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 2 our $VERSION = '0.01';
12  
13 2 my $spotify = Net::Spotify->new();
14 2 my $tpp = XML::TreePP->new();
15  
16 0 ▶sub help {
Subroutine help: not called CC=1 SCAR=6.9
Pod documented
17 0 return 'Will parse those cryptic Spotify URIs showing the interesting information :)';
18 }
19  
20 0 ▶sub said {
Subroutine said: not called CC=4 SCAR=30.0
Pod documented
21 0 my ($self, $mess, $pri) = @_;
22  
23 0 ▶ return unless $pri == 2;
Branch: 1 branch
BranchTrueFalseTotal
unless $pri == 2 0 0 0
24  
25 0 my @data = $self->parse_spotify_uris($mess->{body});
26  
27 0 ▶ if (! scalar @data) {
Branch: 1 branch
BranchTrueFalseTotal
unless (scalar @data) 0 0 0
28 0 return;
29 }
30  
31 0 foreach my $info (@data) {
32 0 $self->tell($mess->{channel}, $info)
33 }
34  
35 0 return;
36 }
37  
38 0 ▶sub parse_spotify_uris {
Subroutine parse_spotify_uris: not called CC=6 SCAR=37.4
Pod documented
39 0 my ($self, $text) = @_;
40  
41 0 my @data = ();
42  
43 0 ▶ while ($text =~ m{ \b (spotify:(artist|album|track):\w+) \b }gmx) {
Branch: 1 branch
BranchTrueFalseTotal
if ($text =~ / \b (spotify:(artist|album|track):\w+) \b /gmx) 0 0 0
44 0 my ($uri, $type) = ($1, $2);
45  
46 0 my $xml = $spotify->lookup(uri => $uri);
47  
48 0 ▶ if (my $tree = $tpp->parse($xml)) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $tree = $tpp->parse($xml)) 0 0 0
49 0 ▶ if ($type eq 'artist') {
Branch: 3 branches
BranchTrueFalseTotal
if ($type eq 'artist') { } 0 0 0
elsif ($type eq 'album') { } 0 0 0
elsif ($type eq 'track') { } 0 0 0
50 push @data, sprintf(
51 '%s -> Artist: %s',
52 $uri,
53 $tree->{artist}->{name},
54 0 );
55 }
56 elsif ($type eq 'album') {
57 push @data, sprintf(
58 '%s -> Album: %s, Artist: %s, Year: %s',
59 $uri,
60 $tree->{album}->{name}, $tree->{album}->{artist}->{name},
61 $tree->{album}->{released}
62 0 );
63 }
64 elsif ($type eq 'track') {
65 push @data, sprintf(
66 '%s -> Track: %s, Album: %s, Artist: %s',
67 $uri,
68 $tree->{track}->{name},
69 $tree->{track}->{album}->{name},
70 $tree->{track}->{artist}->{name},
71 0 );
72 }
73 }
74 }
75  
76 0 return @data;
77 }
78  
79 2 1;
80  
81 __END__
↑ Summary