VCI/VCS/Svn/Project.pm untested

filter: Statementstmt 0.0% 0 / 54 Branchbran 0.0% 0 / 6 Conditioncond 0.0% 0 / 12 MC/DCmcdc 0.0% 0 / 7 Subroutinesub 0.0% 0 / 8 Podpod 0.0% 0 / 3 totaltotal 0.0% 0 / 90 CC 2 SCAR 10.6
CC
2
Cov
0%
_build_root_directory
6.0
BUILD
2.0
_build_history
2.0
CRAP 2.9
1 package VCI::VCS::Svn::Project;
2 use Moose;
3 use MooseX::Method;
4  
5 use Path::Abstract::Underload;
6 use SVN::Core;
7  
8 # Class::MOP 0.75 has a bug in its XS module that makes get_commit_prototype
9 # below invisible unless we do this explicitly.
10 use VCI::Abstract::Project;
11  
12 extends 'VCI::Abstract::Project';
13  
14 sub BUILD {
15 my $self = shift;
16 $self->_name_never_ends_with_slash();
17 $self->_name_never_starts_with_slash();
18 }
19  
20 method 'get_commit' => named (VCI::Abstract::Project::get_commit_prototype()) =>
21 sub {
22 my $self = shift;
23 my $params = shift;
24  
25 # MooseX::Method always has a hash key for each parameter, even if they
26 # weren't passed by the caller.
27 delete $params->{$_} foreach (grep { !defined $params->{$_} } keys %$params);
28
29 # We only use our custom implementation if the History object
30 # doesn't already exist, and if we were just asked for a revision id.
31 if (!defined $self->{history} && defined $params->{revision}
32 && keys(%$params) == 1)
33 {
34 my $commits = $self->_x_get_commits(
35 start => $params->{revision}, end => $params->{revision},
36 limit => 1);
37 return $commits->[0];
38 }
39
40 unshift(@_, $params);
41 return $self->SUPER::get_commit(@_);
42 };
43  
44 # We need a dirent for the root directory, so we have to override the
45 # default build_root_directory.
46 sub _build_root_directory {
47 my $self = shift;
48 # XXX Probably should use x_ra.
49 my $ctx = $self->vci->x_client;
50 my $info;
51 # Getting the root_directory of the root_project only works if there's
52 # no slash on the end of the URL.
53 my $name = $self->name eq '' ? '' : ('/' . $self->name);
54 $ctx->info($self->repository->x_root_noslash . $name, undef,
55 'HEAD', sub { $info = $_[1] }, 0);
56 return $self->directory_class->new(
57 path => '', project => $self, x_info => $info);
58 }
59  
60 sub _build_history {
61 my $self = shift;
62 my $commits = $self->_x_get_commits();
63 return $self->history_class->new(commits => $commits, project => $self);
64 }
65  
66 method '_x_get_commits' => named (
67 start => { isa => 'Int', default => 0 },
68 end => { isa => 'Int' },
69 limit => { isa => 'Int', default => 0 },
70 path => { isa => 'Str' },
71 ) => sub {
72 my ($self, $params) = @_;
73 my $ra = $self->repository->x_ra;
74 $params->{path} ||= $self->name;
75 $params->{end} ||= $ra->get_latest_revnum;
76  
77 my @commits;
78 if ($self->vci->debug) {
79 print STDERR "Calling get_log for $params->{path}"
80 . " START: $params->{start} END: $params->{end}\n";
81 }
82 $ra->get_log([$params->{path}], $params->{start}, $params->{end},
83 # discover_changed_paths, strict_node_history
84 $params->{limit}, 1, 0,
85 sub { push(@commits, $self->commit_class->x_from_log($self, @_)) });
86 return \@commits;
87 };
88  
89 __PACKAGE__->meta->make_immutable;
90  
91 1;