File Coverage

blib/lib/Cogit/Object.pm
Criterion Covered Total %
statement 21 21 100.0
branch n/a
condition 1 2 50.0
subroutine 7 7 100.0
pod 0 1 0.0
total 29 31 93.5


line stmt bran cond sub pod time code
1             package Cogit::Object;
2             $Cogit::Object::VERSION = '0.001001';
3 4     4   1401 use Moo;
  4         6  
  4         16  
4 4     4   8690 use Digest::SHA;
  4         10383  
  4         184  
5 4     4   23 use MooX::Types::MooseLike::Base qw( Str Int InstanceOf );
  4         6  
  4         200  
6 4     4   14 use namespace::clean;
  4         4  
  4         26  
7              
8             has kind => (
9             is => 'ro',
10             isa => sub {
11             die "$_[0] is not a valid object type" unless $_[0] =~ m/commit|tree|blob|tag/
12             },
13             required => 1,
14             );
15              
16             # TODO: make this required later
17             has content => (
18             is => 'rw',
19             builder => '_build_content',
20             lazy => 1,
21             predicate => 'has_content',
22             );
23              
24             has size => (
25             is => 'ro',
26             isa => Int,
27             builder => '_build_size',
28             lazy => 1,
29             );
30              
31             has sha1 => (
32             is => 'ro',
33             isa => Str,
34             builder => '_build_sha1',
35             lazy => 1,
36             );
37              
38             has git => (
39             is => 'rw',
40             isa => InstanceOf['Cogit'],
41             weak_ref => 1,
42             );
43              
44             sub _build_sha1 {
45 14     14   285 my $self = shift;
46 14         110 my $sha1 = Digest::SHA->new;
47 14         180 $sha1->add( $self->raw );
48 14         1041 my $sha1_hex = $sha1->hexdigest;
49 14         243 return $sha1_hex;
50             }
51              
52             sub _build_size {
53 14     14   97 my $self = shift;
54 14   50     223 return length($self->content || "");
55             }
56              
57             sub raw {
58 28     28 0 37 my $self = shift;
59 28         605 return $self->kind . ' ' . $self->size . "\0" . $self->content;
60             }
61              
62             1;
63              
64             __END__
65              
66             =pod
67              
68             =encoding UTF-8
69              
70             =head1 NAME
71              
72             Cogit::Object
73              
74             =head1 VERSION
75              
76             version 0.001001
77              
78             =head1 AUTHOR
79              
80             Arthur Axel "fREW" Schmidt <cogit@afoolishmanifesto.com>
81              
82             =head1 COPYRIGHT AND LICENSE
83              
84             This software is copyright (c) 2017 by Arthur Axel "fREW" Schmidt.
85              
86             This is free software; you can redistribute it and/or modify it under
87             the same terms as the Perl 5 programming language system itself.
88              
89             =cut