Native/TreeBuilder.pm untested

filter: Statementstmt 0.0% 0 / 34 Branchbran 0.0% 0 / 4 Conditioncond 0.0% 0 / 2 MC/DCmcdc 0.0% 0 / 1 Subroutinesub 0.0% 0 / 9 Podpod 0.0% 0 / 4 totaltotal 0.0% 0 / 54 CC 3 SCAR 12.4
CC
3
Cov
0%
insert
6.0
DEMOLISH
6.0
remove
2.0
CRAP 3.5
1 # ABSTRACT: Build a libgit2 tree object entry by entry
2  
3 package Git::Native::TreeBuilder;
4 our $VERSION = '0.006';
5 use Moo;
6 use Git::Libgit2::FFI ();
7 use Git::Native::Error qw( check_rc );
8 use Git::Native::Oid ();
9 use FFI::Platypus::Buffer qw( scalar_to_buffer );
10  
11 has _handle => ( is => 'ro', required => 1 );
12 has _owner => ( is => 'ro', required => 1 ); # Repository
13  
14 sub insert {
15 my ( $self, %args ) = @_;
16 my $oid = $args{oid};
17 $oid = Git::Native::Oid->from_hex($oid) if !ref $oid;
18 check_rc Git::Libgit2::FFI::git_treebuilder_insert(
19 \my $entry,
20 $self->_handle,
21 $args{name},
22 $oid->ptr,
23 $args{mode} // 0100644,
24 );
25 return $self;
26 }
27  
28 sub remove {
29 my ( $self, $name ) = @_;
30 check_rc Git::Libgit2::FFI::git_treebuilder_remove( $self->_handle, $name );
31 return $self;
32 }
33  
34 sub write {
35 my $self = shift;
36 my $raw = "\0" x 20;
37 my ($p) = scalar_to_buffer($raw);
38 check_rc Git::Libgit2::FFI::git_treebuilder_write( $p, $self->_handle );
39 return Git::Native::Oid->from_raw($raw);
40 }
41  
42 sub DEMOLISH {
43 my $self = shift;
44 Git::Libgit2::FFI::git_treebuilder_free( $self->{_handle} )
45 if $self->{_handle};
46 }
47  
48 1;
49  
50 __END__