Fixed failing Content-Type tests.
[catagits/Gitalist.git] / lib / Gitalist / Git / Repository.pm
index 986180a..0973a39 100644 (file)
@@ -3,28 +3,19 @@ use MooseX::Declare;
 class Gitalist::Git::Repository with Gitalist::Git::HasUtils {
     # FIXME, use Types::Path::Class and coerce
     use MooseX::Types::Common::String qw/NonEmptySimpleStr/;
-    use MooseX::Types::Path::Class qw/Dir/;
     use MooseX::Types::Moose qw/Str Maybe Bool HashRef ArrayRef/;
-    use Gitalist::Git::Types qw/SHA1/;
-    use MooseX::MultiMethods;
+    use Gitalist::Git::Types qw/SHA1 DateTime Dir/;
     use Moose::Autobox;
     use List::MoreUtils qw/any zip/;
-    use DateTime;
+    use aliased 'DateTime' => 'DT';
     use Encode qw/decode/;
-
-    use if $^O ne 'MSWin32', 'I18N::Langinfo', => qw/langinfo CODESET/;
-    BEGIN {
-        no strict 'subs';
-        *__owner = defined &langinfo
-            ? sub { map { decode(langinfo(CODESET), $_) } (getpwuid $_[0]->path->stat->uid)[6,0] }
-            : sub { return qw/OwnEr GroUp/ }
-        ;
-    }
-
+    use I18N::Langinfo qw/langinfo CODESET/;
     use Gitalist::Git::Object::Blob;
     use Gitalist::Git::Object::Tree;
     use Gitalist::Git::Object::Commit;
     use Gitalist::Git::Object::Tag;
+    
+    with 'Gitalist::Serializeable';
 
     our $SHA1RE = qr/[0-9a-fA-F]{40}/;
 
@@ -44,7 +35,8 @@ class Gitalist::Git::Repository with Gitalist::Git::HasUtils {
                   is => 'ro', required => 1 );
 
     has path => ( isa => Dir,
-                  is => 'ro', required => 1);
+                  is => 'ro', required => 1,
+                  traits => [qw/ DoNotSerialize /] );
 
     has description => ( isa => Str,
                          is => 'ro',
@@ -56,7 +48,7 @@ class Gitalist::Git::Repository with Gitalist::Git::HasUtils {
                    lazy_build => 1,
                );
 
-    has last_change => ( isa => Maybe['DateTime'],
+    has last_change => ( isa => Maybe[DateTime],
                          is => 'ro',
                          lazy_build => 1,
                      );
@@ -65,13 +57,15 @@ class Gitalist::Git::Repository with Gitalist::Git::HasUtils {
                      is => 'ro',
                      lazy => 1,
                      default => sub {
-                         -d $_[0]->path->parent->subdir->($_[0]->name)
+                         -d $_[0]->path->parent->subdir($_[0]->name)
                              ? 1 : 0
                          },
                      );
     has heads => ( isa => ArrayRef[HashRef],
                    is => 'ro',
-                   lazy_build => 1);
+                   lazy_build => 1,
+                   traits => [qw/ DoNotSerialize /],
+                   );
     has tags => ( isa => ArrayRef[HashRef],
                    is => 'ro',
                    lazy_build => 1);
@@ -80,19 +74,16 @@ class Gitalist::Git::Repository with Gitalist::Git::HasUtils {
                         lazy_build => 1 );
 
     method BUILD {
-        $self->$_() for qw/last_change owner description/; # Ensure to build early.
+        $self->$_() for qw/last_change owner description /; # Ensure to build early.
     }
 
     ## Public methods
 
-    multi method get_object_or_head (SHA1 $sha1) {
+    method get_object_or_head (NonEmptySimpleStr $ref) {
+        my $sha1 = is_SHA1($ref) ? $ref : $self->head_hash($ref);
         $self->get_object($sha1);
     }
-    multi method get_object_or_head (NonEmptySimpleStr $ref) {
-        my $sha1 = $self->head_hash($ref);
-        $self->get_object($sha1);
-    }    
-    
+
     method head_hash (Str $head?) {
         my $output = $self->run_cmd(qw/rev-parse --verify/, $head || 'HEAD' );
         confess("No such head: " . $head) unless defined $output;
@@ -144,7 +135,7 @@ class Gitalist::Git::Repository with Gitalist::Git::HasUtils {
             if !$sha1 || $sha1 !~ $SHA1RE;
 
         my @search_opts;
-        if ($search) {
+        if ($search and exists $search->{text}) {
             $search->{type} = 'grep'
                 if $search->{type} eq 'commit';
             @search_opts = (
@@ -262,7 +253,7 @@ class Gitalist::Git::Repository with Gitalist::Git::HasUtils {
     }
 
     method _build_owner {
-        my ($gecos, $name) = $self->__owner;
+        my ($gecos, $name) = map { decode(langinfo(CODESET), $_) } (getpwuid $self->path->stat->uid)[6,0];
         $gecos =~ s/,+$//;
         return length($gecos) ? $gecos : $name;
     }
@@ -274,7 +265,7 @@ class Gitalist::Git::Repository with Gitalist::Git::HasUtils {
                 --sort=-committerdate --count=1 refs/heads
           });
         if (my ($epoch, $tz) = $output =~ /\s(\d+)\s+([+-]\d+)$/) {
-            my $dt = DateTime->from_epoch(epoch => $epoch);
+            my $dt = DT->from_epoch(epoch => $epoch);
             $dt->set_time_zone($tz);
             $last_change = $dt;
         }
@@ -292,7 +283,7 @@ class Gitalist::Git::Repository with Gitalist::Git::HasUtils {
 
             #FIXME: That isn't the time I'm looking for..
             if (my ($epoch, $tz) = $line =~ /\s(\d+)\s+([+-]\d+)$/) {
-                my $dt = DateTime->from_epoch(epoch => $epoch);
+                my $dt = DT->from_epoch(epoch => $epoch);
                 $dt->set_time_zone($tz);
                 $ret[-1]->{last_change} = $dt;
             }
@@ -318,7 +309,7 @@ class Gitalist::Git::Repository with Gitalist::Git::HasUtils {
 
             #FIXME: That isn't the time I'm looking for..
             if($epoch and $tz) {
-                my $dt = DateTime->from_epoch(epoch => $epoch);
+                my $dt = DT->from_epoch(epoch => $epoch);
                 $dt->set_time_zone($tz);
                 $ret[-1]->{last_change} = $dt;
             }