VCI/Abstract/Committable.pm

filter: Statementstmt 33.3% 19 / 57 Branchbran 0.0% 0 / 10 Conditioncond 0.0% 0 / 6 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 16.6% 2 / 12 Podpod n/a totaltotal 23.6% 21 / 89 CC 9 SCAR 21.7
CC
9
Cov
26%
_build_history
20.0
_me_from
12.0
_no_time_without_revision
12.0
CRAP 8.8
« VCI/VCS/Hg/Project.pm ↑ Summary VCI/Abstract/Diff.pm »
1 package VCI::Abstract::Committable;
2 4 ▶use Moose::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 4 ▶use VCI::Util;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 4 with 'VCI::Abstract::ProjectItem';
6  
7 4 has 'history' => (is => 'ro', isa => 'VCI::Abstract::History', lazy_build => 1);
8  
9 4 has 'first_revision' => (is => 'ro', does => 'VCI::Abstract::Committable',
10 lazy_build => 1);
11
12 4 has 'last_revision' => (is => 'ro', does => 'VCI::Abstract::Committable',
13 lazy_build => 1);
14  
15 4 has 'revision' => (is => 'ro', lazy_build => 1, predicate => '_has_revision');
16 4 has 'revno' => (is => 'ro', lazy_build => 1);
17 # All of this crazy init_arg stuff means "coerce lazily, because it's
18 # slow to make thousands of DateTime and Path::Abstract::Underload objects."
19 has 'time' => (is => 'ro', isa => 'VCI::Type::DateTime', coerce => 1,
20 lazy => 1,
21 0 ▶ default => sub { shift->_time }, init_arg => '__time');
Subroutine __ANON__: not called CC=1 SCAR=1.2
22 4 has '_time' => (is => 'ro', isa => 'Defined', init_arg => 'time',
23 lazy_build => 1, builder => '_build_time');
24 has 'path' => (is => 'ro', isa => 'VCI::Type::Path', coerce => 1,
25 lazy => 1,
26 0 ▶ default => sub { shift->_path }, init_arg => '__path');
Subroutine __ANON__: not called CC=1 SCAR=1.2
27 4 has '_path' => (is => 'ro', isa => 'Defined', required => 1,
28 init_arg => 'path');
29 has 'name' => (is => 'ro', isa => 'Str', lazy => 1,
30 0 ▶ default => sub { shift->path->last });
Subroutine __ANON__: not called CC=1 SCAR=1.2
31  
32 4 has 'parent' => (is => 'ro', does => 'VCI::Abstract::Committable',
33 lazy_build => 1);
34  
35 # Unfortunately Moose is a little dumb about Roles sometimes, and requires
36 # our *abstract* classes to implement these, instead of our subclasses. So
37 # we can't really require them.
38 # requires 'build_revision', 'build_time';
39  
40 0 ▶sub _build_first_revision {
Subroutine _build_first_revision: not called CC=1 SCAR=6.9
41 0 my $self = shift;
42 0 my $commit = $self->history->commits->[0];
43 0 return $self->_me_from($commit);
44 }
45  
46 0 ▶sub _build_last_revision {
Subroutine _build_last_revision: not called CC=1 SCAR=6.9
47 0 my $self = shift;
48 0 my $commit = $self->history->commits->[-1];
49 0 return $self->_me_from($commit);
50 }
51  
52 0 ▶sub _build_revno {
Subroutine _build_revno: not called CC=1 SCAR=6.9
53 0 my $self = shift;
54 0 my $commit = $self->project->get_commit(revision => $self->revision);
55 0 return $commit->revno;
56 }
57  
58 0 ▶sub _me_from {
Subroutine _me_from: not called CC=3 SCAR=24.8
59 0 my ($self, $commit) = @_;
60 0 ▶ my @item = grep {$_->path->stringify eq $self->path->stringify
Condition0%0/3
$_->path->stringify eq $self->path->stringify && $_->isa(builtin::blessed($self))
!ll&&!rl&&r
000
MC/DC0%0/2
$_->path->stringify eq $self->path->stringify && $_->isa(builtin::blessed($self))
$_->path->stringify eq $self->path->stringify $_->isa(builtin::blessed($self))
Truth table0%0/3
A && B
A= $_->path->stringify eq $self->path->stringifyB= $_->isa(builtin::blessed($self))
ABresult
0X0
100
111
61 # This assures we don't get a Directory if we're a File.
62 && $_->isa(blessed $self)}
63 0 @{$commit->contents};
64 0 ▶ warn("More than one item in the contents of commit "
Branch: 1 branch
BranchTrueFalseTotal
if scalar @item > 1 0 0 0
65 . $commit->revision . " with path " . $self->path)
66 if scalar @item > 1;
67 0 return $item[0];
68 }
69  
70 0 ▶sub _build_history {
Subroutine _build_history: not called CC=4 SCAR=30.0
71 0 my $self = shift;
72
73 0 my $current_path = $self->path->stringify;
74 0 my @commits;
75 # We go backwards in time to catch renames.
76 0 foreach my $commit (reverse @{ $self->project->history->commits }) {
77 0 my $in_contents = grep {$_->path->stringify eq $current_path}
78 0 @{$commit->contents};
79 0 ▶ push(@commits, $commit) if $in_contents;
Branch: 1 branch
BranchTrueFalseTotal
if $in_contents 0 0 0
80 # XXX Need to also track our history through copies.
81 0 ▶ if (exists $commit->moved->{$current_path}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $commit->moved->{$current_path}) 0 0 0
82 0 $current_path = $commit->moved->{$current_path}->path->stringify;
83 }
84 }
85
86 0 return $self->history_class->new(
87 commits => [reverse @commits],
88 project => $self->project,
89 );
90 }
91  
92 0 ▶sub _build_parent {
Subroutine _build_parent: not called CC=2 SCAR=17.9
93 0 my $self = shift;
94 0 my $path = $self->path;
95 0 ▶ return undef if $path->is_empty;
Branch: 1 branch
BranchTrueFalseTotal
if $path->is_empty 0 0 0
96  
97 0 my $parent_path = $self->path->parent;
98 0 return $self->project->get_path(path => $parent_path);
99 }
100  
101 #######################
102 # Implementor Helpers #
103 #######################
104  
105 0 ▶sub _no_time_without_revision {
Subroutine _no_time_without_revision: not called CC=3 SCAR=24.8
106 0 my $self = shift;
107 0 ▶ if (defined $self->{time} && !defined $self->{revision}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{"time"} and not defined $self->{"revision"}) 0 0 0
Condition0%0/3
defined $self->{"time"} and not defined $self->{"revision"}
!ll&&!rl&&r
000
MC/DC0%0/2
defined $self->{"time"} and not defined $self->{"revision"}
defined $self->{"time"} not defined $self->{"revision"}
Truth table0%0/3
A and not(B)
A= defined $self->{"time"}B= not defined $self->{"revision"}
ABresult
0X0
100
111
108 0 confess("You cannot build a Committable that has its time"
109 . " defined but not its revision");
110 }
111 }
112  
113 4 1;
114  
115 __END__
« VCI/VCS/Hg/Project.pm ↑ Summary VCI/Abstract/Diff.pm »