Default ::Object attributes tree_sha1 and comment to '' when not present.
Zachary Stevens [Tue, 10 Nov 2009 02:11:52 +0000 (02:11 +0000)]
lib/Gitalist/Git/Object.pm
t/02git_object.t

index b47ab93..ff33b8d 100644 (file)
@@ -31,15 +31,27 @@ class Gitalist::Git::Object {
                       lazy_build => 1,
                       handles => [ 'parents',
                                    'parent_sha1',
-                                   'comment',
                                    'author',
                                    'authored_time',
                                    'committer',
                                    'committed_time',
-                                   'tree_sha1',
                                ],
                   );
 
+    # This feels wrong, but current templates assume
+    # these attributes are present on every object.
+    foreach my $key (qw/tree_sha1 comment/) {
+        has $key => ( isa => Str,
+                      required => 1,
+                      is => 'ro',
+                      lazy_build => 1,
+                  );
+        method "_build_$key" {
+            return '' unless $self->_gpp_obj->can($key);
+            return $self->_gpp_obj->$key;
+        }
+    }
+
     # objects can't determine their mode or filename
     has file => ( isa => NonEmptySimpleStr,
                   required => 0,
index 92b3710..898d8ac 100644 (file)
@@ -41,3 +41,5 @@ is($obj2->mode, 0, 'mode is correct');
 is($obj2->modestr, '?---------', "modestr is correct" );
 is($obj2->contents, "bar\n", 'obj2 contents is correct');
 is($obj2->size, 4, "size is correct");
+is($obj2->tree_sha1, '', 'tree_sha1 is an empty string');
+is($obj2->comments, '', 'comments is an empty string');