PivotalTracker/Story.pm

filter: Statementstmt 56.5% 52 / 92 Branchbran 0.0% 0 / 2 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 58.3% 14 / 24 Podpod 100% 3 / 3 totaltotal 57.0% 69 / 121 CC 2 SCAR 5.4
CC
2
Cov
55%
_build_labels
6.0
update
2.0
add_comment
2.0
CRAP 1.7
« PivotalTracker/PropertyAttributes.pm ↑ Summary PivotalTracker/Client.pm »
1 package WebService::PivotalTracker::Story;
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 Params::ValidationCompiler qw( validation_for );
Subroutine BEGIN: called CC=1 SCAR=0.0
10 1 ▶use WebService::PivotalTracker::Comment;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 1 ▶use WebService::PivotalTracker::Label;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 1 ▶use WebService::PivotalTracker::Person;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 1 ▶use WebService::PivotalTracker::PropertyAttributes;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 1 ▶use WebService::PivotalTracker::Types qw(
Subroutine BEGIN: called CC=1 SCAR=0.0
15 ArrayRef CommentObject DateTimeObject LabelObject Maybe
16 NonEmptyStr Num PersonObject PositiveInt Str StoryState StoryType Uri
17 1 );
18  
19 1 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
20  
21 my %props = (
22 id => PositiveInt,
23 project_id => PositiveInt,
24 name => NonEmptyStr,
25 description => Str,
26 story_type => StoryType,
27 current_state => StoryState,
28 estimate => Maybe [Num],
29 accepted_at => {
30 type => DateTimeObject,
31 inflator => '_inflate_iso8601_datetime',
32 },
33 deadline => {
34 type => DateTimeObject,
35 inflator => '_inflate_iso8601_datetime',
36 },
37 requested_by_id => PositiveInt,
38 owner_ids => ArrayRef [PositiveInt],
39 task_ids => {
40 type => ArrayRef [PositiveInt],
41 1 ▶ default => sub { [] },
Subroutine __ANON__: called CC=1 SCAR=0.0
42 },
43 follower_ids => {
44 type => ArrayRef [PositiveInt],
45 1 ▶ default => sub { [] },
Subroutine __ANON__: called CC=1 SCAR=0.0
46 },
47 1 created_at => {
48 type => DateTimeObject,
49 inflator => '_inflate_iso8601_datetime',
50 },
51 updated_at => {
52 type => DateTimeObject,
53 inflator => '_inflate_iso8601_datetime',
54 },
55 url => {
56 type => Uri,
57 inflator => '_inflate_uri',
58 },
59 kind => NonEmptyStr,
60 );
61  
62 1 has( @{$_} ) for props_to_attributes(%props);
63  
64 1 has comments => (
65 is => 'ro',
66 isa => ArrayRef [CommentObject],
67 init_arg => undef,
68 lazy => 1,
69 builder => '_build_comments',
70 clearer => '_clear_comments',
71 );
72  
73 1 has labels => (
74 is => 'ro',
75 isa => ArrayRef [LabelObject],
76 init_arg => undef,
77 lazy => 1,
78 builder => '_build_labels',
79 clearer => '_clear_labels',
80 );
81  
82 has requested_by => (
83 is => 'ro',
84 isa => PersonObject,
85 lazy => 1,
86 1 ▶ default => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
87 1 my $self = shift;
88 WebService::PivotalTracker::Person->new(
89 raw_content => $self->raw_content->{requested_by},
90 1 pt_api => $self->_pt_api,
91 );
92 },
93 1 );
94  
95 1 with 'WebService::PivotalTracker::Entity';
96  
97 ## no critic (Subroutines::ProhibitUnusedPrivateSubroutines)
98 2 ▶sub _properties {
Subroutine _properties: called CC=1 SCAR=0.0
99 2 return %props;
100 }
101 ## use critic
102  
103 {
104 1 my $check = validation_for(
105 params => {
106 current_state => { type => StoryState },
107 }
108 );
109  
110 0 ▶ sub update {
Subroutine update: not called CC=1 SCAR=6.9
Pod documented
111 0 my $self = shift;
112 0 my %args = $check->(@_);
113  
114 0 my $raw = $self->_client->put( $self->_self_uri, \%args );
115  
116 0 return ( ref $self )->new(
117 raw_content => $raw,
118 pt_api => $self->_pt_api,
119 );
120 }
121 }
122  
123 {
124 1 my $check = validation_for(
125 params => {
126 person_id => {
127 type => PositiveInt,
128 optional => 1,
129 },
130 text => { type => NonEmptyStr },
131 }
132 );
133  
134 0 ▶ sub add_comment {
Subroutine add_comment: not called CC=1 SCAR=6.9
Pod documented
135 0 my $self = shift;
136 0 my %args = $check->(@_);
137  
138 0 my $comment = WebService::PivotalTracker::Comment->new(
139 raw_content =>
140 $self->_client->post( $self->_comments_uri, \%args ),
141 pt_api => $self->_pt_api,
142 );
143 0 $self->_clear_comments;
144  
145 0 return $comment;
146 }
147 }
148  
149 # We could fetch each id in $self->comment_ids one at a time, but there's an
150 # endpoint to get all the comments at once, which is going to be more
151 # efficient.
152 1 ▶sub _build_comments {
Subroutine _build_comments: not called CC=1 SCAR=4.6
153 0 my $self = shift;
154  
155 0 my $raw_comments = $self->_client->get( $self->_comments_uri );
156  
157 return [
158 map {
159 0 WebService::PivotalTracker::Comment->new(
160 raw_content => $_,
161 pt_api => $self->_pt_api,
162 )
163 0 } @{$raw_comments}
164 ];
165 }
166  
167 0 ▶sub _comments_uri {
Subroutine _comments_uri: not called CC=1 SCAR=6.9
168 0 my $self = shift;
169  
170 0 my $path = sprintf(
171 '/projects/%s/stories/%s/comments',
172 $self->project_id,
173 $self->id,
174 );
175  
176 0 return $self->_client->build_uri($path);
177 }
178  
179 0 ▶before _clear_comments => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
180 0 my $self = shift;
181 0 delete $self->raw_content->{comments};
182 1 };
183  
184 {
185 1 my $check = validation_for(
186 params => {
187 name => { type => NonEmptyStr },
188 }
189 );
190  
191 0 ▶ sub add_label {
Subroutine add_label: not called CC=1 SCAR=6.9
Pod documented
192 0 my $self = shift;
193 0 my %args = $check->(@_);
194  
195 0 $self->_client->post( $self->_labels_uri, \%args );
196 0 $self->_clear_labels;
197  
198 0 return;
199 }
200 }
201  
202 1 ▶before _clear_labels => sub {
Subroutine __ANON__: not called CC=1 SCAR=2.6
203 0 my $self = shift;
204 0 delete $self->raw_content->{labels};
205 1 };
206  
207 # We might already have all the label info, otherwise we can fetch all the
208 # labels at once rather iterating over each id, just like with comments.
209 0 ▶sub _build_labels {
Subroutine _build_labels: not called CC=2 SCAR=17.9
210 0 my $self = shift;
211  
212 0 ▶ if ( $self->raw_content->{labels} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->raw_content->{"labels"}) 0 0 0
213 return [
214 map {
215 0 WebService::PivotalTracker::Label->new(
216 raw_content => $_,
217 pt_api => $self->_pt_api,
218 )
219 0 } @{ $self->raw_content->{labels} }
220 ];
221 }
222  
223 0 my $raw_labels = $self->_client->get( $self->_labels_uri );
224  
225 return [
226 map {
227 0 WebService::PivotalTracker::Label->new(
228 raw_content => $_,
229 pt_api => $self->_pt_api,
230 )
231 0 } @{$raw_labels}
232 ];
233 }
234  
235 0 ▶sub _labels_uri {
Subroutine _labels_uri: not called CC=1 SCAR=6.9
236 0 my $self = shift;
237  
238 0 my $path = sprintf(
239 '/projects/%s/stories/%s/labels',
240 $self->project_id,
241 $self->id,
242 );
243  
244 0 return $self->_client->build_uri($path);
245 }
246  
247 0 ▶sub _self_uri {
Subroutine _self_uri: not called CC=1 SCAR=6.9
248 0 my $self = shift;
249  
250 0 return $self->_client->build_uri(
251 sprintf(
252 '/stories/%s',
253 $self->id,
254 )
255 );
256 }
257  
258 1 1;
259  
260 # ABSTRACT: A single story
261  
262 __END__
« PivotalTracker/PropertyAttributes.pm ↑ Summary PivotalTracker/Client.pm »