File Coverage

blib/lib/Git/PurePerl/NewObject.pm
Criterion Covered Total %
statement 21 21 100.0
branch n/a
condition n/a
subroutine 7 7 100.0
pod 0 1 0.0
total 28 29 96.5


line stmt bran cond sub pod time code
1             package Git::PurePerl::NewObject;
2 4     4   17 use Moose;
  4         6  
  4         25  
3 4     4   16310 use MooseX::StrictConstructor;
  4         6  
  4         27  
4 4     4   7432 use Moose::Util::TypeConstraints;
  4         6  
  4         29  
5 4     4   4859 use namespace::autoclean;
  4         6  
  4         29  
6              
7             enum 'ObjectKind' => [qw(commit tree blob tag)];
8              
9             has 'kind' => ( is => 'ro', isa => 'ObjectKind', required => 1 );
10             has 'size' => ( is => 'ro', isa => 'Int', required => 0, lazy_build => 1 );
11             has 'content' => ( is => 'rw', isa => 'Str', required => 0, lazy_build => 1 );
12             has 'sha1' => ( is => 'ro', isa => 'Str', required => 0, lazy_build => 1 );
13              
14             sub _build_sha1 {
15 14     14   20 my $self = shift;
16 14         102 my $sha1 = Digest::SHA->new;
17 14         165 $sha1->add( $self->raw );
18 14         76 my $sha1_hex = $sha1->hexdigest;
19 14         352 return $sha1_hex;
20             }
21              
22             sub _build_size {
23 14     14   15 my $self = shift;
24 14         370 return length $self->content;
25             }
26              
27             sub raw {
28 28     28 0 29 my $self = shift;
29 28         832 return $self->kind . ' ' . $self->size . "\0" . $self->content;
30             }
31              
32             __PACKAGE__->meta->make_immutable;
33