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   15 use Moose;
  4         5  
  4         21  
3 4     4   16071 use MooseX::StrictConstructor;
  4         5  
  4         25  
4 4     4   7159 use Moose::Util::TypeConstraints;
  4         5  
  4         25  
5 4     4   4744 use namespace::autoclean;
  4         40  
  4         30  
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   14 my $self = shift;
16 14         93 my $sha1 = Digest::SHA->new;
17 14         158 $sha1->add( $self->raw );
18 14         68 my $sha1_hex = $sha1->hexdigest;
19 14         325 return $sha1_hex;
20             }
21              
22             sub _build_size {
23 14     14   12 my $self = shift;
24 14         336 return length $self->content;
25             }
26              
27             sub raw {
28 28     28 0 29 my $self = shift;
29 28         837 return $self->kind . ' ' . $self->size . "\0" . $self->content;
30             }
31              
32             __PACKAGE__->meta->make_immutable;
33