blib/lib/WebService/MusixMatch.pm

filter: Statementstmt 76.2% 45 / 59 Branchbran 0.0% 0 / 2 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 80.0% 12 / 15 Podpod 0.0% 0 / 1 totaltotal 74.0% 57 / 77 CC 2 SCAR 5.6
CC
2
Cov
74%
request
6.0
__ANON__
2.0
__ANON__
2.0
CRAP 1.8
↑ Summary
1 package WebService::MusixMatch;
2 2 ▶use JSON::XS;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 2 ▶use Cache::LRU;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use Net::DNS::Lite;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 2 ▶use Furl;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 2 ▶use URI;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 2 ▶use URI::QueryParam;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 2 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 2 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 2 ▶use namespace::clean;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 2 our $VERSION = "0.06";
12  
13  
14 2 $Net::DNS::Lite::CACHE = Cache::LRU->new( size => 512 );
15  
16 has 'api_key' => (
17 is => 'rw',
18 1 ▶ isa => sub { $_[0] },
Subroutine __ANON__: called CC=1 SCAR=0.0
19 required => 1,
20 0 ▶ default => sub { $ENV{MUSIXMATCH_API_KEY} },
Subroutine __ANON__: not called CC=1 SCAR=6.9
21 2 );
22  
23 has 'http' => (
24 is => 'rw',
25 required => 1,
26 1 ▶ default => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
27 1 my $http = Furl::HTTP->new(
28 inet_aton => \&Net::DNS::Lite::inet_aton,
29 agent => 'WebService::MusixMatch/' . $VERSION,
30 headers => [ 'Accept-Encoding' => 'gzip',],
31 );
32 1 return $http;
33 },
34 2 );
35  
36  
37 2 my @methods = (
38 'chart.artists.get',
39 'chart.tracks.get',
40 'track.search',
41 'track.get',
42 'track.subtitle.get',
43 'track.lyrics.get',
44 'track.snippet.get',
45 'track.lyrics.post',
46 'track.lyrics.feedback.post',
47 'matcher.lyrics.get',
48 'matcher.track.get',
49 'matcher.subtitle.get',
50 'artist.get',
51 'artist.search',
52 'artist.albums.get',
53 'artist.related.get',
54 'album.get',
55 'album.tracks.get',
56 'tracking.url.get',
57 'catalogue.dump.get',
58 );
59  
60  
61 2 for my $method (@methods) {
62 0 ▶ my $code = sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
63 0 my ($self, %query_param) = @_;
64 0 return $self->request($method, \%query_param);
65 40 };
66 2 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
67 40 my $method_name = $method;
68 40 $method_name =~ s|\.|_|g;
69 40 *{$method_name} = $code;
70 }
71  
72  
73 0 ▶sub request {
Subroutine request: not called CC=2 SCAR=17.9
Pod undocumented
74 0 my ( $self, $path, $query_param ) = @_;
75  
76 0 my $query = URI->new;
77 0 $query->query_param( 'apikey', $self->api_key );
78 0 $query->query_param( 'format', 'json' );
79 0 map { $query->query_param( $_, $query_param->{$_} ) } keys %$query_param;
80  
81 0 my ($minor_version, $status_code, $message, $headers, $content) =
82 $self->http->request(
83 scheme => 'http',
84 host => 'api.musixmatch.com',
85 path_query => "ws/1.1/$path$query",
86 method => 'GET',
87 );
88  
89 0 my $data = decode_json( $content );
90 0 ▶ if ( $data->{message}{header}{status_code} != 200 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($data->{'message'}{'header'}{'status_code'} != 200) { } 0 0 0
91 0 confess $data->{message}{header}{status_code};
92 } else {
93 0 return $data;
94 }
95 }
96  
97  
98 2 1;
99 __END__
↑ Summary