Conformance/Source/Git.pm

filter: Statementstmt 45.2% 24 / 53 Branchbran 0.0% 0 / 16 Conditioncond 0.0% 0 / 11 MC/DCmcdc 0.0% 0 / 7 Subroutinesub 50.0% 7 / 14 Podpod 100% 6 / 6 totaltotal 34.5% 37 / 107 CC 13 SCAR 24.8
CC
13
Cov
30%
new
30.0
root
20.0
__ANON__
12.0
CRAP 12.0
« Conformance/Snapshot/Directory.pm ↑ Summary Conformance/Snapshot/Tree.pm »
1 package Dist::Conformance::Source::Git 0.005;
2  
3 # ABSTRACT: Standards fetched from a git repository into a cache directory
4  
5 2 ▶use 5.040;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 2 ▶use warnings FATAL => 'all';
Subroutine BEGIN: called CC=1 SCAR=0.0
7 2 ▶use re '/aasx';
Subroutine BEGIN: called CC=1 SCAR=0.0
8 2 ▶use Mojo::Base 'Dist::Conformance::Source', -signatures;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 2 ▶use Digest::SHA();
Subroutine BEGIN: called CC=1 SCAR=0.0
11 2 ▶use IPC::Run3();
Subroutine BEGIN: called CC=1 SCAR=0.0
12 2 ▶use Mojo::File();
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14  
15 2 has 'url';
16 2 has ref => 'HEAD';
17 2 has offline => 0;
18 0 ▶has cache => sub {
Subroutine __ANON__: not called CC=3 SCAR=24.8
19 0 ▶ my $base = $ENV{XDG_CACHE_HOME} || Mojo::File->new( $ENV{HOME} // die("Neither XDG_CACHE_HOME nor HOME is set\n") )->child('.cache');
Condition0%0/5
$ENV{'XDG_CACHE_HOME'} || 'Mojo::File'->new($ENV{'HOME'} // die("Neither XDG_CACHE_HOME nor HOME is set\n"))->child('.cache')
l!l&&r!l&&!r
000
$ENV{"HOME"} // die("Neither XDG_CACHE_HOME nor HOME is set\n")
l!l
00
MC/DC0%0/2
$ENV{'XDG_CACHE_HOME'} || 'Mojo::File'->new($ENV{'HOME'} // die("Neither XDG_CACHE_HOME nor HOME is set\n"))->child('.cache')
$ENV{'XDG_CACHE_HOME'} 'Mojo::File'->new($ENV{'HOME'} // die("Neither XDG_CACHE_HOME nor HOME is set\n"))->child('.cache')
MC/DC0%0/1
$ENV{"HOME"} // die("Neither XDG_CACHE_HOME nor HOME is set\n")
$ENV{"HOME"}
Truth table0%0/3
A || B
A= $ENV{'XDG_CACHE_HOME'}B= 'Mojo::File'->new($ENV{'HOME'} // die("Neither XDG_CACHE_HOME nor HOME is set\n"))->child('.cache')
ABresult
1X1
011
000
Truth table0%0/2
A
A= $ENV{"HOME"}
Aresult
11
00
20 0 return Mojo::File->new($base)->child('dist-conformance')->to_string;
21 2 };
22  
23  
24 0 ▶sub new ( $class, @args ) {
Subroutine new: not called CC=5 SCAR=34.0
Pod documented
25 0 my $self = $class->SUPER::new(@args);
26 0 ▶ die "url is required\n" if !defined $self->url || $self->url eq q{};
Branch: 1 branch
BranchTrueFalseTotal
if not defined $self->url or $self->url eq "" 0 0 0
Condition0%0/3
not defined $self->url or $self->url eq ""
l!l&&r!l&&!r
000
MC/DC0%0/2
not defined $self->url or $self->url eq ""
not defined $self->url $self->url eq ""
Truth table0%0/3
not(A) or B
A= not defined $self->urlB= $self->url eq ""
ABresult
1X1
011
000
27 0 ▶ die( 'The url ' . $self->url . " starts with -\n" ) if index( $self->url, q{-} ) == 0;
Branch: 1 branch
BranchTrueFalseTotal
if index($self->url, "-") == 0 0 0 0
28 0 ▶ die( 'The ref ' . $self->ref . " starts with -\n" ) if index( $self->ref, q{-} ) == 0;
Branch: 1 branch
BranchTrueFalseTotal
if index($self->ref, "-") == 0 0 0 0
29 0 return $self;
30 }
31  
32  
33 0 ▶sub clone_dir ($self) {
Subroutine clone_dir: not called CC=1 SCAR=6.9
Pod documented
34 0 return Mojo::File->new( $self->cache )->child( Digest::SHA::sha1_hex( $self->url . "\n" . $self->ref ) );
35 }
36  
37  
38 0 ▶sub root ($self) {
Subroutine root: not called CC=4 SCAR=30.0
Pod documented
39 0 ▶ return $self->{root} //= do {
Condition0%0/3
$self->{"root"} //= do { my $dir = $self->clone_dir; if ($self->offline) { die 'Offline, and there is no cached copy of ' . $self->describe, "\n" unless -d $dir->child(".git"); } else { $self->fetch; } ; $dir }
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->{"root"} //= do { my $dir = $self->clone_dir; if ($self->offline) { die 'Offline, and there is no cached copy of ' . $self->describe, "\n" unless -d $dir->child(".git"); } else { $self->fetch; } ; $dir }
$self->{"root"} do { my $dir = $self->clone_dir; if ($self->offline) { die 'Offline, and there is no cached copy of ' . $self->describe, "\n" unless -d $dir->child(".git"); } else { $self->fetch; } ; $dir }
Truth table0%0/3
A //= B
A= $self->{"root"}B= do { my $dir = $self->clone_dir; if ($self->offline) { die 'Offline, and there is no cached copy of ' . $self->describe, "\n" unless -d $dir->child(".git"); } else { $self->fetch; } ; $dir }
ABresult
1X1
011
000
40 0 my $dir = $self->clone_dir;
41 0 ▶ if ( $self->offline ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->offline) { } 0 0 0
42 0 ▶ die( 'Offline, and there is no cached copy of ' . $self->describe, "\n" ) if !-d $dir->child('.git');
Branch: 1 branch
BranchTrueFalseTotal
unless -d $dir->child(".git") 0 0 0
43 }
44 else {
45 0 $self->fetch;
46 }
47 0 $dir;
48 };
49 }
50  
51  
52 0 ▶sub fetch ($self) {
Subroutine fetch: not called CC=2 SCAR=17.9
Pod documented
53 0 my $dir = $self->clone_dir;
54 0 ▶ if ( !-d $dir->child('.git') ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (-d $dir->child(".git")) 0 0 0
55 0 $dir->remove_tree;
56 0 $dir->dirname->make_path;
57 0 git( qw{clone --quiet --no-checkout --}, $self->url, "$dir" );
58 }
59 0 git( '-C', "$dir", qw{fetch --quiet origin}, $self->ref );
60 0 git( '-C', "$dir", qw{checkout --quiet --force --detach FETCH_HEAD} );
61 0 return $dir;
62 }
63  
64  
65 0 ▶sub describe ($self) {
Subroutine describe: not called CC=2 SCAR=17.9
Pod documented
66 0 ▶ return $self->url . ' at ' . $self->ref . ( $self->path ne q{} ? ' (path ' . $self->path . ')' : q{} );
Branch: 1 branch
BranchTrueFalseTotal
$self->path ne '' ? : 0 0 0
67 }
68  
69  
70 # A clone and a fetch need the transports, the credential helpers and the
71 # configuration of the real git, which no CPAN module reproduces.
72 0 ▶sub git (@arguments) {
Subroutine git: not called CC=2 SCAR=17.9
Pod documented
73 0 local $ENV{GIT_TERMINAL_PROMPT} = 0;
74 0 my ( $out, $err ) = ( q{}, q{} );
75 0 IPC::Run3::run3( [ 'git', @arguments ], \undef, \$out, \$err );
76 0 my $status = $?;
77 0 ▶ die( "git @arguments failed: " . ( $err =~ s/\s+\z//r ), "\n" ) if $status;
Branch: 1 branch
BranchTrueFalseTotal
if $status 0 0 0
78 0 return $out;
79 }
80  
81 __END__
« Conformance/Snapshot/Directory.pm ↑ Summary Conformance/Snapshot/Tree.pm »