GitMeta/GMF.pm

filter: Statementstmt 56.1% 32 / 57 Branchbran 30.0% 3 / 10 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 81.8% 9 / 11 Podpod 0.0% 0 / 2 totaltotal 55.0% 44 / 80 CC 7 SCAR 18.6
CC
7
Cov
52%
expand
20.0
_fetch
6.0
repo_dir_from_git_url
3.0
CRAP 6.4
↑ Summary GitMeta.pm »
1 ###########################################
2 package GitMeta::GMF;
3 ###########################################
4 # 2010, Mike Schilli <m@perlmeister.com>
5 ###########################################
6 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 2 ▶use base qw(GitMeta);
Subroutine BEGIN: called CC=1 SCAR=0.0
9 2 ▶use File::Temp qw(tempdir);
Subroutine BEGIN: called CC=1 SCAR=0.0
10 2 ▶use Log::Log4perl qw(:easy);
Subroutine BEGIN: called CC=1 SCAR=0.0
11 2 ▶use YAML qw(Load);
Subroutine BEGIN: called CC=1 SCAR=0.0
12 2 ▶use Sysadm::Install qw(:all);
Subroutine BEGIN: called CC=1 SCAR=0.0
13 2 ▶use File::Basename;
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 ###########################################
16 0 ▶sub expand {
Subroutine expand: not called CC=4 SCAR=30.0
Pod undocumented
17 ###########################################
18 0 my($self) = @_;
19  
20 0 $self->param_check("repo", "gmf_path");
21  
22 my $yml = $self->_fetch(
23 $self->{repo},
24 0 $self->{gmf_path} );
25  
26 0 my @locs = ();
27  
28 0 for my $entry ( @$yml ) {
29 0 my $type = ref($entry);
30  
31 0 ▶ if($type eq "") {
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq '') { } 0 0 0
32 # plain git url
33 0 push @locs, $entry;
34 } else {
35 my $class = "GitMeta::" .
36 0 ucfirst( $entry->{type} );
37 0 ▶ eval "require $class;" or
Branch: 1 branch
BranchTrueFalseTotal
eval "require $class;" or LOGDIE("Class $class missing") 0 0 0
38 LOGDIE "Class $class missing";
39 0 my $expander = $class->new(%$entry);
40 0 push @locs, $expander->expand();
41 }
42 }
43  
44 0 return @locs;
45 }
46  
47 ###########################################
48 0 ▶sub _fetch {
Subroutine _fetch: not called CC=2 SCAR=17.9
49 ###########################################
50 0 my($self, $git_repo, $gmf_path) = @_;
51  
52 0 my $data;
53  
54 0 ▶ if( defined $git_repo ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $git_repo) { } 0 0 0
55 0 my($tempdir) = tempdir( CLEANUP => 1 );
56 0 cd $tempdir;
57 0 tap "git", "clone", $git_repo;
58 0 $data = slurp(basename($git_repo) .
59 "/$gmf_path");
60 0 cdback;
61 } else {
62 0 $data = slurp( $gmf_path );
63 }
64  
65 0 my $yml = Load( $data );
66  
67 0 return $yml;
68 }
69  
70 ###########################################
71 3 ▶sub repo_dir_from_git_url {
Subroutine repo_dir_from_git_url: called CC=3 SCAR=11.1
Pod undocumented
72 ###########################################
73 3 my( $self, $url ) = @_;
74  
75 3 my $repo_dir;
76  
77 3 ▶ if( $url =~ m#/# ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($url =~ m[/]) { } 2 1 3
elsif ($url =~ /:(.*)/) { } 1 0 1
78 2 $repo_dir = basename $url;
79 } elsif( $url =~ m#:(.*)# ) {
80 1 $repo_dir = $1;
81 } else {
82 0 die "cannot determine dir from git url: $url";
83 }
84  
85 3 $repo_dir =~ s/\.git$//g;
86  
87 3 return $repo_dir;
88 }
89  
90 2 1;
91  
92 __END__
↑ Summary GitMeta.pm »