class Gitalist::Git::Project {
# FIXME, use Types::Path::Class and coerce
use MooseX::Types::Common::String qw/NonEmptySimpleStr/;
+ use MooseX::Types::Moose qw/Str Maybe/;
use DateTime;
use Path::Class;
use Gitalist::Git::Util;
use aliased 'Gitalist::Git::Object';
our $SHA1RE = qr/[0-9a-fA-F]{40}/;
-
+
has name => ( isa => NonEmptySimpleStr,
- is => 'ro' );
+ is => 'ro', required => 1 );
has path => ( isa => "Path::Class::Dir",
- is => 'ro');
+ is => 'ro', required => 1);
- has description => ( isa => NonEmptySimpleStr,
+ has description => ( isa => Str,
is => 'ro',
lazy_build => 1,
);
is => 'ro',
lazy_build => 1,
);
- has last_change => ( isa => 'DateTime',
+ has last_change => ( isa => Maybe['DateTime'],
is => 'ro',
lazy_build => 1,
);
handles => [ 'run_cmd' ],
);
+ method BUILD {
+ $self->$_() for qw/_util last_change owner description/; # Ensure to build early.
+ }
+
method _build__util {
- my $util = Gitalist::Git::Util->new(
+ Gitalist::Git::Util->new(
gitdir => $self->path,
);
- return $util;
}
-
+
method _build_description {
- my $description = $self->path->file('description')->slurp;
- chomp $description;
+ my $description = "";
+ eval {
+ $description = $self->path->file('description')->slurp;
+ chomp $description;
+ };
return $description;
}
method _build_owner {
- my $owner = (getpwuid $self->path->stat->uid)[6];
- $owner =~ s/,+$//;
- return $owner;
+ my ($gecos, $name) = (getpwuid $self->path->stat->uid)[6,0];
+ $gecos =~ s/,+$//;
+ return length($gecos) ? $gecos : $name;
}
-
+
method _build_last_change {
my $last_change;
my $output = $self->run_cmd(
type => $type,
sha1 => $object,
file => $file,
+ project => $self,
);
}
return @ret;
}
-
- method project_dir (Path::Class::Dir $project) {
- my $dir = $project->stringify;
- $dir .= '/.git'
- if -f dir($dir)->file('.git/HEAD');
- return $dir;
- }
-
# Compatibility
-=head2 project_info
+=head2 info
Returns a hash containing properties of this project. The keys will
be:
=cut
- method project_info {
+ method info {
return {
name => $self->name,
description => $self->description,
last_change => $self->last_change,
};
};
-
+
} # end class