--- /dev/null
+package Gitalist::Git::HasUtils;
+use Moose::Role;
+use Gitalist::Git::Util;
+use namespace::autoclean;
+
+sub BUILD {}
+after BUILD => sub {
+ my $self = shift;
+ # Force value build. A little convoluted as we don't have an accessor :)
+ $self->_util;
+};
+
+has _util => ( isa => 'Gitalist::Git::Util',
+ is => 'ro',
+ lazy_build => 1,
+ handles => [ 'run_cmd', 'get_gpp_object' ],
+ );
+
+sub _build__util { confess(shift() . " cannot build _util") }
+
+1;
use MooseX::Declare;
-class Gitalist::Git::Project {
+class Gitalist::Git::Project with Gitalist::Git::HasUtils {
# FIXME, use Types::Path::Class and coerce
use MooseX::Types::Common::String qw/NonEmptySimpleStr/;
use MooseX::Types::Moose qw/Str Maybe Bool HashRef/;
use DateTime;
use MooseX::Types::Path::Class qw/Dir/;
use List::MoreUtils qw/any zip/;
- use Gitalist::Git::Util;
use aliased 'Gitalist::Git::Object';
our $SHA1RE = qr/[0-9a-fA-F]{40}/;
is => 'ro',
lazy_build => 1,
);
- has _util => ( isa => 'Gitalist::Git::Util',
- is => 'ro',
- lazy_build => 1,
- handles => [ 'run_cmd', 'get_gpp_object' ],
- );
has project_dir => ( isa => Dir,
is => 'ro',
);
method BUILD {
- $self->$_() for qw/_util last_change owner description/; # Ensure to build early.
+ $self->$_() for qw/last_change owner description/; # Ensure to build early.
}
method _project_dir {
use MooseX::Declare;
-class Gitalist::Git::Repo {
+class Gitalist::Git::Repo with Gitalist::Git::HasUtils {
use MooseX::Types::Common::String qw/NonEmptySimpleStr/;
use MooseX::Types::Path::Class qw/Dir/;
use MooseX::Types::Moose qw/ArrayRef/;
- use Gitalist::Git::Project;
+ use aliased 'Gitalist::Git::Project';
+
+ # FIXME - this is nasty as we build the Git::Utils thing without a project name
+ # should refactor or something?
+ method _build__util {
+ Gitalist::Git::Util->new();
+ }
+
has repo_dir => (
isa => Dir,
is => 'ro',
);
method project (NonEmptySimpleStr $project) {
- return Gitalist::Git::Project->new(
+ return Project->new(
name => $project,
path => $self->repo_dir->subdir($project),
);
next unless -d $obj;
next unless $self->_is_git_repo($obj);
- push @ret, Gitalist::Git::Project->new(
- name => $file,
- path => $obj,
- );
+ push @ret, $self->project($file);
}
return [sort { $a->name cmp $b->name } @ret];
handles => { gitdir => 'project_dir' },
is => 'bare', # No accessor
weak_ref => 1, # Weak, you have to hold onto me.
+ predicate => 'has_project',
);
has _git => ( isa => NonEmptySimpleStr, is => 'ro', lazy_build => 1 );
sub _build__git {
has _gpp => (
isa => 'Git::PurePerl', is => 'ro', lazy => 1,
- default => sub { Git::PurePerl->new(gitdir => shift->gitdir) },
+ default => sub {
+ my $self = shift;
+ confess("Cannot get gpp without project")
+ unless $self->has_project;
+ Git::PurePerl->new(gitdir => $self->gitdir);
+ },
);
method run_cmd (@args) {
- unshift @args, ( '--git-dir' => $self->gitdir );
+ unshift @args, ( '--git-dir' => $self->gitdir )
+ if $self->has_project;
# print STDERR 'RUNNING: ', $self->_git, qq[ @args], $/;
open my $fh, '-|', $self->_git, @args