Native/Config.pm untested

filter: Statementstmt 0.0% 0 / 24 Branchbran 0.0% 0 / 4 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 7 Podpod 0.0% 0 / 4 totaltotal 0.0% 0 / 39 CC 3 SCAR 13.3
CC
3
Cov
0%
get_string
6.0
DEMOLISH
6.0
set_string
2.0
CRAP 3.8
1 # ABSTRACT: A libgit2 configuration handle
2  
3 package Git::Native::Config;
4 use Moo;
5 use Git::Libgit2 qw( check_rc );
6 use Git::Libgit2::FFI ();
7  
8 has _handle => ( is => 'ro', required => 1 );
9 has _owner => ( is => 'ro' ); # Repository (when repo-derived) - keeps it alive
10  
11 # get_string($key): the value, or undef when the key is unset.
12 # libgit2 only guarantees git_config_get_string on a *snapshot* config;
13 # use Repository->config_snapshot / config_string for reads.
14 sub get_string {
15 my ( $self, $key ) = @_;
16 my $rc = Git::Libgit2::FFI::git_config_get_string( \my $out, $self->_handle, $key );
17 return undef if $rc < 0; # GIT_ENOTFOUND etc. - treat as "unset"
18 return $out;
19 }
20  
21 # set_string($key, $value): only valid on a live (non-snapshot) config.
22 sub set_string {
23 my ( $self, $key, $value ) = @_;
24 check_rc Git::Libgit2::FFI::git_config_set_string( $self->_handle, $key, $value );
25 return $self;
26 }
27  
28 # snapshot(): a read-only point-in-time copy. Returns a fresh Config.
29 sub snapshot {
30 my $self = shift;
31 check_rc Git::Libgit2::FFI::git_config_snapshot( \my $snap, $self->_handle );
32 return Git::Native::Config->new( _handle => $snap, _owner => $self->_owner );
33 }
34  
35 sub DEMOLISH {
36 my $self = shift;
37 Git::Libgit2::FFI::git_config_free( $self->{_handle} ) if $self->{_handle};
38 }
39  
40 1;
41  
42 __END__