API/Endpoint.pm untested

filter: Statementstmt 0.0% 0 / 67 Branchbran 0.0% 0 / 4 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 18 Podpod 0.0% 0 / 2 totaltotal 0.0% 0 / 91 CC 3 SCAR 12.5
CC
3
Cov
0%
path
12.0
dump
2.0
BEGIN
2.0
CRAP 3.5
1 package Imgur::API::Endpoint;
2  
3 use strict;
4  
5 use Imgur::API::Endpoint::Account;
6 use Imgur::API::Endpoint::Album;
7 use Imgur::API::Endpoint::Comment;
8 use Imgur::API::Endpoint::Conversation;
9 use Imgur::API::Endpoint::Custom_gallery;
10 use Imgur::API::Endpoint::Gallery;
11 use Imgur::API::Endpoint::Image;
12 use Imgur::API::Endpoint::Memegen;
13 use Imgur::API::Endpoint::Notification;
14 use Imgur::API::Endpoint::Topic;
15 use Imgur::API::Endpoint::Misc;
16 use Imgur::API::Endpoint::OAuth;
17  
18 use Mouse;
19 use Data::Dumper;
20 use feature qw(say);
21  
22 has dispatcher=>(is=>'ro');
23  
24 sub dump {
25 my ($this,$obj) = @_;
26  
27 say Dumper($obj);
28 }
29  
30 sub path {
31 my ($this,$base,$required,$optional,$params) = @_;
32
33 my $main = sprintf($base,map {$params->{$_}} @$required);
34 foreach (@$required) { delete $params->{$_}; }
35 my @parts;
36 foreach my $opt (@$optional) {
37 if ($params->{$opt}) {
38 push(@parts,$params->{$opt});
39 delete $params->{$opt};
40 } else {
41 last OPTIONALS;
42 }
43 }
44 if (scalar(@parts)) {
45 return "https://api.imgur.com/".join("/",$main,join("/",@parts));
46 } else {
47 return "https://api.imgur.com/$main";
48 }
49 }
50  
51 1;
52 __PACKAGE__->meta->make_immutable;