LinkEmbedder/Link/Spotify.pm untested

filter: Statementstmt 0.0% 0 / 23 Branchbran 0.0% 0 / 6 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 2 Podpod 0.0% 0 / 1 totaltotal 0.0% 0 / 32 CC 4 SCAR 28.0
CC
4
Cov
0%
learn_p
20.0
BEGIN
2.0
CRAP 16.4
1 package LinkEmbedder::Link::Spotify;
2 use Mojo::Base 'LinkEmbedder::Link';
3  
4 has provider_name => 'Spotify';
5 has provider_url => sub { Mojo::URL->new('https://spotify.com') };
6 has theme => 'white';
7 has view => ''; # list, coverart
8  
9 sub learn_p {
10 my $self = shift;
11 my $url = $self->url;
12 my ($iframe_src, @path);
13  
14 if ($url =~ s!^spotify:!!) { # spotify:track:5tv77MoS0TzE0sJ7RwTj34
15 @path = split /:/, $url;
16 }
17 elsif (@{$url->path} == 2) { # https://open.spotify.com/artist/6VKNnZIuu9YEOvLgxR6uhQ
18 @path = @{$url->path};
19 }
20  
21 return $self->SUPER::learn_p unless @path;
22  
23 $iframe_src = Mojo::URL->new('https://embed.spotify.com');
24 $iframe_src->query(theme => $self->theme, uri => join(':', spotify => @path), view => $self->view);
25 $self->{iframe_src} = $iframe_src;
26 $self->template->[1] = 'iframe.html.ep';
27 $self->type('rich');
28  
29 return Mojo::Promise->new->resolve($self);
30 }
31  
32 1;