Asana.pm

filter: Statementstmt 26.0% 19 / 73 Branchbran 0.0% 0 / 24 Conditioncond 20.0% 1 / 5 MC/DCmcdc 0.0% 0 / 3 Subroutinesub 15.0% 3 / 20 Podpod 54.5% 6 / 11 totaltotal 21.3% 29 / 136 CC 16 SCAR 32.9
CC
16
Cov
20%
get_request
90.0
BUILDARGS
12.0
do
12.0
CRAP 26.9
« Asana/Response.pm ↑ Summary Asana/Task.pm »
1 package WWW::Asana;
2 1 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
3 1 $WWW::Asana::AUTHORITY = 'cpan:GETTY';
4 }
5 {
6 1 $WWW::Asana::VERSION = '0.003';
7 }
8 # ABSTRACT: Client Class for accessing Asana API
9  
10  
11 1 ▶use MooX qw(
Subroutine BEGIN: called CC=1 SCAR=0.0
12 +LWP::UserAgent
13 +WWW::Asana::Response
14 +WWW::Asana::Request
15 +URI
16 1 );
17  
18 1 ▶use Carp qw( croak );
Subroutine BEGIN: called CC=1 SCAR=0.0
19  
20 1 ▶our $VERSION ||= '0.000';
Condition50%1/2
our $VERSION ||= "0.000"
l!l
10
MC/DC0%0/1
our $VERSION ||= "0.000"
our $VERSION
Truth table50%1/2
A
A= our $VERSION
Aresult
11
00
21  
22  
23 1 has api_key => (
24 is => 'ro',
25 required => 1,
26 );
27  
28  
29 1 has version => (
30 is => 'ro',
31 lazy => 1,
32 builder => 1,
33 );
34  
35 0 ▶sub _build_version { '1.0' }
Subroutine _build_version: not called CC=1 SCAR=6.9
36  
37  
38 1 has base_uri => (
39 is => 'ro',
40 lazy => 1,
41 builder => 1,
42 );
43  
44 0 ▶sub _build_base_uri { 'https://app.asana.com/api' }
Subroutine _build_base_uri: not called CC=1 SCAR=6.9
45  
46  
47 1 has useragent => (
48 is => 'ro',
49 lazy => 1,
50 builder => 1,
51 );
52  
53 0 ▶sub _build_useragent {
Subroutine _build_useragent: not called CC=2 SCAR=17.9
54 0 my ( $self ) = @_;
55 0 ▶ LWP::UserAgent->new(
Branch: 1 branch
BranchTrueFalseTotal
$self->has_useragent_timeout ? : 0 0 0
56 agent => $self->useragent_agent,
57 $self->has_useragent_timeout ? (timeout => $self->useragent_timeout) : (),
58 );
59 }
60  
61  
62 1 has useragent_agent => (
63 is => 'ro',
64 lazy => 1,
65 builder => 1,
66 );
67  
68 0 ▶sub _build_useragent_agent { (ref $_[0] ? ref $_[0] : $_[0]).'/'.$VERSION }
Subroutine _build_useragent_agent: not called CC=2 SCAR=17.9
Branch: 1 branch
BranchTrueFalseTotal
ref $_[0] ? : 0 0 0
69  
70  
71 1 has useragent_timeout => (
72 is => 'ro',
73 predicate => 'has_useragent_timeout',
74 );
75  
76  
77 1 has request_class => (
78 is => 'ro',
79 lazy => 1,
80 builder => 1,
81 );
82  
83 0 ▶sub _build_request_class { 'WWW::Asana::Request' }
Subroutine _build_request_class: not called CC=1 SCAR=6.9
84  
85  
86 1 has response_class => (
87 is => 'ro',
88 lazy => 1,
89 builder => 1,
90 );
91  
92 0 ▶sub _build_response_class { 'WWW::Asana::Response' }
Subroutine _build_response_class: not called CC=1 SCAR=6.9
93  
94 #############################################################################################################
95  
96 0 ▶sub BUILDARGS {
Subroutine BUILDARGS: not called CC=3 SCAR=24.8
Pod undocumented
97 0 my ( $class, @args ) = @_;
98 0 ▶ unshift @args, "api_key" if @args % 2 && ref $args[0] ne 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
if @args % 2 and ref $args[0] ne "HASH" 0 0 0
Condition0%0/3
@args % 2 and ref $args[0] ne "HASH"
!ll&&!rl&&r
000
MC/DC0%0/2
@args % 2 and ref $args[0] ne "HASH"
@args % 2 ref $args[0] ne "HASH"
Truth table0%0/3
A and B
A= @args % 2B= ref $args[0] ne "HASH"
ABresult
0X0
100
111
99 0 return { @args };
100 }
101  
102  
103 0 ▶sub request {
Subroutine request: not called CC=2 SCAR=17.9
Pod documented
104 0 my ( $self, @args ) = @_;
105 0 my $request;
106 0 ▶ if (ref $args[0] eq $self->request_class) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $args[0] eq $self->request_class) { } 0 0 0
107 0 $request = $args[0];
108 } else {
109 0 $request = $self->get_request(@args);
110 }
111 0 my $http_response = $self->useragent->request($request->http_request);
112 0 my $class_response = $self->response_class;
113 0 return $class_response->new($request, $http_response, $request->to, $self);
114 }
115  
116  
117 0 ▶sub get_uri {
Subroutine get_uri: not called CC=1 SCAR=6.9
Pod undocumented
118 0 my ( $self, @args ) = @_;
119 0 return join('/',$self->base_uri,$self->version,@args);
120 }
121  
122  
123 0 ▶sub get_request {
Subroutine get_request: not called CC=9 SCAR=45.0
Pod documented
124 0 my ( $self, @args ) = @_;
125 0 my $to = shift @args;
126 0 my $method = shift @args;
127 0 my @path_parts;
128 my %data;
129 0 my @params;
130 0 my @codes;
131 0 for my $arg (@args) {
132 0 ▶ if (ref $arg eq 'HASH') {
Branch: 3 branches
BranchTrueFalseTotal
if (ref $arg eq 'HASH') { } 0 0 0
elsif (ref $arg eq 'ARRAY') { } 0 0 0
elsif (ref $arg eq 'CODE') { } 0 0 0
133 0 $data{$_} = $arg->{$_} for (keys %{$arg});
134 } elsif (ref $arg eq 'ARRAY') {
135 0 push @params, [@{$arg}];
136 } elsif (ref $arg eq 'CODE') {
137 0 push @codes, $arg;
138 } else {
139 0 push @path_parts, $arg;
140 }
141 }
142 0 my $uri = $self->get_uri(@path_parts);
143 0 my $request_class = $self->request_class;
144 0 ▶ return $request_class->new(
Branch: 3 branches
BranchTrueFalseTotal
%data ? : 0 0 0
@params ? : 0 0 0
@codes ? : 0 0 0
145 api_key => $self->api_key,
146 uri => $uri,
147 to => $to,
148 method => $method,
149 %data ? ( data => \%data ) : (),
150 @params ? ( params => \@params ) : (),
151 @codes ? ( codes => \@codes ) : (),
152 );
153 }
154  
155  
156 0 ▶sub do {
Subroutine do: not called CC=3 SCAR=24.8
Pod documented
157 0 my ( $self, @args ) = @_;
158 0 my $response = $self->request(@args);
159 0 ▶ if ($response->has_errors) {
Branch: 1 branch
BranchTrueFalseTotal
if ($response->has_errors) 0 0 0
160 0 ▶ croak "Asana Errors:\n".join("\n",map { $_->message.( $_->has_phrase ? " [phrase:".$_->phrase."]" : "" ) } @{$response->errors})."\n";
Branch: 1 branch
BranchTrueFalseTotal
$_->has_phrase ? : 0 0 0
161 }
162 0 return $response->result;
163 }
164  
165  
166 0 ▶sub me_args { 'User','GET','users','me' }
Subroutine me_args: not called CC=1 SCAR=6.9
Pod undocumented
167 0 ▶sub me {
Subroutine me: not called CC=1 SCAR=6.9
Pod documented
168 0 my $self = shift;
169 0 $self->do($self->me_args(@_));
170 }
171  
172  
173 0 ▶sub users_args { '[User]','GET','users' }
Subroutine users_args: not called CC=1 SCAR=6.9
Pod undocumented
174 0 ▶sub users {
Subroutine users: not called CC=1 SCAR=6.9
Pod documented
175 0 my $self = shift;
176 0 $self->do($self->users_args(@_));
177 }
178  
179  
180 0 ▶sub user_args { shift; '[User]','GET','users',shift }
Subroutine user_args: not called CC=1 SCAR=6.9
Pod undocumented
181 0 ▶sub user {
Subroutine user: not called CC=1 SCAR=6.9
Pod documented
182 0 my $self = shift;
183 0 $self->do($self->user_args(@_));
184 }
185  
186 1 1;
187  
188  
189 __END__
« Asana/Response.pm ↑ Summary Asana/Task.pm »