| 1 | #! /usr/bin/env perl | ||||||||||||||||||||||||||||
| 2 | # PODNAME: cpangit-server | ||||||||||||||||||||||||||||
| 3 | 2 | our $VERSION = '0.005'; # 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 31 | } | ||||||||||||||||||||||||||||
| 32 | 2 | ▶ | @ARGV= qw( daemon -m production ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
Condition33%1/3
defined $git_dir and not -d $git_dir
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
| |||||||||||||||||||||||||||||
| 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 // "."
MC/DC0%0/1
$git_dir // "."
$git_dir
Truth table50%1/2
A
A= $git_dir
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 45 | 0 | my $name= $mount_options{archive_tree}; | |||||||||||||||||||||||||||
| 46 | 0 | ▶ | my $atree= $cpan_repo->get_archive_tree($name) | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 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, %mount_options); | |||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||
| 58 | 2 | app->start; | |||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||
| 60 | __END__ | ||||||||||||||||||||||||||||