line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Net::Lighthouse::Project::Milestone; |
2
|
11
|
|
|
11
|
|
66
|
use Any::Moose; |
|
11
|
|
|
|
|
26
|
|
|
11
|
|
|
|
|
85
|
|
3
|
11
|
|
|
11
|
|
5892
|
use Params::Validate ':all'; |
|
11
|
|
|
|
|
23
|
|
|
11
|
|
|
|
|
2866
|
|
4
|
11
|
|
|
11
|
|
99
|
use Net::Lighthouse::Util; |
|
11
|
|
|
|
|
40
|
|
|
11
|
|
|
|
|
1139
|
|
5
|
|
|
|
|
|
|
extends 'Net::Lighthouse::Base'; |
6
|
|
|
|
|
|
|
# read only attr |
7
|
|
|
|
|
|
|
has [qw/created_at updated_at/] => ( |
8
|
|
|
|
|
|
|
isa => 'Maybe[DateTime]', |
9
|
|
|
|
|
|
|
is => 'ro', |
10
|
|
|
|
|
|
|
); |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
has [qw/open_tickets_count id project_id tickets_count/] => ( |
13
|
|
|
|
|
|
|
isa => 'Int', |
14
|
|
|
|
|
|
|
is => 'ro', |
15
|
|
|
|
|
|
|
); |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
has [ 'goals_html', 'user_name', 'permalink', 'url', ] => ( |
18
|
|
|
|
|
|
|
isa => 'Maybe[Str]', |
19
|
|
|
|
|
|
|
is => 'ro', |
20
|
|
|
|
|
|
|
); |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
# read&write attr |
23
|
|
|
|
|
|
|
has [qw/title goals due_on/] => ( |
24
|
|
|
|
|
|
|
isa => 'Maybe[Str]', |
25
|
|
|
|
|
|
|
is => 'rw', |
26
|
|
|
|
|
|
|
); |
27
|
|
|
|
|
|
|
|
28
|
11
|
|
|
11
|
|
58
|
no Any::Moose; |
|
11
|
|
|
|
|
36
|
|
|
11
|
|
|
|
|
64
|
|
29
|
|
|
|
|
|
|
__PACKAGE__->meta->make_immutable; |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
sub load { |
32
|
1
|
|
|
1
|
1
|
11834
|
my $self = shift; |
33
|
1
|
|
|
|
|
32
|
validate_pos( @_, { type => SCALAR, regex => qr/^\d+|\w+$/ } ); |
34
|
1
|
|
|
|
|
13
|
my $id = shift; |
35
|
|
|
|
|
|
|
|
36
|
1
|
50
|
|
|
|
9
|
if ( $id !~ /^\d+$/ ) { |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
# so we got a title, let's find it |
39
|
0
|
|
|
|
|
0
|
my ($milestone) = grep { $_->title eq $id } $self->list; |
|
0
|
|
|
|
|
0
|
|
40
|
0
|
0
|
|
|
|
0
|
if ($milestone) { |
41
|
0
|
|
|
|
|
0
|
$id = $milestone->id; |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
else { |
44
|
0
|
|
|
|
|
0
|
die "can't find milestone $id in project " |
45
|
|
|
|
|
|
|
. $self->project_id |
46
|
|
|
|
|
|
|
. ' in account ' |
47
|
|
|
|
|
|
|
. $self->account; |
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
|
51
|
1
|
|
|
|
|
14
|
my $ua = $self->ua; |
52
|
1
|
|
|
|
|
8
|
my $url = |
53
|
|
|
|
|
|
|
$self->base_url |
54
|
|
|
|
|
|
|
. '/projects/' |
55
|
|
|
|
|
|
|
. $self->project_id . '/milestones/' |
56
|
|
|
|
|
|
|
. $id . '.xml'; |
57
|
1
|
|
|
|
|
6
|
my $res = $ua->get( $url ); |
58
|
1
|
50
|
|
|
|
53
|
if ( $res->is_success ) { |
59
|
1
|
|
|
|
|
51
|
$self->load_from_xml( $res->content ); |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
else { |
62
|
0
|
|
|
|
|
0
|
die "try to get $url failed: " |
63
|
|
|
|
|
|
|
. $res->status_line . "\n" |
64
|
|
|
|
|
|
|
. $res->content; |
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
sub load_from_xml { |
69
|
4
|
|
|
4
|
1
|
133
|
my $self = shift; |
70
|
4
|
|
|
|
|
24
|
my $ref = Net::Lighthouse::Util->translate_from_xml( shift ); |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
# dirty hack: some attrs are read-only, and Mouse doesn't support |
73
|
|
|
|
|
|
|
# writer => '...' |
74
|
4
|
|
|
|
|
23
|
for my $k ( keys %$ref ) { |
75
|
52
|
|
|
|
|
129
|
$self->{$k} = $ref->{$k}; |
76
|
|
|
|
|
|
|
} |
77
|
4
|
|
|
|
|
26
|
return $self; |
78
|
|
|
|
|
|
|
} |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
sub create { |
81
|
0
|
|
|
0
|
1
|
0
|
my $self = shift; |
82
|
0
|
|
|
|
|
0
|
validate( |
83
|
|
|
|
|
|
|
@_, |
84
|
|
|
|
|
|
|
{ |
85
|
|
|
|
|
|
|
goals => { type => SCALAR }, |
86
|
|
|
|
|
|
|
title => { type => SCALAR }, |
87
|
|
|
|
|
|
|
due_on => { optional => 1, type => SCALAR }, |
88
|
|
|
|
|
|
|
} |
89
|
|
|
|
|
|
|
); |
90
|
0
|
|
|
|
|
0
|
my %args = @_; |
91
|
|
|
|
|
|
|
|
92
|
0
|
|
|
|
|
0
|
my $xml = |
93
|
|
|
|
|
|
|
Net::Lighthouse::Util->translate_to_xml( \%args, root => 'milestone', ); |
94
|
0
|
|
|
|
|
0
|
my $ua = $self->ua; |
95
|
|
|
|
|
|
|
|
96
|
0
|
|
|
|
|
0
|
my $url = $self->base_url . '/projects/' . $self->project_id . '/milestones.xml'; |
97
|
|
|
|
|
|
|
|
98
|
0
|
|
|
|
|
0
|
my $request = HTTP::Request->new( 'POST', $url, undef, $xml ); |
99
|
0
|
|
|
|
|
0
|
my $res = $ua->request( $request ); |
100
|
0
|
0
|
|
|
|
0
|
if ( $res->is_success ) { |
101
|
0
|
|
|
|
|
0
|
$self->load_from_xml( $res->content ); |
102
|
0
|
|
|
|
|
0
|
return 1; |
103
|
|
|
|
|
|
|
} |
104
|
|
|
|
|
|
|
else { |
105
|
0
|
|
|
|
|
0
|
die "try to POST $url failed: " |
106
|
|
|
|
|
|
|
. $res->status_line . "\n" |
107
|
|
|
|
|
|
|
. $res->content; |
108
|
|
|
|
|
|
|
} |
109
|
|
|
|
|
|
|
} |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
sub update { |
112
|
0
|
|
|
0
|
1
|
0
|
my $self = shift; |
113
|
0
|
|
|
|
|
0
|
validate( |
114
|
|
|
|
|
|
|
@_, |
115
|
|
|
|
|
|
|
{ |
116
|
|
|
|
|
|
|
goals => { optional => 1, type => SCALAR }, |
117
|
|
|
|
|
|
|
title => { optional => 1, type => SCALAR }, |
118
|
|
|
|
|
|
|
due_on => { optional => 1, type => SCALAR }, |
119
|
|
|
|
|
|
|
} |
120
|
|
|
|
|
|
|
); |
121
|
0
|
|
|
|
|
0
|
my %args = ( ( map { $_ => $self->$_ } qw/title goals due_on/ ), @_ ); |
|
0
|
|
|
|
|
0
|
|
122
|
|
|
|
|
|
|
|
123
|
0
|
|
|
|
|
0
|
my $xml = |
124
|
|
|
|
|
|
|
Net::Lighthouse::Util->translate_to_xml( \%args, root => 'milestone', ); |
125
|
0
|
|
|
|
|
0
|
my $ua = $self->ua; |
126
|
0
|
|
|
|
|
0
|
my $url = |
127
|
|
|
|
|
|
|
$self->base_url |
128
|
|
|
|
|
|
|
. '/projects/' |
129
|
|
|
|
|
|
|
. $self->project_id . '/milestones/' |
130
|
|
|
|
|
|
|
. $self->id . '.xml'; |
131
|
|
|
|
|
|
|
|
132
|
0
|
|
|
|
|
0
|
my $request = HTTP::Request->new( 'PUT', $url, undef, $xml ); |
133
|
0
|
|
|
|
|
0
|
my $res = $ua->request( $request ); |
134
|
0
|
0
|
|
|
|
0
|
if ( $res->is_success ) { |
135
|
0
|
|
|
|
|
0
|
$self->load( $self->id ); # let's reload |
136
|
0
|
|
|
|
|
0
|
return 1; |
137
|
|
|
|
|
|
|
} |
138
|
|
|
|
|
|
|
else { |
139
|
0
|
|
|
|
|
0
|
die "try to PUT $url failed: " |
140
|
|
|
|
|
|
|
. $res->status_line . "\n" |
141
|
|
|
|
|
|
|
. $res->content; |
142
|
|
|
|
|
|
|
} |
143
|
|
|
|
|
|
|
} |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
sub delete { |
146
|
0
|
|
|
0
|
1
|
0
|
my $self = shift; |
147
|
0
|
|
|
|
|
0
|
my $ua = $self->ua; |
148
|
0
|
|
|
|
|
0
|
my $url = |
149
|
|
|
|
|
|
|
$self->base_url |
150
|
|
|
|
|
|
|
. '/projects/' |
151
|
|
|
|
|
|
|
. $self->project_id . '/milestones/' |
152
|
|
|
|
|
|
|
. $self->id . '.xml'; |
153
|
|
|
|
|
|
|
|
154
|
0
|
|
|
|
|
0
|
my $request = HTTP::Request->new( 'DELETE', $url ); |
155
|
0
|
|
|
|
|
0
|
my $res = $ua->request( $request ); |
156
|
0
|
0
|
|
|
|
0
|
if ( $res->is_success ) { |
157
|
0
|
|
|
|
|
0
|
return 1; |
158
|
|
|
|
|
|
|
} |
159
|
|
|
|
|
|
|
else { |
160
|
0
|
|
|
|
|
0
|
die "try to DELETE $url failed: " |
161
|
|
|
|
|
|
|
. $res->status_line . "\n" |
162
|
|
|
|
|
|
|
. $res->content; |
163
|
|
|
|
|
|
|
} |
164
|
|
|
|
|
|
|
} |
165
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
sub list { |
167
|
3
|
|
|
3
|
1
|
10602
|
my $self = shift; |
168
|
3
|
|
|
|
|
22
|
my $url = |
169
|
|
|
|
|
|
|
$self->base_url . '/projects/' . $self->project_id . '/milestones.xml'; |
170
|
3
|
|
|
|
|
18
|
my $ua = $self->ua; |
171
|
3
|
|
|
|
|
19
|
my $res = $ua->get($url); |
172
|
3
|
50
|
|
|
|
174
|
if ( $res->is_success ) { |
173
|
3
|
|
|
|
|
172
|
my $ms = |
174
|
|
|
|
|
|
|
Net::Lighthouse::Util->read_xml( $res->content )->{milestones}{milestone}; |
175
|
9
|
|
|
|
|
87
|
my @list = map { |
176
|
3
|
50
|
|
|
|
6238
|
my $t = Net::Lighthouse::Project::Milestone->new( |
177
|
9
|
|
|
|
|
34
|
map { $_ => $self->$_ } |
178
|
3
|
|
|
|
|
7
|
grep { $self->$_ } qw/account auth project_id/ |
179
|
|
|
|
|
|
|
); |
180
|
3
|
|
|
|
|
37
|
$t->load_from_xml($_); |
181
|
|
|
|
|
|
|
} ref $ms eq 'ARRAY' ? @$ms : $ms; |
182
|
3
|
100
|
|
|
|
32
|
return wantarray ? @list : \@list; |
183
|
|
|
|
|
|
|
} |
184
|
|
|
|
|
|
|
else { |
185
|
0
|
|
|
|
|
0
|
die "try to get $url failed: " |
186
|
|
|
|
|
|
|
. $res->status_line . "\n" |
187
|
|
|
|
|
|
|
. $res->content; |
188
|
|
|
|
|
|
|
} |
189
|
|
|
|
|
|
|
|
190
|
|
|
|
|
|
|
} |
191
|
|
|
|
|
|
|
|
192
|
|
|
|
|
|
|
sub initial_state { |
193
|
1
|
|
|
1
|
1
|
3
|
my $self = shift; |
194
|
1
|
|
|
|
|
5
|
my $ua = $self->ua; |
195
|
1
|
|
|
|
|
6
|
my $url = |
196
|
|
|
|
|
|
|
$self->base_url . '/projects/' . $self->project_id . '/milestones/new.xml'; |
197
|
1
|
|
|
|
|
9
|
my $res = $ua->get( $url ); |
198
|
1
|
50
|
|
|
|
67
|
if ( $res->is_success ) { |
199
|
1
|
|
|
|
|
65
|
return Net::Lighthouse::Util->translate_from_xml( $res->content ); |
200
|
|
|
|
|
|
|
} |
201
|
|
|
|
|
|
|
else { |
202
|
0
|
|
|
|
|
|
die "try to get $url failed: " |
203
|
|
|
|
|
|
|
. $res->status_line . "\n" |
204
|
|
|
|
|
|
|
. $res->content; |
205
|
|
|
|
|
|
|
} |
206
|
|
|
|
|
|
|
} |
207
|
|
|
|
|
|
|
|
208
|
|
|
|
|
|
|
1; |
209
|
|
|
|
|
|
|
|
210
|
|
|
|
|
|
|
__END__ |