bin/cpangit-server

filter: Statementstmt 90.2% 37 / 41 Branchbran 35.7% 5 / 14 Conditioncond 40.0% 2 / 5 MC/DCmcdc 0.0% 0 / 3 Subroutinesub 88.8% 8 / 9 Podpod n/a totaltotal 72.2% 52 / 72 CC 2 SCAR 2.8
CC
2
Cov
73%
BEGIN
2.1
__ANON__
2.0
BEGIN
1.0
CRAP 1.3
« bin/cpangit-add ↑ Summary
1 #! /usr/bin/env perl
2 # PODNAME: cpangit-server
3 2 our $VERSION = '0.006'; # VERSION
4 # ABSTRACT: serve a CPAN tree from a git branch, or all CPAN trees in the git repo
5  
6 2 ▶use FindBin;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 2 ▶BEGIN { push @INC, "$FindBin::RealBin/../lib" if -f "$FindBin::RealBin/../dist.ini" }
Subroutine BEGIN: called CC=2 SCAR=7.6
Branch: 1 branch
BranchTrueFalseTotal
if -f "$FindBin::RealBin/../dist.ini" 2 0 2
8 2 ▶use Mojolicious::Lite;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 2 ▶use CPAN::InGit::Server;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 2 ▶use Getopt::Long;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 2 ▶use Pod::Usage;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 2 ▶use Log::Any::Adapter;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 2 ▶use v5.36;
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15  
16 2 my $git_dir= $ENV{GIT_DIR};
17 2 my $base_path= '/';
18 2 my %mount_options;
19 {
20 2 local $Getopt::Long::config= Getopt::Long::ConfigDefaults();
21 2 Getopt::Long::Configure(qw( no_permute pass_through no_auto_abbrev ));
22 GetOptions(
23 'git-dir=s' => \$git_dir,
24 'path-base=s' => \$base_path,
25 'base-path|p=s' => \$base_path,
26 'tree|t=s' => \$mount_options{archive_tree},
27 'branch-head-only' => \$mount_options{branch_head_only},
28 'index-branches' => \$mount_options{index_branches},
29 0 ▶ 'help|h' => sub { pod2usage(1) },
Subroutine __ANON__: not called CC=1 SCAR=6.9
30 2 ▶ ) or pod2usage(2);
Branch: 1 branch
BranchTrueFalseTotal
&GetOptions("git-dir=s", \$git_dir, "path-base=s", \$base_path, "base-path|p=s", \$base_path, "tree|t=s", \$mount_options{"archive_tree"}, "branch-head-only", \$mount_options{"branch_head_only"}, "index-branches", \$mount_options{"index_branches"}, "help|h", sub { pod2usage(1); } ) or pod2usage(2) 2 0 2
31 }
32 2 ▶@ARGV= qw( daemon -m production )
Branch: 1 branch
BranchTrueFalseTotal
unless @ARGV 0 2 2
33 unless @ARGV;
34  
35 2 Log::Any::Adapter->set( MojoLog => logger => app->log );
36  
37 2 ▶die "No such GIT_DIR directory: '$git_dir'\n"
Branch: 1 branch
BranchTrueFalseTotal
if defined $git_dir and not -d $git_dir 0 2 2
Condition33%1/3
defined $git_dir and not -d $git_dir
!ll&&!rl&&r
020
MC/DC0%0/2
defined $git_dir and not -d $git_dir
defined $git_dir not -d $git_dir
Truth table33%1/3
A and not(B)
A= defined $git_dirB= not -d $git_dir
ABresult
0X0
100
111
38 if defined $git_dir && !-d $git_dir;
39  
40 2 ▶my $git_repo= Git::Raw::Repository->discover($git_dir // '.');
Condition50%1/2
$git_dir // "."
l!l
20
MC/DC0%0/1
$git_dir // "."
$git_dir
Truth table50%1/2
A
A= $git_dir
Aresult
11
00
41 2 my $cpan_repo= CPAN::InGit->new(git_repo => $git_repo);
42  
43 # If user wants a single tree, resolve the name
44 2 ▶if (defined $mount_options{archive_tree}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $mount_options{"archive_tree"}) 0 2 2
45 0 my $name= $mount_options{archive_tree};
46 0 ▶ my $atree= $cpan_repo->get_archive_tree($name)
Branch: 2 branches
BranchTrueFalseTotal
my $atree = $cpan_repo->get_archive_tree($name) or croak($cpan_repo->lookup_tree($name) ? "Tree '${name}' does not look like an ArchiveTree" : "Unknown git tree '${name}'") 0 0 0
$cpan_repo->lookup_tree($name) ? : 0 0 0
47 or croak($cpan_repo->lookup_tree($name)
48 ? "Tree '$name' does not look like an ArchiveTree"
49 : "Unknown git tree '$name'");
50 0 $mount_options{archive_tree}= $atree;
51 }
52  
53 # The routes for the server controller can be mounted at any sub-path desired.
54 # By default, this mounts every possible Git tree which looks like a valid ArchiveTree layout
55 # so you can point cpanm to `-M host:/BRANCH_NAME` or `-M host:/SHA-1` or `-M host:/GIT_TAG`
56 2 CPAN::InGit::Server->mount(app->routes->any($base_path), $cpan_repo, app => app, %mount_options);
57  
58 2 app->start;
59  
60 __END__
« bin/cpangit-add ↑ Summary