VCI/VCS/Svn/Committable.pm untested

filter: Statementstmt 0.0% 0 / 38 Branchbran 0.0% 0 / 8 Conditioncond 0.0% 0 / 6 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 0.0% 0 / 9 Podpod 0.0% 0 / 5 totaltotal 0.0% 0 / 70 CC 5 SCAR 15.0
CC
5
Cov
0%
BUILD
6.0
_build_history
6.0
_build_revision
6.0
CRAP 4.5
1 package VCI::VCS::Svn::Committable;
2 use Moose::Role;
3 use Moose::Util::TypeConstraints;
4  
5 use Path::Abstract::Underload;
6  
7 use VCI::Abstract::Committable;
8  
9 # We could make this not required and build it with $ctx->info, but I want
10 # it to be required right now to make sure I don't forget to add it while
11 # constructing objects.
12 has 'x_info' => (is => 'ro', isa => 'SVN_Info', lazy_build => 1);
13  
14 subtype 'SVN_Info'
15 => as 'Object'
16 => where { $_->isa('_p_svn_dirent_t') || $_->isa('_p_svn_info_t') };
17  
18 sub BUILD {
19 my $self = shift;
20 if (!defined $self->{x_info} && !defined $self->{revision}) {
21 confess("You must define x_info if you don't define revision");
22 }
23 }
24  
25 sub _build_history {
26 my ($self) = @_;
27 # We only use our custom implementation if the Project's History object
28 # doesn't already exist.
29 if (defined $self->project->{history}) {
30 return VCI::Abstract::Committable::_build_history(@_);
31 }
32
33 my $commits = $self->project->_x_get_commits(
34 path => Path::Abstract::Underload->new($self->project->name,
35 $self->path->stringify)->stringify);
36 return $self->history_class->new(commits => $commits,
37 project => $self->project);
38 }
39  
40 sub _build_revision {
41 my $info = shift->x_info;
42 if ($info->isa('_p_svn_info_t')) {
43 return $info->last_changed_rev;
44 }
45 return $info->created_rev;
46 }
47  
48 # SVN Returns times in microseconds.
49 sub _build_time {
50 my $info = shift->x_info;
51 if ($info->isa('_p_svn_info_t')) {
52 return $info->last_changed_date / 1000000.0;
53 }
54 return $info->time / 1000000.0;
55 }
56  
57 # This is mostly used to build "time" if you don't specify it during
58 # construction.
59 sub _build_x_info {
60 my $self = shift;
61 my $ctx = $self->vci->x_client;
62 my $info;
63 # XXX Need to check return for errors.
64 my $full_path = Path::Abstract::Underload->new($self->name, $self->path);
65 $ctx->info($self->repository->root . $full_path->stringify,
66 undef, $self->revision, sub { $info = $_[1] }, 0);
67 return $info;
68 }
69  
70 1;