line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Net::Lighthouse::Project::Changeset; |
2
|
11
|
|
|
11
|
|
65
|
use Any::Moose; |
|
11
|
|
|
|
|
26
|
|
|
11
|
|
|
|
|
88
|
|
3
|
11
|
|
|
11
|
|
5653
|
use Params::Validate ':all'; |
|
11
|
|
|
|
|
28
|
|
|
11
|
|
|
|
|
2554
|
|
4
|
11
|
|
|
11
|
|
115
|
use Net::Lighthouse::Util; |
|
11
|
|
|
|
|
50
|
|
|
11
|
|
|
|
|
1242
|
|
5
|
|
|
|
|
|
|
extends 'Net::Lighthouse::Base'; |
6
|
|
|
|
|
|
|
# read only attr |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
has [qw/project_id user_id/] => ( |
9
|
|
|
|
|
|
|
isa => 'Int', |
10
|
|
|
|
|
|
|
is => 'ro', |
11
|
|
|
|
|
|
|
); |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
has 'body_html' => ( |
14
|
|
|
|
|
|
|
isa => 'Maybe[Str]', |
15
|
|
|
|
|
|
|
is => 'ro', |
16
|
|
|
|
|
|
|
); |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
# read&write attr |
19
|
|
|
|
|
|
|
has 'changed_at' => ( |
20
|
|
|
|
|
|
|
isa => 'DateTime', |
21
|
|
|
|
|
|
|
is => 'rw', |
22
|
|
|
|
|
|
|
); |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
has 'changes' => ( |
25
|
|
|
|
|
|
|
isa => 'ArrayRef', |
26
|
|
|
|
|
|
|
is => 'rw', |
27
|
|
|
|
|
|
|
auto_deref => 1, |
28
|
|
|
|
|
|
|
); |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
has [qw/body title revision/] => ( |
31
|
|
|
|
|
|
|
isa => 'Maybe[Str]', |
32
|
|
|
|
|
|
|
is => 'rw', |
33
|
|
|
|
|
|
|
); |
34
|
|
|
|
|
|
|
|
35
|
11
|
|
|
11
|
|
103
|
no Any::Moose; |
|
11
|
|
|
|
|
22
|
|
|
11
|
|
|
|
|
55
|
|
36
|
|
|
|
|
|
|
__PACKAGE__->meta->make_immutable; |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
sub load { |
39
|
1
|
|
|
1
|
1
|
30936
|
my $self = shift; |
40
|
1
|
|
|
|
|
40
|
validate_pos( @_, { type => SCALAR, regex => qr/^\d+$/ } ); |
41
|
1
|
|
|
|
|
19
|
my $revision = shift; |
42
|
1
|
|
|
|
|
342
|
my $ua = $self->ua; |
43
|
1
|
|
|
|
|
9
|
my $url = |
44
|
|
|
|
|
|
|
$self->base_url |
45
|
|
|
|
|
|
|
. '/projects/' |
46
|
|
|
|
|
|
|
. $self->project_id . '/changesets/' |
47
|
|
|
|
|
|
|
. $revision . '.xml'; |
48
|
1
|
|
|
|
|
9
|
my $res = $ua->get( $url ); |
49
|
1
|
50
|
|
|
|
64
|
if ( $res->is_success ) { |
50
|
1
|
|
|
|
|
1204
|
$self->load_from_xml( $res->content ); |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
else { |
53
|
0
|
|
|
|
|
0
|
die "try to get $url failed: " |
54
|
|
|
|
|
|
|
. $res->status_line . "\n" |
55
|
|
|
|
|
|
|
. $res->content; |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
sub load_from_xml { |
60
|
4
|
|
|
4
|
1
|
589
|
my $self = shift; |
61
|
4
|
|
|
|
|
29
|
my $ref = Net::Lighthouse::Util->translate_from_xml( shift ); |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
# dirty hack: some attrs are read-only, and Mouse doesn't support |
64
|
|
|
|
|
|
|
# writer => '...' |
65
|
4
|
|
|
|
|
22
|
for my $k ( keys %$ref ) { |
66
|
32
|
|
|
|
|
255
|
$self->{$k} = $ref->{$k}; |
67
|
|
|
|
|
|
|
} |
68
|
4
|
|
|
|
|
26
|
return $self; |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
sub create { |
72
|
0
|
|
|
0
|
1
|
0
|
my $self = shift; |
73
|
0
|
|
|
|
|
0
|
validate( |
74
|
|
|
|
|
|
|
@_, |
75
|
|
|
|
|
|
|
{ |
76
|
|
|
|
|
|
|
revision => { type => SCALAR }, |
77
|
|
|
|
|
|
|
body => { type => SCALAR }, |
78
|
|
|
|
|
|
|
title => { type => SCALAR }, |
79
|
|
|
|
|
|
|
changes => { type => SCALAR }, |
80
|
|
|
|
|
|
|
changed_at => { type => SCALAR }, |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
); |
83
|
0
|
|
|
|
|
0
|
my %args = @_; |
84
|
|
|
|
|
|
|
|
85
|
0
|
|
|
|
|
0
|
my $xml = |
86
|
|
|
|
|
|
|
Net::Lighthouse::Util->translate_to_xml( \%args, root => 'changeset', ); |
87
|
|
|
|
|
|
|
|
88
|
0
|
|
|
|
|
0
|
my $ua = $self->ua; |
89
|
|
|
|
|
|
|
|
90
|
0
|
|
|
|
|
0
|
my $url = $self->base_url . '/projects/' . $self->project_id . '/changesets.xml'; |
91
|
|
|
|
|
|
|
|
92
|
0
|
|
|
|
|
0
|
my $request = HTTP::Request->new( 'POST', $url, undef, $xml ); |
93
|
0
|
|
|
|
|
0
|
my $res = $ua->request( $request ); |
94
|
0
|
0
|
|
|
|
0
|
if ( $res->is_success ) { |
95
|
0
|
|
|
|
|
0
|
$self->load_from_xml( $res->content ); |
96
|
0
|
|
|
|
|
0
|
return 1; |
97
|
|
|
|
|
|
|
} |
98
|
|
|
|
|
|
|
else { |
99
|
0
|
|
|
|
|
0
|
die "try to POST $url failed: " |
100
|
|
|
|
|
|
|
. $res->status_line . "\n" |
101
|
|
|
|
|
|
|
. $res->content; |
102
|
|
|
|
|
|
|
} |
103
|
|
|
|
|
|
|
} |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
sub delete { |
106
|
0
|
|
|
0
|
1
|
0
|
my $self = shift; |
107
|
0
|
|
|
|
|
0
|
my $ua = $self->ua; |
108
|
0
|
|
|
|
|
0
|
my $url = |
109
|
|
|
|
|
|
|
$self->base_url |
110
|
|
|
|
|
|
|
. '/projects/' |
111
|
|
|
|
|
|
|
. $self->project_id . '/changesets/' |
112
|
|
|
|
|
|
|
. $self->revision . '.xml'; |
113
|
|
|
|
|
|
|
|
114
|
0
|
|
|
|
|
0
|
my $request = HTTP::Request->new( 'DELETE', $url ); |
115
|
0
|
|
|
|
|
0
|
my $res = $ua->request( $request ); |
116
|
0
|
0
|
|
|
|
0
|
if ( $res->is_success ) { |
117
|
0
|
|
|
|
|
0
|
return 1; |
118
|
|
|
|
|
|
|
} |
119
|
|
|
|
|
|
|
else { |
120
|
0
|
|
|
|
|
0
|
die "try to DELETE $url failed: " |
121
|
|
|
|
|
|
|
. $res->status_line . "\n" |
122
|
|
|
|
|
|
|
. $res->content; |
123
|
|
|
|
|
|
|
} |
124
|
|
|
|
|
|
|
} |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
sub list { |
127
|
3
|
|
|
3
|
1
|
14432
|
my $self = shift; |
128
|
3
|
|
|
|
|
26
|
my $url = |
129
|
|
|
|
|
|
|
$self->base_url . '/projects/' . $self->project_id . '/changesets.xml'; |
130
|
3
|
|
|
|
|
19
|
my $ua = $self->ua; |
131
|
3
|
|
|
|
|
16
|
my $res = $ua->get($url); |
132
|
3
|
50
|
|
|
|
338
|
if ( $res->is_success ) { |
133
|
3
|
|
|
|
|
160
|
my $cs = |
134
|
|
|
|
|
|
|
Net::Lighthouse::Util->read_xml( $res->content )->{changesets}{changeset}; |
135
|
9
|
|
|
|
|
93
|
my @list = map { |
136
|
3
|
50
|
|
|
|
5303
|
my $t = Net::Lighthouse::Project::Changeset->new( |
137
|
9
|
|
|
|
|
37
|
map { $_ => $self->$_ } |
138
|
3
|
|
|
|
|
9
|
grep { $self->$_ } qw/account auth project_id/ |
139
|
|
|
|
|
|
|
); |
140
|
3
|
|
|
|
|
18
|
$t->load_from_xml($_); |
141
|
|
|
|
|
|
|
} ref $cs eq 'ARRAY' ? @$cs : $cs; |
142
|
3
|
100
|
|
|
|
35
|
return wantarray ? @list : \@list; |
143
|
|
|
|
|
|
|
} |
144
|
|
|
|
|
|
|
else { |
145
|
0
|
|
|
|
|
0
|
die "try to get $url failed: " |
146
|
|
|
|
|
|
|
. $res->status_line . "\n" |
147
|
|
|
|
|
|
|
. $res->content; |
148
|
|
|
|
|
|
|
} |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
} |
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
sub initial_state { |
153
|
1
|
|
|
1
|
1
|
2
|
my $self = shift; |
154
|
1
|
|
|
|
|
8
|
my $ua = $self->ua; |
155
|
1
|
|
|
|
|
6
|
my $url = |
156
|
|
|
|
|
|
|
$self->base_url . '/projects/' . $self->project_id . '/changesets/new.xml'; |
157
|
1
|
|
|
|
|
8
|
my $res = $ua->get( $url ); |
158
|
1
|
50
|
|
|
|
67
|
if ( $res->is_success ) { |
159
|
1
|
|
|
|
|
62
|
return Net::Lighthouse::Util->translate_from_xml( $res->content ); |
160
|
|
|
|
|
|
|
} |
161
|
|
|
|
|
|
|
else { |
162
|
0
|
|
|
|
|
|
die "try to get $url failed: " |
163
|
|
|
|
|
|
|
. $res->status_line . "\n" |
164
|
|
|
|
|
|
|
. $res->content; |
165
|
|
|
|
|
|
|
} |
166
|
|
|
|
|
|
|
} |
167
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
1; |
169
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
__END__ |