Lighthouse/Project/Changeset.pm

filter: Statementstmt 68.9% 51 / 74 Branchbran 42.8% 6 / 14 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 80.0% 8 / 10 Podpod 100% 6 / 6 totaltotal 68.2% 71 / 104 CC 9 SCAR 11.4
CC
9
Cov
65%
create
6.0
delete
6.0
list
4.1
CRAP 3.1
« Lighthouse/Project/Message.pm ↑ Summary Lighthouse/Project.pm »
1 package Net::Lighthouse::Project::Changeset;
2 11 ▶use Any::Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 11 ▶use Params::Validate ':all';
Subroutine BEGIN: called CC=1 SCAR=0.0
4 11 ▶use Net::Lighthouse::Util;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 11 extends 'Net::Lighthouse::Base';
6 # read only attr
7  
8 11 has [qw/project_id user_id/] => (
9 isa => 'Int',
10 is => 'ro',
11 );
12  
13 11 has 'body_html' => (
14 isa => 'Maybe[Str]',
15 is => 'ro',
16 );
17  
18 # read&write attr
19 11 has 'changed_at' => (
20 isa => 'DateTime',
21 is => 'rw',
22 );
23  
24 11 has 'changes' => (
25 isa => 'ArrayRef',
26 is => 'rw',
27 auto_deref => 1,
28 );
29  
30 11 has [qw/body title revision/] => (
31 isa => 'Maybe[Str]',
32 is => 'rw',
33 );
34  
35 11 ▶no Any::Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
36 11 __PACKAGE__->meta->make_immutable;
37  
38 1 ▶sub load {
Subroutine load: called CC=2 SCAR=7.1
Pod documented
39 1 my $self = shift;
40 1 validate_pos( @_, { type => SCALAR, regex => qr/^\d+$/ } );
41 1 my $revision = shift;
42 1 my $ua = $self->ua;
43 1 my $url =
44 $self->base_url
45 . '/projects/'
46 . $self->project_id . '/changesets/'
47 . $revision . '.xml';
48 1 my $res = $ua->get( $url );
49 1 ▶ if ( $res->is_success ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($res->is_success) { } 1 0 1
50 1 $self->load_from_xml( $res->content );
51 }
52 else {
53 0 die "try to get $url failed: "
54 . $res->status_line . "\n"
55 . $res->content;
56 }
57 }
58  
59 4 ▶sub load_from_xml {
Subroutine load_from_xml: called CC=2 SCAR=6.9
Pod documented
60 4 my $self = shift;
61 4 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 for my $k ( keys %$ref ) {
66 32 $self->{$k} = $ref->{$k};
67 }
68 4 return $self;
69 }
70  
71 0 ▶sub create {
Subroutine create: not called CC=2 SCAR=17.9
Pod documented
72 0 my $self = shift;
73 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 my %args = @_;
84  
85 0 my $xml =
86 Net::Lighthouse::Util->translate_to_xml( \%args, root => 'changeset', );
87  
88 0 my $ua = $self->ua;
89  
90 0 my $url = $self->base_url . '/projects/' . $self->project_id . '/changesets.xml';
91  
92 0 my $request = HTTP::Request->new( 'POST', $url, undef, $xml );
93 0 my $res = $ua->request( $request );
94 0 ▶ if ( $res->is_success ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($res->is_success) { } 0 0 0
95 0 $self->load_from_xml( $res->content );
96 0 return 1;
97 }
98 else {
99 0 die "try to POST $url failed: "
100 . $res->status_line . "\n"
101 . $res->content;
102 }
103 }
104  
105 0 ▶sub delete {
Subroutine delete: not called CC=2 SCAR=17.9
Pod documented
106 0 my $self = shift;
107 0 my $ua = $self->ua;
108 0 my $url =
109 $self->base_url
110 . '/projects/'
111 . $self->project_id . '/changesets/'
112 . $self->revision . '.xml';
113  
114 0 my $request = HTTP::Request->new( 'DELETE', $url );
115 0 my $res = $ua->request( $request );
116 0 ▶ if ( $res->is_success ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($res->is_success) { } 0 0 0
117 0 return 1;
118 }
119 else {
120 0 die "try to DELETE $url failed: "
121 . $res->status_line . "\n"
122 . $res->content;
123 }
124 }
125  
126 3 ▶sub list {
Subroutine list: called CC=4 SCAR=14.0
Pod documented
127 3 my $self = shift;
128 3 my $url =
129 $self->base_url . '/projects/' . $self->project_id . '/changesets.xml';
130 3 my $ua = $self->ua;
131 3 my $res = $ua->get($url);
132 3 ▶ if ( $res->is_success ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($res->is_success) { } 3 0 3
133 my $cs =
134 3 Net::Lighthouse::Util->read_xml( $res->content )->{changesets}{changeset};
135 my @list = map {
136 3 my $t = Net::Lighthouse::Project::Changeset->new(
137 9 map { $_ => $self->$_ }
138 3 grep { $self->$_ } qw/account auth project_id/
139 );
140 3 ▶ $t->load_from_xml($_);
Branch: 1 branch
BranchTrueFalseTotal
ref $cs eq 'ARRAY' ? : 0 3 3
141 } ref $cs eq 'ARRAY' ? @$cs : $cs;
142 3 ▶ return wantarray ? @list : \@list;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 2 1 3
143 }
144 else {
145 0 die "try to get $url failed: "
146 . $res->status_line . "\n"
147 . $res->content;
148 }
149  
150 }
151  
152 1 ▶sub initial_state {
Subroutine initial_state: called CC=2 SCAR=7.1
Pod documented
153 1 my $self = shift;
154 1 my $ua = $self->ua;
155 1 my $url =
156 $self->base_url . '/projects/' . $self->project_id . '/changesets/new.xml';
157 1 my $res = $ua->get( $url );
158 1 ▶ if ( $res->is_success ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($res->is_success) { } 1 0 1
159 1 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 11 1;
169  
170 __END__
« Lighthouse/Project/Message.pm ↑ Summary Lighthouse/Project.pm »