blib/lib/Pinto/Schema/Result/Revision.pm

filter: Statementstmt 67.2% 113 / 168 Branchbran 18.1% 4 / 22 Conditioncond 46.3% 19 / 41 MC/DCmcdc 16.0% 4 / 25 Subroutinesub 64.5% 31 / 48 Podpod 0.0% 0 / 18 totaltotal 53.1% 171 / 322 CC 28 SCAR 16.4
CC
28
Cov
59%
numeric_compare
20.0
is_ancestor_of
12.0
is_descendant_of
12.0
CRAP 5.1
« blib/lib/Pinto/Schema/Result/Package.pm ↑ Summary blib/lib/Pinto/Locator/Multiplex.pm »
1 63 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
2  
3 package Pinto::Schema::Result::Revision;
4  
5 # Created by DBIx::Class::Schema::Loader
6 # DO NOT MODIFY THE FIRST PART OF THIS FILE
7  
8  
9 63 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 63 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 63 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 63 ▶use MooseX::NonMoose;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 63 ▶use MooseX::MarkAsMethods autoclean => 1;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 63 extends 'DBIx::Class::Core';
16  
17  
18 63 __PACKAGE__->table("revision");
19  
20  
21 63 __PACKAGE__->add_columns(
22 "id", { data_type => "integer", is_auto_increment => 1, is_nullable => 0 },
23 "uuid", { data_type => "text", is_nullable => 0 },
24 "message", { data_type => "text", is_nullable => 0 },
25 "username", { data_type => "text", is_nullable => 0 },
26 "utc_time", { data_type => "integer", is_nullable => 0 },
27 "time_offset", { data_type => "integer", is_nullable => 0 },
28 "is_committed", { data_type => "boolean", is_nullable => 0 },
29 "has_changes", { data_type => "boolean", is_nullable => 0 },
30 );
31  
32  
33 63 __PACKAGE__->set_primary_key("id");
34  
35  
36 63 __PACKAGE__->add_unique_constraint( "uuid_unique", ["uuid"] );
37  
38  
39 63 __PACKAGE__->has_many(
40 "ancestry_children", "Pinto::Schema::Result::Ancestry",
41 { "foreign.child" => "self.id" }, { cascade_copy => 0, cascade_delete => 0 },
42 );
43  
44  
45 63 __PACKAGE__->has_many(
46 "ancestry_parents", "Pinto::Schema::Result::Ancestry",
47 { "foreign.parent" => "self.id" }, { cascade_copy => 0, cascade_delete => 0 },
48 );
49  
50  
51 63 __PACKAGE__->has_many(
52 "registrations", "Pinto::Schema::Result::Registration",
53 { "foreign.revision" => "self.id" }, { cascade_copy => 0, cascade_delete => 0 },
54 );
55  
56  
57 63 __PACKAGE__->has_many(
58 "stacks",
59 "Pinto::Schema::Result::Stack",
60 { "foreign.head" => "self.id" },
61 { cascade_copy => 0, cascade_delete => 0 },
62 );
63  
64  
65 63 with 'Pinto::Role::Schema::Result';
66  
67 # Created by DBIx::Class::Schema::Loader v0.07033 @ 2013-03-07 12:56:52
68 # DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:u3EeZBioyg8H9+azCHQYNA
69  
70 #------------------------------------------------------------------------------
71  
72 # ABSTRACT: Represents a set of changes to a stack
73  
74 #------------------------------------------------------------------------------
75  
76 63 our $VERSION = '0.14'; # VERSION
77  
78 #------------------------------------------------------------------------------
79  
80 63 ▶use MooseX::Types::Moose qw(Str Bool);
Subroutine BEGIN: called CC=1 SCAR=0.0
81  
82 63 ▶use DateTime;
Subroutine BEGIN: called CC=1 SCAR=0.0
83 63 ▶use DateTime::TimeZone;
Subroutine BEGIN: called CC=1 SCAR=0.0
84 63 ▶use DateTime::TimeZone::OffsetOnly;
Subroutine BEGIN: called CC=1 SCAR=0.0
85 63 ▶use String::Format;
Subroutine BEGIN: called CC=1 SCAR=0.0
86 63 ▶use Digest::SHA;
Subroutine BEGIN: called CC=1 SCAR=0.0
87  
88 63 ▶use Pinto::Util qw(:all);
Subroutine BEGIN: called CC=1 SCAR=0.0
89  
90 63 ▶use overload (
Subroutine BEGIN: called CC=1 SCAR=0.0
91 63 '""' => 'to_string',
92 '<=>' => 'numeric_compare',
93 'cmp' => 'numeric_compare',
94 'eq' => 'equals'
95 63 );
96  
97 #------------------------------------------------------------------------------
98  
99 has uuid_prefix => (
100 is => 'ro',
101 isa => Str,
102 532 ▶ default => sub { substr( $_[0]->uuid, 0, 8 ) },
Subroutine __ANON__: called CC=1 SCAR=0.0
103 63 init_arg => undef,
104 lazy => 1,
105 );
106  
107 has message_title => (
108 is => 'ro',
109 isa => Str,
110 0 ▶ default => sub { trim_text( title_text( $_[0]->message ) ) },
Subroutine __ANON__: not called CC=1 SCAR=6.9
111 63 init_arg => undef,
112 lazy => 1,
113 );
114  
115 has message_body => (
116 is => 'ro',
117 isa => Str,
118 0 ▶ default => sub { trim_text( body_text( $_[0]->message ) ) },
Subroutine __ANON__: not called CC=1 SCAR=6.9
119 63 init_arg => undef,
120 lazy => 1,
121 );
122  
123 has is_root => (
124 is => 'ro',
125 isa => Bool,
126 6 ▶ default => sub { $_[0]->id == 1 },
Subroutine __ANON__: called CC=1 SCAR=0.0
127 63 init_arg => undef,
128 lazy => 1,
129 );
130  
131 has datetime => (
132 is => 'ro',
133 isa => 'DateTime',
134 0 ▶ default => sub { DateTime->from_epoch( epoch => $_[0]->utc_time ) },
Subroutine __ANON__: not called CC=1 SCAR=6.9
135 63 init_arg => undef,
136 lazy => 1,
137 );
138  
139 has datetime_local => (
140 is => 'ro',
141 isa => 'DateTime',
142 3 ▶ default => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
143 3 my $tz = DateTime::TimeZone->offset_as_string( $_[0]->repo->config->time_offset );
144 3 return DateTime->from_epoch( epoch => $_[0]->utc_time, time_zone => $tz );
145 },
146 63 init_arg => undef,
147 lazy => 1,
148 );
149  
150 has datetime_user => (
151 is => 'ro',
152 isa => 'DateTime',
153 0 ▶ default => sub { DateTime->from_epoch( epoch => $_[0]->utc_time, time_zone => $_[0]->time_zone ) },
Subroutine __ANON__: not called CC=1 SCAR=6.9
154 63 init_arg => undef,
155 lazy => 1,
156 );
157  
158 has time_zone => (
159 is => 'ro',
160 isa => 'DateTime::TimeZone',
161 0 ▶ default => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
162 0 my $offset = DateTime::TimeZone->offset_as_string( $_[0]->time_offset );
163 0 return DateTime::TimeZone::OffsetOnly->new( offset => $offset );
164 },
165 63 init_arg => undef,
166 lazy => 1,
167 );
168  
169 #------------------------------------------------------------------------------
170  
171 136 ▶sub FOREIGNBUILDARGS {
Subroutine FOREIGNBUILDARGS: called CC=9 SCAR=22.8
Pod undocumented
172 136 my ( $class, $args ) = @_;
173  
174 136 ▶ $args ||= {};
Condition50%1/2
$args ||= {}
l!l
1360
MC/DC0%0/1
$args ||= {}
$args
Truth table50%1/2
A
A= $args
Aresult
11
00
175 136 ▶ $args->{uuid} ||= uuid();
Condition66%2/3
$args->{"uuid"} ||= uuid()
l!l&&r!l&&!r
70660
MC/DC0%0/2
$args->{"uuid"} ||= uuid()
$args->{"uuid"} uuid()
Truth table66%2/3
A ||= B
A= $args->{"uuid"}B= uuid()
ABresult
1X1
011
000
176 136 ▶ $args->{username} ||= '';
Condition50%1/2
$args->{"username"} ||= ""
l!l
0136
MC/DC0%0/1
$args->{"username"} ||= ""
$args->{"username"}
Truth table50%1/2
A
A= $args->{"username"}
Aresult
11
00
177 136 ▶ $args->{utc_time} ||= current_utc_time();
Condition66%2/3
$args->{"utc_time"} ||= current_utc_time()
l!l&&r!l&&!r
01342
MC/DC50%1/2
$args->{"utc_time"} ||= current_utc_time()
$args->{"utc_time"} current_utc_time()
Truth table66%2/3
A ||= B
A= $args->{"utc_time"}B= current_utc_time()
ABresult
1X1
011
000
178 136 ▶ $args->{time_offset} ||= 0;
Condition50%1/2
$args->{"time_offset"} ||= 0
l!l
0136
MC/DC0%0/1
$args->{"time_offset"} ||= 0
$args->{"time_offset"}
Truth table50%1/2
A
A= $args->{"time_offset"}
Aresult
11
00
179 136 ▶ $args->{is_committed} ||= 0;
Condition100%2/2
$args->{"is_committed"} ||= 0
l!l
7066
MC/DC100%1/1
$args->{"is_committed"} ||= 0
$args->{"is_committed"}
Truth table100%2/2
A
A= $args->{"is_committed"}
Aresult
11
00
180 136 ▶ $args->{has_changes} ||= 0;
Condition50%1/2
$args->{"has_changes"} ||= 0
l!l
0136
MC/DC0%0/1
$args->{"has_changes"} ||= 0
$args->{"has_changes"}
Truth table50%1/2
A
A= $args->{"has_changes"}
Aresult
11
00
181 136 ▶ $args->{message} ||= '';
Condition100%2/2
$args->{"message"} ||= ""
l!l
7066
MC/DC100%1/1
$args->{"message"} ||= ""
$args->{"message"}
Truth table100%2/2
A
A= $args->{"message"}
Aresult
11
00
182  
183 136 return $args;
184 }
185  
186 #------------------------------------------------------------------------------
187  
188 66 ▶sub add_parent {
Subroutine add_parent: called CC=1 SCAR=0.0
Pod undocumented
189 66 my ( $self, $parent ) = @_;
190  
191 # TODO: Figure out how to do merges
192 66 $self->create_related( ancestry_children => { parent => $parent->id } );
193  
194 66 return;
195 }
196  
197 #------------------------------------------------------------------------------
198  
199 0 ▶sub add_child {
Subroutine add_child: not called CC=1 SCAR=6.9
Pod undocumented
200 0 my ( $self, $child ) = @_;
201  
202 # TODO: Figure out how to do merges
203 0 $self->create_related( ancestry_parents => { child => $child->id } );
204  
205 0 return;
206 }
207  
208 #------------------------------------------------------------------------------
209  
210 4 ▶sub parents {
Subroutine parents: called CC=1 SCAR=0.0
Pod undocumented
211 4 my ($self) = @_;
212  
213 4 my $where = { child => $self->id };
214 4 my $attrs = { join => 'ancestry_parents', order_by => 'me.utc_time' };
215  
216 4 return $self->result_source->resultset->search( $where, $attrs )->all;
217 }
218  
219 #------------------------------------------------------------------------------
220  
221 0 ▶sub children {
Subroutine children: not called CC=1 SCAR=6.9
Pod undocumented
222 0 my ($self) = @_;
223  
224 0 my $where = { parent => $self->id };
225 0 my $attrs = { join => 'ancestry_children', order_by => 'me.utc_time' };
226  
227 0 return $self->result_source->resultset->search( $where, $attrs )->all;
228 }
229  
230 #------------------------------------------------------------------------------
231  
232 0 ▶sub is_ancestor_of {
Subroutine is_ancestor_of: not called CC=3 SCAR=24.8
Pod undocumented
233 0 my ($self, $rev) = @_;
234  
235 0 my @ancestors = $rev->parents;
236 0 ▶ while (my $ancestor = pop @ancestors) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $ancestor = pop @ancestors) 0 0 0
237 0 ▶ return 1 if $ancestor->id == $self->id;
Branch: 1 branch
BranchTrueFalseTotal
if $ancestor->id == $self->id 0 0 0
238 0 push @ancestors, $ancestor->parents;
239 }
240  
241 0 return 0;
242 }
243  
244 #------------------------------------------------------------------------------
245  
246 0 ▶sub is_descendant_of {
Subroutine is_descendant_of: not called CC=3 SCAR=24.8
Pod undocumented
247 0 my ($self, $rev) = @_;
248  
249 0 my @descendants = $rev->children;
250 0 ▶ while (my $descendant = pop @descendants) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $descendant = pop @descendants) 0 0 0
251 0 ▶ return 1 if $descendant->id == $self->id;
Branch: 1 branch
BranchTrueFalseTotal
if $descendant->id == $self->id 0 0 0
252 0 push @descendants, $descendant->children;
253 }
254  
255 0 return 0;
256 }
257  
258 #------------------------------------------------------------------------------
259  
260 0 ▶sub distributions {
Subroutine distributions: not called CC=1 SCAR=6.9
Pod undocumented
261 0 my ($self) = @_;
262  
263 0 my $rev_id = $self->id;
264 0 my $subquery = "SELECT DISTINCT distribution FROM registration WHERE revision = $rev_id";
265 0 my $where = { 'me.id' => { in => \$subquery } };
266 0 my $attrs = { order_by => 'archive' };
267  
268 0 return $self->result_source->schema->search_distribution( $where, $attrs );
269 }
270  
271 #------------------------------------------------------------------------------
272  
273 0 ▶sub packages {
Subroutine packages: not called CC=1 SCAR=6.9
Pod undocumented
274 0 my ($self) = @_;
275  
276 0 my $rev_id = $self->id;
277 0 my $subquery = "SELECT package FROM registration WHERE revision = $rev_id";
278 0 my $where = { 'me.id' => { in => \$subquery } };
279 0 my $attrs = { order_by => 'name' };
280  
281 0 return $self->result_source->schema->search_package( $where, $attrs );
282 }
283  
284 #------------------------------------------------------------------------------
285  
286 58 ▶sub commit {
Subroutine commit: called CC=5 SCAR=17.4
Pod undocumented
287 58 my ( $self, %args ) = @_;
288  
289 58 ▶ throw "Must specify a message to commit" if not $args{message};
Branch: 1 branch
BranchTrueFalseTotal
unless $args{"message"} 0 58 58
290  
291 58 $args{is_committed} = 1;
292 58 $args{has_changes} = 0; # XXX: Why reset this?
293 58 ▶ $args{username} ||= $self->repo->config->username;
Condition66%2/3
$args{"username"} ||= $self->repo->config->username
l!l&&r!l&&!r
0553
MC/DC50%1/2
$args{"username"} ||= $self->repo->config->username
$args{"username"} $self->repo->config->username
Truth table66%2/3
A ||= B
A= $args{"username"}B= $self->repo->config->username
ABresult
1X1
011
000
294 55 ▶ $args{time_offset} ||= $self->repo->config->time_offset;
Condition33%1/3
$args{"time_offset"} ||= $self->repo->config->time_offset
l!l&&r!l&&!r
0055
MC/DC0%0/2
$args{"time_offset"} ||= $self->repo->config->time_offset
$args{"time_offset"} $self->repo->config->time_offset
Truth table33%1/3
A ||= B
A= $args{"time_offset"}B= $self->repo->config->time_offset
ABresult
1X1
011
000
295 2 ▶ $args{utc_time} ||= current_utc_time;
Condition33%1/3
$args{"utc_time"} ||= current_utc_time()
l!l&&r!l&&!r
002
MC/DC0%0/2
$args{"utc_time"} ||= current_utc_time()
$args{"utc_time"} current_utc_time()
Truth table33%1/3
A ||= B
A= $args{"utc_time"}B= current_utc_time()
ABresult
1X1
011
000
296  
297 2 $self->update( \%args );
298  
299 2 return $self;
300 }
301  
302 #------------------------------------------------------------------------------
303  
304 183 ▶sub assert_is_open {
Subroutine assert_is_open: called CC=2 SCAR=7.1
Pod undocumented
305 183 my ($self) = @_;
306  
307 # TODO: mark column dirty rather than refresh whole object.
308 183 ▶ throw "PANIC: Revision $self is already committed"
Branch: 1 branch
BranchTrueFalseTotal
if $self->refresh->get_column("is_committed") 0 183 183
309 if $self->refresh->get_column('is_committed');
310  
311 183 return $self;
312 }
313  
314 #-------------------------------------------------------------------------------
315  
316 68 ▶sub assert_is_committed {
Subroutine assert_is_committed: called CC=2 SCAR=7.1
Pod undocumented
317 68 my ($self) = @_;
318  
319 # TODO: mark column dirty rather than refresh whole object.
320 68 ▶ throw "PANIC: Revision $self is still open"
Branch: 1 branch
BranchTrueFalseTotal
unless $self->refresh->get_column("is_committed") 0 68 68
321 if not $self->refresh->get_column('is_committed');
322  
323 68 return $self;
324 }
325  
326 #-------------------------------------------------------------------------------
327  
328 58 ▶sub assert_has_changed {
Subroutine assert_has_changed: called CC=2 SCAR=7.1
Pod undocumented
329 58 my ($self) = @_;
330  
331 # TODO: mark column dirty rather than refresh whole object.
332 58 ▶ throw "PANIC: Revision $self has not changed"
Branch: 1 branch
BranchTrueFalseTotal
unless $self->refresh->get_column("has_changes") 0 58 58
333 if not $self->refresh->get_column('has_changes');
334  
335 58 return $self;
336 }
337  
338 #------------------------------------------------------------------------------
339  
340 0 ▶sub diff {
Subroutine diff: not called CC=2 SCAR=17.9
Pod undocumented
341 0 my ( $self, $other ) = @_;
342  
343 0 ▶ my $left = $other || ( $self->parents )[0];
Condition0%0/3
$other || ($self->parents)[0]
l!l&&r!l&&!r
000
MC/DC0%0/2
$other || ($self->parents)[0]
$other ($self->parents)[0]
Truth table0%0/3
A || B
A= $otherB= ($self->parents)[0]
ABresult
1X1
011
000
344 0 my $right = $self;
345  
346 0 require Pinto::Difference;
347 0 return Pinto::Difference->new( left => $left, right => $right );
348 }
349  
350 #------------------------------------------------------------------------------
351  
352 0 ▶sub numeric_compare {
Subroutine numeric_compare: not called CC=4 SCAR=30.0
Pod undocumented
353 0 my ( $revision_a, $revision_b ) = @_;
354  
355 0 my $pkg = __PACKAGE__;
356 0 ▶ throw "Can only compare $pkg objects"
Branch: 1 branch
BranchTrueFalseTotal
unless itis($revision_a, $pkg) and itis($revision_b, $pkg) 0 0 0
Condition0%0/3
itis($revision_a, $pkg) and itis($revision_b, $pkg)
!ll&&!rl&&r
000
MC/DC0%0/2
itis($revision_a, $pkg) and itis($revision_b, $pkg)
itis($revision_a, $pkg) itis($revision_b, $pkg)
Truth table0%0/3
A and B
A= itis($revision_a, $pkg)B= itis($revision_b, $pkg)
ABresult
0X0
100
111
357 if not( itis( $revision_a, $pkg ) && itis( $revision_b, $pkg ) );
358  
359 0 ▶ return 0 if $revision_a->id == $revision_b->id;
Branch: 1 branch
BranchTrueFalseTotal
if $revision_a->id == $revision_b->id 0 0 0
360  
361 0 my $r = ( $revision_a->utc_time <=> $revision_b->utc_time );
362  
363 0 return $r;
364 }
365  
366 #------------------------------------------------------------------------------
367  
368 0 ▶sub equals {
Subroutine equals: not called CC=3 SCAR=24.8
Pod undocumented
369 0 my ( $revision_a, $revision_b ) = @_;
370  
371 0 my $pkg = __PACKAGE__;
372 0 ▶ throw "Can only compare $pkg objects"
Branch: 1 branch
BranchTrueFalseTotal
unless itis($revision_a, $pkg) and itis($revision_b, $pkg) 0 0 0
Condition0%0/3
itis($revision_a, $pkg) and itis($revision_b, $pkg)
!ll&&!rl&&r
000
MC/DC0%0/2
itis($revision_a, $pkg) and itis($revision_b, $pkg)
itis($revision_a, $pkg) itis($revision_b, $pkg)
Truth table0%0/3
A and B
A= itis($revision_a, $pkg)B= itis($revision_b, $pkg)
ABresult
0X0
100
111
373 if not( itis( $revision_a, $pkg ) && itis( $revision_b, $pkg ) );
374  
375 0 return $revision_a->id == $revision_b->id;
376 }
377  
378 #------------------------------------------------------------------------------
379  
380 541 ▶sub to_string {
Subroutine to_string: called CC=2 SCAR=7.4
Pod undocumented
381 541 my ( $self, $format ) = @_;
382  
383 my %fspec = (
384 535 ▶ i => sub { $self->uuid_prefix },
Subroutine __ANON__: called CC=1 SCAR=0.0
385 3 ▶ I => sub { $self->uuid },
Subroutine __ANON__: called CC=1 SCAR=0.0
386 3 ▶ j => sub { $self->username },
Subroutine __ANON__: called CC=1 SCAR=0.0
387 3 ▶ u => sub { $self->datetime_local->strftime( $_[0] || '%c' ) },
Subroutine __ANON__: called CC=2 SCAR=7.6
Condition50%1/2
$_[0] || '%c'
l!l
03
MC/DC0%0/1
$_[0] || '%c'
$_[0]
Truth table50%1/2
A
A= $_[0]
Aresult
11
00
388 0 ▶ g => sub { $self->message_body },
Subroutine __ANON__: not called CC=1 SCAR=6.9
389 3 ▶ G => sub { indent_text( trim_text( $self->message ), $_[0] ) },
Subroutine __ANON__: called CC=1 SCAR=0.0
390 0 ▶ t => sub { $self->message_title },
Subroutine __ANON__: not called CC=1 SCAR=6.9
391 0 ▶ T => sub { truncate_text( $self->message_title, $_[0] ) },
Subroutine __ANON__: not called CC=1 SCAR=6.9
392 541 );
393  
394 541 ▶ $format ||= $self->default_format;
Condition66%2/3
$format ||= $self->default_format
l!l&&r!l&&!r
65350
MC/DC0%0/2
$format ||= $self->default_format
$format $self->default_format
Truth table66%2/3
A ||= B
A= $formatB= $self->default_format
ABresult
1X1
011
000
395 541 return String::Format::stringf( $format, %fspec );
396 }
397  
398 #-------------------------------------------------------------------------------
399  
400 535 ▶sub default_format {
Subroutine default_format: called CC=1 SCAR=0.0
Pod undocumented
401 535 my ($self) = @_;
402  
403 535 return '%i';
404 }
405  
406 #------------------------------------------------------------------------------
407  
408 63 __PACKAGE__->meta->make_immutable;
409  
410 #------------------------------------------------------------------------------
411 63 1;
412  
413 __END__
« blib/lib/Pinto/Schema/Result/Package.pm ↑ Summary blib/lib/Pinto/Locator/Multiplex.pm »