Lose some code by not converting to/from path::class objects, and also by flattening...
Tomas Doran [Fri, 6 Nov 2009 02:06:07 +0000 (02:06 +0000)]
lib/Gitalist/Git/Project.pm
lib/Gitalist/Git/Repo.pm
lib/Gitalist/Git/Util.pm

index df05ac1..de3f05f 100644 (file)
@@ -39,10 +39,9 @@ class Gitalist::Git::Project {
     }
 
     method _build__util {
-        my $util = Gitalist::Git::Util->new(
-            gitdir => $self->project_dir($self->path),
+        Gitalist::Git::Util->new(
+            gitdir => $self->path,
         );
-        return $util;
     }
 
     method _build_description {
@@ -120,14 +119,6 @@ The keys for each item will be:
         return @ret;
     }
 
-    # FIXME - Why not just stay in Path::Class land and return a P::C::D here?
-    method project_dir {
-        my $dir = $self->path->stringify;
-        $dir .= '/.git'
-            if -f dir($dir)->file('.git/HEAD');
-        return $dir;
-    }
-
     # Compatibility
 
 =head2 info
index 6470cbf..fe18e97 100644 (file)
@@ -16,7 +16,7 @@ C<git> repo.
 =cut
 
     method _is_git_repo ($dir) {
-        return -f $dir->file('HEAD') || -f $dir->file('.git/HEAD');
+        return -f $dir->file('HEAD') || -f $dir->file('.git', 'HEAD');
     }
 
 =head2 project_dir
@@ -26,14 +26,9 @@ The directory under which the given project will reside i.e C<.git/..>
 =cut
 
     method project_dir ($project) {
-        my $dir = blessed($project) && $project->isa('Path::Class::Dir')
-            ? $project->stringify
-                : $self->dir_from_project_name($project);
-
-        $dir .= '/.git'
-            if -f dir($dir)->file('.git/HEAD');
-
-        return $dir;
+        -f $project->file('.git', 'HEAD')
+            ? $project->subdir('.git')
+            : $project;
     }
 
 =head2 list_projects
@@ -54,12 +49,12 @@ each item will contain the contents of L</project_info>.
             next unless -d $obj;
             next unless $self->_is_git_repo($obj);
 
-            # XXX Leaky abstraction alert!
-            my $is_bare = !-d $obj->subdir('.git');
-
-            my $name = (File::Spec->splitdir($obj))[-1];
-            push @ret, Gitalist::Git::Project->new( name => $name,
-                                     path => $obj,
+            # FIXME - Is resolving project_dir here sane?
+            #         I think not, just pass $obj down, and
+            #         resolve $project->path and $project->is_bare
+            #         in BUILDARGS
+            push @ret, Gitalist::Git::Project->new( name => $file,
+                                     path => $self->project_dir($obj),
                                  );
         }
 
index 06b6d4d..d624c4d 100644 (file)
@@ -4,8 +4,7 @@ class Gitalist::Git::Util {
     use File::Which;
     use Git::PurePerl;
     use MooseX::Types::Common::String qw/NonEmptySimpleStr/;
-    use MooseX::Types::Moose qw/Str/;
-    has gitdir => ( isa => Str, is => 'ro', required => 1 );
+    has gitdir => ( isa => 'Path::Class::Dir', is => 'ro', required => 1 );
     has _git      => ( isa => NonEmptySimpleStr, is => 'ro', lazy_build => 1 );
     sub _build__git {
         my $git = File::Which::which('git');