PivotalTracker.pm

filter: Statementstmt 65.7% 75 / 114 Branchbran 50.0% 3 / 6 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 69.5% 16 / 23 Podpod 85.7% 6 / 7 totaltotal 64.5% 100 / 155 CC 5 SCAR 14.1
CC
5
Cov
63%
_deflate_datetime_values
20.0
_build_client
2.1
projects
2.0
CRAP 4.1
↑ Summary PivotalTracker/PropertyAttributes.pm »
1 package WebService::PivotalTracker;
2  
3 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 1 our $VERSION = '0.12';
8  
9 1 ▶use DateTime::Format::RFC3339;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 1 ▶use Params::ValidationCompiler qw( validation_for );
Subroutine BEGIN: called CC=1 SCAR=0.0
11 1 ▶use Scalar::Util qw( blessed );
Subroutine BEGIN: called CC=1 SCAR=0.0
12 1 ▶use WebService::PivotalTracker::Client;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 1 ▶use WebService::PivotalTracker::Me;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 1 ▶use WebService::PivotalTracker::Project;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 1 ▶use WebService::PivotalTracker::ProjectIteration;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 1 ▶use WebService::PivotalTracker::ProjectMembership;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 1 ▶use WebService::PivotalTracker::Story;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 use WebService::PivotalTracker::Types
19 1 ▶ qw( ArrayRef ClientObject IterationScope LWPObject MD5Hex NonEmptyStr PositiveInt Uri );
Subroutine BEGIN: called CC=1 SCAR=0.0
20  
21 1 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
22  
23 1 has token => (
24 is => 'ro',
25 isa => MD5Hex,
26 required => 1,
27 );
28  
29 1 has base_uri => (
30 is => 'ro',
31 isa => Uri,
32 coerce => 1,
33 default => 'https://www.pivotaltracker.com/services/v5',
34 );
35  
36 1 has _ua => (
37 is => 'ro',
38 isa => LWPObject,
39 init_arg => 'ua',
40 predicate => '_has_ua',
41 );
42  
43 1 has _client => (
44 is => 'ro',
45 isa => ClientObject,
46 lazy => 1,
47 builder => '_build_client',
48 );
49  
50 # This is gross. Is there a better way to manage this? This is the only way to
51 # get the Person who is the requester. There is no person endpoint from which
52 # to retrieve this information later!
53 1 my $StoryFields = do {
54 ## no critic (Subroutines::ProtectPrivateSubs)
55 1 my %props = WebService::PivotalTracker::Story->_properties;
56 1 join ',', sort ( keys %props, 'requested_by' );
57 };
58  
59 0 ▶sub projects {
Subroutine projects: not called CC=1 SCAR=6.9
Pod documented
60 0 my $self = shift;
61  
62 0 my $uri = $self->_client->build_uri('/projects');
63  
64 return [
65 map {
66 0 WebService::PivotalTracker::Project->new(
67 raw_content => $_,
68 pt_api => $self,
69 )
70 0 } @{ $self->_client->get($uri) }
71 ];
72 }
73  
74 {
75 1 my $check = validation_for(
76 params => {
77 project_id => { type => PositiveInt },
78 filter => {
79 type => NonEmptyStr,
80 optional => 1
81 },
82 }
83 );
84  
85 0 ▶ sub project_stories_where {
Subroutine project_stories_where: not called CC=1 SCAR=6.9
Pod documented
86 0 my $self = shift;
87 0 my %args = $check->(@_);
88  
89 0 my $uri = $self->_client->build_uri(
90 "/projects/$args{project_id}/stories?",
91 {
92 %args,
93 fields => $StoryFields,
94 },
95 );
96  
97 return [
98 map {
99 0 WebService::PivotalTracker::Story->new(
100 raw_content => $_,
101 pt_api => $self,
102 )
103 0 } @{ $self->_client->get($uri) }
104 ];
105 }
106 }
107  
108 {
109 1 my $check = validation_for(
110 params => {
111 story_id => { type => PositiveInt },
112 }
113 );
114  
115 3 ▶ sub story {
Subroutine story: called CC=1 SCAR=0.0
Pod documented
116 3 my $self = shift;
117 3 my %args = $check->(@_);
118  
119 3 my $content = $self->_client->get(
120 $self->_client->build_uri(
121 "/stories/$args{story_id}",
122 { fields => $StoryFields }
123 ),
124 );
125 1 WebService::PivotalTracker::Story->new(
126 raw_content => $content,
127 pt_api => $self,
128 );
129 }
130 }
131  
132 {
133 1 my $check = validation_for(
134 params => {
135 project_id => { type => PositiveInt },
136 sort_by => {
137 type => NonEmptyStr, # This could be an enum.
138 optional => 1,
139 },
140 },
141 );
142  
143 0 ▶ sub project_memberships {
Subroutine project_memberships: not called CC=1 SCAR=6.9
Pod documented
144 0 my $self = shift;
145 0 my %args = $check->(@_);
146  
147 0 my $project_id = delete $args{project_id};
148 0 my $uri = $self->_client->build_uri(
149 "/projects/$project_id/memberships",
150 \%args,
151 );
152  
153 return [
154 map {
155 0 WebService::PivotalTracker::ProjectMembership->new(
156 raw_content => $_,
157 pt_api => $self,
158 )
159 0 } @{ $self->_client->get($uri) }
160 ];
161 }
162 }
163  
164 {
165 1 my $check = validation_for(
166 params => {
167 project_id => { type => PositiveInt },
168 label => {
169 type => NonEmptyStr,
170 optional => 1
171 },
172 limit => {
173 type => PositiveInt,
174 default => 1,
175 },
176 offset => {
177 type => PositiveInt,
178 optional => 1,
179 },
180 scope => {
181 type => IterationScope,
182 optional => 1
183 },
184 },
185 );
186  
187 0 ▶ sub project_iterations {
Subroutine project_iterations: not called CC=1 SCAR=6.9
Pod undocumented
188 0 my $self = shift;
189 0 my %args = $check->(@_);
190  
191 0 my $uri = $self->_client->build_uri(
192 "/projects/$args{project_id}/iterations",
193 \%args,
194 );
195  
196 return [
197 map {
198 0 WebService::PivotalTracker::ProjectIteration->new(
199 raw_content => $_,
200 pt_api => $self,
201 )
202 0 } @{ $self->_client->get($uri) }
203 ];
204 }
205 }
206  
207 # XXX - if we want to add more create_X methods we should find a way to
208 # streamline & simplify this code so we don't have to repeat this sort of
209 # boilerplate over and over. Maybe each entity class should provide more
210 # detail about the properties, including type, coercions (like DateTime ->
211 # RFC3339 string), required for create/update, etc.
212 {
213 ## no critic (Subroutines::ProtectPrivateSubs)
214 1 my %props = WebService::PivotalTracker::Story->_properties;
215 my %params = map {
216 1 $_ => blessed $props{$_}
217 ? { type => $props{$_} }
218 : { type => $props{$_}{type} }
219 17 ▶ } keys %props;
Branch: 1 branch
BranchTrueFalseTotal
builtin::blessed($props{$_}) ? : 10 7 17
220  
221 1 my %required = map { $_ => 1 } qw( project_id name );
222 1 $params{$_}{optional} = 1 for grep { !$required{$_} } keys %props;
223  
224 1 %params = (
225 %params,
226 before_id => {
227 type => PositiveInt,
228 optional => 1,
229 },
230 after_id => {
231 type => PositiveInt,
232 optional => 1,
233 },
234 labels => {
235 type => ArrayRef [NonEmptyStr],
236 optional => 1
237 },
238 );
239  
240 1 my $check = validation_for(
241 params => \%params,
242 );
243  
244 0 ▶ sub create_story {
Subroutine create_story: not called CC=1 SCAR=6.9
Pod documented
245 0 my $self = shift;
246 0 my %args = $check->(@_);
247  
248 0 $self->_deflate_datetime_values( \%args );
249  
250 0 my $project_id = delete $args{project_id};
251 0 my $raw_content = $self->_client->post(
252 $self->_client->build_uri("/projects/$project_id/stories"),
253 \%args,
254 );
255  
256 0 return WebService::PivotalTracker::Story->new(
257 raw_content => $raw_content,
258 pt_api => $self,
259 );
260 }
261 }
262  
263 1 ▶sub me {
Subroutine me: not called CC=1 SCAR=2.6
Pod documented
264 0 my $self = shift;
265  
266 0 return WebService::PivotalTracker::Me->new(
267 raw_content =>
268 $self->_client->get( $self->_client->build_uri('/me') ),
269 pt_api => $self,
270 );
271 }
272  
273 3 ▶sub _build_client {
Subroutine _build_client: called CC=2 SCAR=7.2
274 3 my $self = shift;
275  
276 3 ▶ return WebService::PivotalTracker::Client->new(
Branch: 1 branch
BranchTrueFalseTotal
$self->_has_ua ? : 3 0 3
277 token => $self->token,
278 base_uri => $self->base_uri,
279 ( $self->_has_ua ? ( ua => $self->_ua ) : () ),
280 );
281 }
282  
283 0 ▶sub _deflate_datetime_values {
Subroutine _deflate_datetime_values: not called CC=4 SCAR=30.0
284 0 my $self = shift;
285 0 my $args = shift;
286  
287 0 for my $key ( keys %{$args} ) {
288 0 ▶ next unless blessed $args->{$key} && $args->{$key}->isa('DateTime');
Branch: 1 branch
BranchTrueFalseTotal
unless builtin::blessed($args->{$key}) and $args->{$key}->isa("DateTime") 0 0 0
Condition0%0/3
builtin::blessed($args->{$key}) and $args->{$key}->isa("DateTime")
!ll&&!rl&&r
000
MC/DC0%0/2
builtin::blessed($args->{$key}) and $args->{$key}->isa("DateTime")
builtin::blessed($args->{$key}) $args->{$key}->isa("DateTime")
Truth table0%0/3
A and B
A= builtin::blessed($args->{$key})B= $args->{$key}->isa("DateTime")
ABresult
0X0
100
111
289 $args->{$key}
290 0 = DateTime::Format::RFC3339->format_datetime( $args->{$key} );
291 }
292  
293 0 return;
294 }
295  
296 1 1;
297  
298 # ABSTRACT: Perl library for the Pivotal Tracker REST API
299  
300 __END__
↑ Summary PivotalTracker/PropertyAttributes.pm »