File Coverage

blib/lib/WebService/Qiita/V2/Client.pm
Criterion Covered Total %
statement 7 9 77.7
branch n/a
condition n/a
subroutine 3 3 100.0
pod n/a
total 10 12 83.3


line stmt bran cond sub pod time code
1             package WebService::Qiita::V2::Client;
2 4     4   22 use strict;
  4         8  
  4         100  
3 4     4   19 use warnings;
  4         7  
  4         88  
4              
5 4     4   1149 use WebService::Qiita::V2::Client::Methods;
  0            
  0            
6              
7             sub new {
8             my ($class, $params) = @_;
9              
10             $params ||= {};
11             my $args = {
12             methods => WebService::Qiita::V2::Client::Methods->new,
13             token => undef,
14             team => undef,
15             };
16             $args = {%$args, %$params};
17             my $self = bless $args, $class;
18             $self;
19             }
20              
21             sub AUTOLOAD {
22             my $self = shift;
23             my $method = our $AUTOLOAD;
24             my (@args) = @_;
25              
26             $self->call($method, @args);
27             }
28              
29             sub DESTROY {}
30              
31             sub call {
32             my ($self, $method, @args) = @_;
33              
34             $method =~ s/.*:://;
35              
36             my $common_args;
37             $common_args->{headers} = { Authorization => "Bearer " . $self->{token} } if $self->{token};
38             $common_args->{team} = $self->{team} if $self->{team};
39             push @args, $common_args if defined $common_args;
40              
41             $self->{methods}->$method(@args);
42             }
43              
44             sub get_error {
45             my $self = shift;
46             return $self->{methods}->{error};
47             }
48              
49             1;
50             __END__