Make Project->heads an attribute.
Zachary Stevens [Thu, 12 Nov 2009 20:07:08 +0000 (20:07 +0000)]
lib/Gitalist/Controller/Root.pm
lib/Gitalist/Git/Project.pm
t/02git_project.t

index 60779e8..8a23613 100644 (file)
@@ -122,7 +122,7 @@ sub summary : Local {
   my $project = $c->stash->{Project};
   $c->detach('error_404') unless $project;
   my $commit = $self->_get_object($c);
-  my @heads  = $project->heads;
+  my @heads  = @{$project->heads};
   my $maxitems = Gitalist->config->{paging}{summary} || 10;
   $c->stash(
     commit    => $commit,
@@ -148,7 +148,7 @@ sub heads : Local {
   my $project = $c->stash->{Project};
   $c->stash(
     commit => $self->_get_object($c),
-    heads  => [$project->heads],
+    heads  => $project->heads,
     action => 'heads',
   );
 }
index 4862b46..853f0c5 100644 (file)
@@ -129,11 +129,13 @@ Return the sha1 for HEAD, or any specified head.
 
 =head2 heads
 
-Returns a list of hashes containing the name and sha1 of all heads.
+ArrayRef of hashes containing the name and sha1 of all heads.
 
 =cut
 
-    method heads {
+    has heads => ( isa => ArrayRef[HashRef], is => 'ro', lazy_build => 1);
+
+    method _build_heads {
         my @revlines = $self->run_cmd_list(qw/for-each-ref --sort=-committerdate /, '--format=%(objectname)%00%(refname)%00%(committer)', 'refs/heads');
         my @ret;
         for my $line (@revlines) {
@@ -150,12 +152,12 @@ Returns a list of hashes containing the name and sha1 of all heads.
             }
         }
 
-        return @ret;
+        return \@ret;
     }
 
 =head2 references
 
-Returns a hash of references.
+Hashref of ArrayRefs for each reference.
 
 =cut
 
index be0f9a6..90c8b38 100644 (file)
@@ -23,7 +23,10 @@ isa_ok($proj->last_change, 'DateTime', 'last_change');
 
 is($proj->info->{name}, qw/repo1/, 'repo name in info hash');
 
-my @heads = $proj->heads;
+my %references = %{$proj->references};
+ok(keys %references >= 2, '->references hash has elements');
+is($references{'36c6c6708b8360d7023e8a1649c45bcf9b3bd818'}->[0], 'heads/master', 'reference looks ok');
+my @heads = @{$proj->heads};
 ok(scalar @heads > 1, '->heads list has more than one element');
 my %head = %{$heads[1]};
 ok(keys %head == 3, '->heads[1] has the right number of keys');