lib/Net/Async/Spotify/Scope.pm

filter: Statementstmt 51.3% 19 / 37 Branchbran 0.0% 0 / 6 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 28.5% 4 / 14 Podpod 100% 9 / 9 totaltotal 48.4% 32 / 66 CC 4 SCAR 13.9
CC
4
Cov
44%
AUTOLOAD
12.0
scopes
6.0
images
2.0
CRAP 4.0
« lib/Net/Async/Spotify/API/Personalization.pm ↑ Summary lib/Net/Async/Spotify/API/Search.pm »
1 package Net::Async::Spotify::Scope;
2  
3 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 2 our $VERSION = '0.002'; # VERSION
7 2 our $AUTHORITY = 'cpan:VNEALV'; # AUTHORITY
8  
9 =encoding utf8
10  
11 =head1 NAME
12  
13 Net::Async::Spotify::Scope - Helper for Spotify Scopes
14  
15 =head1 SYNOPSIS
16  
17 use Net::Async::Spotify::Scope qw(scopes images);
18  
19 my @all = scopes();
20 my @needed = scopes(qw(ugc_image_upload user_read_recently_played));
21  
22 my @images_scopes = images();
23 my $mod_lib = Net::Async::Spotify::Scope::user_library_modify();
24  
25 # Safe to call, even if Scope does not exist
26 my $dne = Net::Async::Spotify::Scope::dne();
27  
28 =head1 DESCRIPTION
29  
30 Representation for Spotify Authorization Scopes defined in https://developer.spotify.com/documentation/general/guides/scopes
31 methods exported will group scopes as categorized by Spotify.
32  
33 =cut
34  
35 2 ▶use Log::Any qw($log);
Subroutine BEGIN: called CC=1 SCAR=0.0
36  
37 2 ▶use Exporter 'import';
Subroutine BEGIN: called CC=1 SCAR=0.0
38  
39 2 our @EXPORT_OK = qw(scopes images listening_history spotify_connect playback playlists follow library users);
40 2 our %EXPORT_TAGS = ( all => \@EXPORT_OK );
41  
42 2 my %scopes = map { $_ =~ s/-/_/gr => $_ } qw(ugc-image-upload user-read-recently-played user-read-playback-state user-top-read app-remote-control playlist-modify-public user-modify-playback-state playlist-modify-private user-follow-modify user-read-currently-playing user-follow-read user-library-modify user-read-playback-position playlist-read-private user-read-email user-read-private user-library-read playlist-read-collaborative streaming);
43  
44 # TODO: Add support for endpoints allowed for each Scope.
45  
46 =head1 METHODS
47  
48 =head2 scopes
49  
50 Returns list of Spotify Scopes, if no specific scopes requested; will return all scopes.
51  
52 =cut
53  
54 0 ▶sub scopes {
Subroutine scopes: not called CC=2 SCAR=17.9
Pod documented
55 0 my @keys = @_;
56 0 ▶ if ( @keys ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@keys) { } 0 0 0
57 # Get only defined scopes only
58 0 @scopes{ grep { $scopes{$_} } @keys };
59 } else {
60 0 values %scopes;
61 }
62 }
63  
64 =head2 images
65  
66 Returns list of Spotify Scopes for Images
67  
68 =cut
69  
70 0 ▶sub images { @scopes{qw(ugc_image_upload)} }
Subroutine images: not called CC=1 SCAR=6.9
Pod documented
71  
72 =head2 listening_history
73  
74 Returns list of Spotify Scopes for Listening History
75  
76 =cut
77  
78 0 ▶sub listening_history { @scopes{qw(user_read_recently_played user_top_read user_read_playback_position)} }
Subroutine listening_history: not called CC=1 SCAR=6.9
Pod documented
79  
80 =head2 spotify_connect
81  
82 Returns list of Spotify Scopes for Spotify Connect
83  
84 =cut
85  
86 0 ▶sub spotify_connect { @scopes{qw(user_read_playback_state user_modify_playback_state user_read_currently_playing)} }
Subroutine spotify_connect: not called CC=1 SCAR=6.9
Pod documented
87  
88 =head2 playback
89  
90 Returns list of Spotify Scopes for Playback
91  
92 =cut
93  
94 0 ▶sub playback { @scopes{qw(app_remote_control streaming)} }
Subroutine playback: not called CC=1 SCAR=6.9
Pod documented
95  
96 =head2 playlists
97  
98 Returns list of Spotify Scopes for Playlists
99  
100 =cut
101  
102 0 ▶sub playlists { @scopes{qw(playlist_modify_public playlist_modify_private playlist_read_private playlist_read_collaborative)} }
Subroutine playlists: not called CC=1 SCAR=6.9
Pod documented
103  
104 =head2 follow
105  
106 Returns list of Spotify Scopes for Follow
107  
108 =cut
109  
110 0 ▶sub follow { @scopes{qw(user_follow_modify user_follow_read)} }
Subroutine follow: not called CC=1 SCAR=6.9
Pod documented
111  
112 =head2 library
113  
114 Returns list of Spotify Scopes for Library
115  
116 =cut
117  
118 0 ▶sub library { @scopes{qw(user_library_modify user_library_read)} }
Subroutine library: not called CC=1 SCAR=6.9
Pod documented
119  
120 =head2 users
121  
122 Retruns list of Spotify Scopes for Users
123  
124 =cut
125  
126 0 ▶sub users { @scopes{qw(user_read_email user_read_private)} }
Subroutine users: not called CC=1 SCAR=6.9
Pod documented
127  
128 =head2 AUTOLOAD
129  
130 An addition to this helper is that it will check if sub name called corresponde to any Spotify scope.
131 And return a Scope, or log a warn message and return empty list when not found.
132  
133 =cut
134  
135 0 ▶sub AUTOLOAD {
Subroutine AUTOLOAD: not called CC=3 SCAR=24.8
136 0 my ($s) = our $AUTOLOAD =~ m{^.*::([^:]+)$};
137 # Check if exists as individual scope. Else return empty list.
138 0 ▶ return $scopes{$s} if exists $scopes{$s};
Branch: 1 branch
BranchTrueFalseTotal
if exists $scopes{$s} 0 0 0
139 0 ▶ return $scopes{$s =~ s/-/_/gr} if exists $scopes{$s =~ s/-/_/gr};
Branch: 1 branch
BranchTrueFalseTotal
if exists $scopes{$s =~ s/-/_/gr} 0 0 0
140 0 $log->warnf('Could not find Spotify Scope, for: %s', $s);
141 0 return '';
142 }
143  
144 2 1;
« lib/Net/Async/Spotify/API/Personalization.pm ↑ Summary lib/Net/Async/Spotify/API/Search.pm »