| 1 | package CPAN::InGit::Server; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | 3 | our $VERSION = '0.005'; # VERSION | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | # ABSTRACT: A Mojolicious::Controller that serves the ArchiveTrees from a git repo | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | 3 | ▶ | use Carp; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | 3 | ▶ | use Scalar::Util 'refaddr', 'blessed'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | 3 | ▶ | use JSON::PP; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | 3 | ▶ | use Time::Piece; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | 3 | ▶ | use Log::Any '$log'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | 3 | ▶ | use Archive::Tar; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | 3 | ▶ | use IO::Compress::Gzip qw( gzip $GzipError ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | 3 | ▶ | use CPAN::InGit; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | 3 | ▶ | use File::ShareDir (); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | 3 | ▶ | use Mojo::File 'path'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | 3 | ▶ | use Mojolicious::Static; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | 3 | ▶ | use Mojo::Base 'Mojolicious::Controller'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | 3 | ▶ | use v5.36; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | 53 | ▶ | sub cpan_repo($c) { $c->stash('cpan_repo') } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
cpan_repo: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | 151 | ▶ | sub archive_tree($c) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
archive_tree: called CC=9 SCAR=22.4
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | 151 | ▶ | $c->stash->{archive_tree} //= do { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%3/3
$c->stash->{"archive_tree"} //= do {
my $branch_name = $c->branch_name;
my $cache = $c->branch_cache;
my $atree = $cache->{$branch_name};
if ($atree) {
my $current_tree = $c->cpan_repo->lookup_tree($branch_name);
unless (defined $current_tree and $atree->tree->id eq $current_tree->id) {
delete $cache->{$branch_name};
$atree = undef;
};
};
if (not $atree and $atree = $c->cpan_repo->get_archive_tree($branch_name)) {
if ($c->branch_head_only and not defined $atree->branch) {
$c->log->debug("Branch '${branch_name}' is not a branch HEAD");
$atree = undef;
}
else {
$cache->{$branch_name} = $atree;
};
};
$atree
}
MC/DC100%2/2
$c->stash->{"archive_tree"} //= do {
my $branch_name = $c->branch_name;
my $cache = $c->branch_cache;
my $atree = $cache->{$branch_name};
if ($atree) {
my $current_tree = $c->cpan_repo->lookup_tree($branch_name);
unless (defined $current_tree and $atree->tree->id eq $current_tree->id) {
delete $cache->{$branch_name};
$atree = undef;
};
};
if (not $atree and $atree = $c->cpan_repo->get_archive_tree($branch_name)) {
if ($c->branch_head_only and not defined $atree->branch) {
$c->log->debug("Branch '${branch_name}' is not a branch HEAD");
$atree = undef;
}
else {
$cache->{$branch_name} = $atree;
};
};
$atree
}
$c->stash->{"archive_tree"}
do {
my $branch_name = $c->branch_name;
my $cache = $c->branch_cache;
my $atree = $cache->{$branch_name};
if ($atree) {
my $current_tree = $c->cpan_repo->lookup_tree($branch_name);
unless (defined $current_tree and $atree->tree->id eq $current_tree->id) {
delete $cache->{$branch_name};
$atree = undef;
};
};
if (not $atree and $atree = $c->cpan_repo->get_archive_tree($branch_name)) {
if ($c->branch_head_only and not defined $atree->branch) {
$c->log->debug("Branch '${branch_name}' is not a branch HEAD");
$atree = undef;
}
else {
$cache->{$branch_name} = $atree;
};
};
$atree
}
Truth table100%3/3
A //= B
A= $c->stash->{"archive_tree"}B= do {
my $branch_name = $c->branch_name;
my $cache = $c->branch_cache;
my $atree = $cache->{$branch_name};
if ($atree) {
my $current_tree = $c->cpan_repo->lookup_tree($branch_name);
unless (defined $current_tree and $atree->tree->id eq $current_tree->id) {
delete $cache->{$branch_name};
$atree = undef;
};
};
if (not $atree and $atree = $c->cpan_repo->get_archive_tree($branch_name)) {
if ($c->branch_head_only and not defined $atree->branch) {
$c->log->debug("Branch '${branch_name}' is not a branch HEAD");
$atree = undef;
}
else {
$cache->{$branch_name} = $atree;
};
};
$atree
}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | 45 | my $branch_name= $c->branch_name; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | 45 | my $cache= $c->branch_cache; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | 45 | my $atree= $cache->{$branch_name}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | 45 | ▶ | if ($atree) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | # check whether branch has updated since cached | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | 31 | my $current_tree= $c->cpan_repo->lookup_tree($branch_name); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | 31 | ▶ | unless (defined $current_tree and $atree->tree->id eq $current_tree->id) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $current_tree and $atree->tree->id eq $current_tree->id
MC/DC50%1/2
defined $current_tree and $atree->tree->id eq $current_tree->id
defined $current_tree
$atree->tree->id eq $current_tree->id
Truth table66%2/3
A and B
A= defined $current_treeB= $atree->tree->id eq $current_tree->id
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | 2 | delete $cache->{$branch_name}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | 2 | $atree= undef; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | 45 | ▶ | if (!$atree && ($atree= $c->cpan_repo->get_archive_tree($branch_name))) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
not $atree and $atree = $c->cpan_repo->get_archive_tree($branch_name)
MC/DC100%2/2
not $atree and $atree = $c->cpan_repo->get_archive_tree($branch_name)
not $atree
$atree = $c->cpan_repo->get_archive_tree($branch_name)
Truth table100%3/3
not(A) and B
A= not $atreeB= $atree = $c->cpan_repo->get_archive_tree($branch_name)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | 14 | ▶ | if ($c->branch_head_only && !defined $atree->branch) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$c->branch_head_only and not defined $atree->branch
MC/DC0%0/2
$c->branch_head_only and not defined $atree->branch
$c->branch_head_only
not defined $atree->branch
Truth table33%1/3
A and not(B)
A= $c->branch_head_onlyB= not defined $atree->branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | 0 | $c->log->debug("Branch '$branch_name' is not a branch HEAD"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | 0 | $atree= undef; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | 14 | $cache->{$branch_name}= $atree; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | 45 | $atree; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | 61 | ▶ | sub branch_name($c) { $c->stash('branch_name') } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
branch_name: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | 45 | ▶ | sub branch_cache($c) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
branch_cache: called CC=2 SCAR=11.6
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | 45 | ▶ | $c->stash->{branch_cache} //= do { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$c->stash->{"branch_cache"} //= do {
warn "no branch_cache, creating temporary";
$c->_new_cache
}
MC/DC0%0/2
$c->stash->{"branch_cache"} //= do {
warn "no branch_cache, creating temporary";
$c->_new_cache
}
$c->stash->{"branch_cache"}
do {
warn "no branch_cache, creating temporary";
$c->_new_cache
}
Truth table33%1/3
A //= B
A= $c->stash->{"branch_cache"}B= do {
warn "no branch_cache, creating temporary";
$c->_new_cache
}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | 0 | warn "no branch_cache, creating temporary"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | 0 | $c->_new_cache | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | 14 | ▶ | sub branch_head_only($c) { $c->stash('branch_head_only') } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
branch_head_only: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | 7 | ▶ | sub index_branches($c) { $c->stash('index_branches') } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
index_branches: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | 37 | ▶ | sub module_index_max_rows($c) { $c->stash('module_index_max_rows') // 5000 } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
module_index_max_rows: called CC=2 SCAR=6.9
Pod
documented
Condition100%2/2
$c->stash("module_index_max_rows") // 5000
MC/DC100%1/1
$c->stash("module_index_max_rows") // 5000
$c->stash("module_index_max_rows")
Truth table100%2/2
A
A= $c->stash("module_index_max_rows")
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | 33 | ▶ | sub _share_dir { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_share_dir: called CC=2 SCAR=7.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | 33 | state $dir= do { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | 3 | my $relative= path(__FILE__)->sibling('..', '..', '..', 'share'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | 3 | ▶ | -f $relative->child('archive_tree_index.html.ep')? $relative->realpath | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | : path(File::ShareDir::dist_dir('CPAN-InGit')); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | 33 | return $dir; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | 9 | ▶ | sub _new_cache { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_new_cache: called CC=2 SCAR=7.6
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | # the 'recent_limit' feature was added in 0.20 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | 0 | ▶ | state $have_tree_rb_xs= eval 'use Tree::RB::XS 0.20'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=1.2
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | 9 | my %hash; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | 9 | ▶ | tie %hash, 'Tree::RB::XS', track_recent => 1, recent_limit => 20 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | if $have_tree_rb_xs; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | 9 | \%hash; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | 12 | ▶ | sub mount($class, $base_route, $cpan_repo, %options) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
mount: called CC=9 SCAR=22.3
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | 12 | my $root= $base_route->root; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | 12 | ▶ | unless ($root->{_cpan_ingit_public}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | 12 | my $static= Mojolicious::Static->new( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | paths => [$class->_share_dir->child('public')->to_string], prefix => '/~static'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | 7 | ▶ | $root->get('/~static/*asset')->to(cb => sub($c) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | 7 | ▶ | $static->dispatch($c) || $c->reply->not_found; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | 12 | }); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | # Static files must take precedence over the catch-all branch index. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | 12 | unshift $root->children->@*, pop $root->children->@*; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | 12 | $root->{_cpan_ingit_public}= $static; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | 12 | my $atree= $options{archive_tree}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | 12 | ▶ | if ($atree) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | 3 | ▶ | croak "Not an ArchiveTree" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
builtin::blessed($atree) and $atree->can("get_path")
MC/DC0%0/2
builtin::blessed($atree) and $atree->can("get_path")
builtin::blessed($atree)
$atree->can("get_path")
Truth table33%1/3
A and B
A= builtin::blessed($atree)B= $atree->can("get_path")
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | unless blessed($atree) && $atree->can('get_path'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | # Ensure there is a cache if serving all branches | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | 9 | ▶ | $options{branch_cache} //= $class->_new_cache; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$options{"branch_cache"} //= $class->_new_cache
MC/DC0%0/2
$options{"branch_cache"} //= $class->_new_cache
$options{"branch_cache"}
$class->_new_cache
Truth table33%1/3
A //= B
A= $options{"branch_cache"}B= $class->_new_cache
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | 12 | $base_route= $base_route->to(namespace => '', controller => $class, cpan_repo => $cpan_repo, %options); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | 12 | ▶ | $base_route->get('/')->to(action => 'serve_repo_index') unless $atree; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | # Keep each suffix in the same pattern as the branch wildcard, so Git branch | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | # names containing slashes can be matched without consuming the file path. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | 12 | ▶ | my $prefix= $atree? '' : '/*branch_name'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | 12 | $base_route->get("$prefix/modules/02packages.details", [ format => ['txt','txt.gz'] ]) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | ->to(action => 'serve_package_details'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | 12 | $base_route->get("$prefix/authors/id/*author_path")->to(action => 'serve_author_file'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | 12 | $base_route->get("$prefix/modules/")->to(action => 'serve_module_list'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | 12 | ▶ | $base_route->get($atree? '/' : $prefix, [ branch_name => qr{.+?(?=/?$)}, format => 0 ]) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | ->to(action => 'serve_index'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | 7 | ▶ | sub serve_repo_index($c) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
serve_repo_index: called CC=6 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | 7 | my @branches; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | 7 | ▶ | my $index_branches= $c->index_branches // 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$c->index_branches // 0
MC/DC100%1/1
$c->index_branches // 0
$c->index_branches
Truth table100%2/2
A
A= $c->index_branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | 7 | ▶ | if ($index_branches) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | 3 | my $base= $c->url_for->query(undef); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | 3 | my $base_path= $base->path->to_string =~ s{/*$}{/}r; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | 3 | for my $branch (sort { $a->shorthand cmp $b->shorthand } $c->cpan_repo->git_repo->branches('local')) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | 8 | my $tree= $branch->peel('tree'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | 8 | ▶ | next unless $tree->entry_bypath('cpan_ingit.json') | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$tree->entry_bypath("cpan_ingit.json") and $tree->entry_bypath("modules/02packages.details.txt")
MC/DC50%1/2
$tree->entry_bypath("cpan_ingit.json") and $tree->entry_bypath("modules/02packages.details.txt")
$tree->entry_bypath("cpan_ingit.json")
$tree->entry_bypath("modules/02packages.details.txt")
Truth table66%2/3
A and B
A= $tree->entry_bypath("cpan_ingit.json")B= $tree->entry_bypath("modules/02packages.details.txt")
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | && $tree->entry_bypath('modules/02packages.details.txt'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | 6 | my $name= $branch->shorthand; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | 6 | push @branches, { name => $name, url => $base->clone->path($base_path.Mojo::Util::url_escape($name).'/') }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | 7 | $c->render(inline => $c->_share_dir->child('repo_index.html.ep')->slurp('UTF-8'), handler => 'ep', format => 'html', | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | index_branches => $index_branches, branches => \@branches); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | 39 | ▶ | sub _module_index($c) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_module_index: called CC=7 SCAR=19.6
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | 39 | my $atree= $c->archive_tree; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | 39 | my $blob= $atree->package_details_blob; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | 39 | ▶ | return undef unless $blob; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | 37 | my $index= $atree->{_server_module_index}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | 37 | ▶ | unless ($index && $index->{blob_id} eq $blob->id) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$index and $index->{"blob_id"} eq $blob->id
MC/DC50%1/2
$index and $index->{"blob_id"} eq $blob->id
$index
$index->{"blob_id"} eq $blob->id
Truth table66%2/3
A and B
A= $indexB= $index->{"blob_id"} eq $blob->id
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | 15 | my ($headers, $body)= split /\r?\n\r?\n/, $blob->content, 2; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | 15 | my ($updated)= $headers =~ /^Last-Updated:\s*([^\r\n]*)/m; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | 15 | my @rows; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | 15 | ▶ | for my $line (split /\r?\n/, $body // '') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$body // ""
MC/DC0%0/1
$body // ""
$body
Truth table50%1/2
A
A= $body
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | 3521 | ▶ | next unless $line =~ /^(\S+)\s+(\S+)\s+(\S+)\s*$/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | 3521 | push @rows, { name => $1, version => $2, path => $3, text => $line }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 146 | 15 | @rows= sort { $a->{name} cmp $b->{name} } @rows; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 147 | 15 | $index= $atree->{_server_module_index}= { blob_id => $blob->id, updated => $updated, rows => \@rows }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 148 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 149 | 37 | return $index; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 150 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 151 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 152 | 37 | ▶ | sub _module_page($c, $index) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_module_page: called CC=16 SCAR=27.7
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 153 | 37 | ▶ | my $filter= $c->param('filter') // ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$c->param("filter") // ""
MC/DC100%1/1
$c->param("filter") // ""
$c->param("filter")
Truth table100%2/2
A
A= $c->param("filter")
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 154 | 37 | my $needle= lc $filter; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 155 | 37 | my @matches= grep index(lc $_->{text}, $needle) >= 0, $index->{rows}->@*; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 156 | 37 | my ($after, $before)= map $c->param($_), qw(after before); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 157 | 37 | my ($start, $end)= (0, scalar @matches); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 158 | 37 | my $max= $c->module_index_max_rows; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 159 | 37 | ▶ | if (defined $before) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 160 | 3 | ▶ | --$end while $end && $matches[$end-1]{name} ge $before; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$end and $matches[$end - 1]{"name"} ge $before
MC/DC100%2/2
$end and $matches[$end - 1]{"name"} ge $before
$end
$matches[$end - 1]{"name"} ge $before
Truth table100%3/3
A and B
A= $endB= $matches[$end - 1]{"name"} ge $before
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 161 | 3 | ▶ | $start= $end > $max? $end-$max : 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 162 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 163 | 34 | ▶ | ++$start while $start < $end && defined $after && $matches[$start]{name} le $after; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%6/6
$start < $end and defined $after and $matches[$start]{"name"} le $after
$start < $end and defined $after
MC/DC100%3/3
$start < $end and defined $after and $matches[$start]{"name"} le $after
$start < $end
defined $after
$matches[$start]{"name"} le $after
Truth table100%4/4
A and B and C
A= $start < $endB= defined $afterC= $matches[$start]{"name"} le $after
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 164 | 34 | ▶ | $end= $start+$max if $end > $start+$max; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 165 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 166 | 37 | my @rows= @matches[$start .. $end-1]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 167 | return { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 168 | modules => \@rows, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 169 | filter => $filter, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 170 | tree => $c->archive_tree->tree->id, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 171 | complete => $start == 0 && $end == @matches? JSON::PP::true : JSON::PP::false, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 172 | next_after => @rows && $end < @matches? $rows[-1]{name} : undef, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 173 | previous_before => @rows && $start > 0? $rows[0]{name} : undef, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 174 | 37 | ▶ | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
Condition100%9/9
$start == 0 and $end == @matches
@rows and $end < @matches
@rows and $start > 0
MC/DC100%2/2
$start == 0 and $end == @matches
$start == 0
$end == @matches
MC/DC100%2/2
@rows and $end < @matches
@rows
$end < @matches
MC/DC100%2/2
@rows and $start > 0
@rows
$start > 0
Truth table100%3/3
A and B
A= $start == 0B= $end == @matches
Truth table100%3/3
A and B
A= @rowsB= $end < @matches
Truth table100%3/3
A and B
A= @rowsB= $start > 0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 175 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 176 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 177 | 26 | ▶ | sub serve_module_list($c) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
serve_module_list: called CC=5 SCAR=16.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 178 | 26 | ▶ | return undef unless $c->check_branch_exists; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 179 | 25 | ▶ | return $c->render(status => 400, json => { error => 'Supply only one of after and before' }) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
defined $c->param("after") and defined $c->param("before")
MC/DC100%2/2
defined $c->param("after") and defined $c->param("before")
defined $c->param("after")
defined $c->param("before")
Truth table100%3/3
A and B
A= defined $c->param("after")B= defined $c->param("before")
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 180 | if defined $c->param('after') && defined $c->param('before'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 181 | 24 | ▶ | my $index= $c->_module_index | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 182 | or return $c->render(status => 404, json => { error => 'No package index in this tree' }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 183 | 23 | $c->render(json => $c->_module_page($index)); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 184 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 185 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 186 | 16 | ▶ | sub serve_index($c) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
serve_index: called CC=11 SCAR=25.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 187 | 16 | ▶ | return undef unless $c->check_branch_exists; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 188 | 15 | ▶ | my $index= $c->_module_index | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 189 | or return $c->render(status => 404, text => 'No package index in this tree'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 190 | 14 | my $atree= $c->archive_tree; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 191 | 14 | my $origin= $atree->branch; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 192 | 14 | ▶ | (undef, $origin)= $c->cpan_repo->lookup_tree($c->branch_name // $atree->name) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$c->branch_name // $atree->name
MC/DC0%0/2
$c->branch_name // $atree->name
$c->branch_name
$atree->name
Truth table66%2/3
A // B
A= $c->branch_nameB= $atree->name
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 193 | unless $origin; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 194 | 14 | ▶ | $origin= $origin->target while $origin && $origin->isa('Git::Raw::Tag'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$origin and $origin->isa("Git::Raw::Tag")
MC/DC0%0/2
$origin and $origin->isa("Git::Raw::Tag")
$origin
$origin->isa("Git::Raw::Tag")
Truth table33%1/3
A and B
A= $originB= $origin->isa("Git::Raw::Tag")
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 195 | 14 | ▶ | my $commit= !$origin? undef | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 196 | : $origin->isa('Git::Raw::Commit')? $origin : $origin->peel('commit'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 197 | 14 | my $base= $c->url_for->query(undef); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 198 | 14 | my $base_path= $base->path->to_string =~ s{/*$}{/}r; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 199 | $c->render(inline => $c->_share_dir->child('archive_tree_index.html.ep')->slurp('UTF-8'), handler => 'ep', format => 'html', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 200 | module_page => $c->_module_page($index), index_updated => $index->{updated}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 201 | 14 | ▶ | commit_date => $commit? gmtime($commit->time)->strftime('%a, %d %b %Y %H:%M:%S GMT') : undef, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$c->branch_name // $atree->name
MC/DC0%0/2
$c->branch_name // $atree->name
$c->branch_name
$atree->name
Truth table66%2/3
A // B
A= $c->branch_nameB= $atree->name
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 202 | tree_name => $c->branch_name // $atree->name, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 203 | json_url => $base->clone->path($base_path.'modules/'), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 204 | script_url => $c->url_for('/~static/archive_tree_index.js'), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 205 | cve_script_url => $c->url_for('/~static/cpan_cves.js'), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 206 | authors_url => $base->clone->path($base_path.'authors/id/')); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 207 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 208 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 209 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 210 | 50 | ▶ | sub check_branch_exists($c) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
check_branch_exists: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 211 | 50 | ▶ | unless ($c->archive_tree) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 212 | 2 | $c->render(text => 'Git branch does not exist', status => 404); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 213 | 2 | return undef; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 214 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 215 | 48 | return 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 216 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 217 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 218 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 219 | 3 | ▶ | sub serve_package_details($c) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
serve_package_details: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 220 | 3 | ▶ | return undef unless $c->check_branch_exists; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 221 | 3 | my $blob= $c->archive_tree->package_details_blob; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 222 | $c->respond_to( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 223 | 2 | ▶ | txt => sub { $c->render(text => $blob->content) }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 224 | 1 | ▶ | 'txt.gz' => sub { $c->render_gzipped($blob->content, '02packages.details.txt.gz') }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 225 | 3 | ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 226 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 227 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 228 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 229 | 5 | ▶ | sub serve_author_file($c) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
serve_author_file: called CC=14 SCAR=33.5
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 230 | 5 | ▶ | return undef unless $c->check_branch_exists; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 231 | 5 | my $path= 'authors/id/'.$c->stash->{author_path}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 232 | # cpanm adds extra '/' when the path name doesn't match the expected A/AU/AUTHOR format | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 233 | 5 | $path =~ s,//+,/,g; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 234 | 5 | my ($basename)= ($path =~ m,([^/]+)\z,); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 235 | # Does the exact file exist? | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 236 | 5 | my $ent= $c->archive_tree->get_path($path); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 237 | 5 | ▶ | $c->log->debug("Path $path is ".($ent? ($ent->[0]->is_blob? 'blob ':'tree ').$ent->[0]->id : '<undef>')); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 238 | 5 | ▶ | if ($ent) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 239 | 4 | ▶ | if ($ent->[0]->is_blob) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 240 | 4 | $c->res->headers->content_disposition(qq{attachment; filename="$basename"}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 241 | 4 | $c->render(data => $ent->[0]->content); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 242 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 243 | 0 | $c->render(status => 403, text => 'not a file'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 244 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 245 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 246 | ▶ | elsif ($path =~ /(.*?)\.gz\z/ | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%2/6
$path =~ /(.*?)\.gz\z/u and $ent = $c->archive_tree->get_path($1) and $ent->[0]->is_blob
$path =~ /(.*?)\.gz\z/u and $ent = $c->archive_tree->get_path($1)
MC/DC0%0/3
$path =~ /(.*?)\.gz\z/u and $ent = $c->archive_tree->get_path($1) and $ent->[0]->is_blob
$path =~ /(.*?)\.gz\z/u
$ent = $c->archive_tree->get_path($1)
$ent->[0]->is_blob
Truth table25%1/4
A and B and C
A= $path =~ /(.*?)\.gz\z/uB= $ent = $c->archive_tree->get_path($1)C= $ent->[0]->is_blob
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 247 | && ($ent= $c->archive_tree->get_path($1)) && $ent->[0]->is_blob | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 248 | ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 249 | 0 | $c->log->debug("Path $1 is ".$ent->[0]->id.', will gzip it'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 250 | 0 | $c->render_gzipped($ent->[0]->content, $basename); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 251 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 252 | ▶ | elsif ($path =~ /(.*?)\.tar\.gz\z/ | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%4/12
$path =~ /(.*?)\.tar\.gz\z/u and $ent = $c->archive_tree->get_path("$1.meta") and $ent->[0]->is_blob and $ent = $c->archive_tree->get_path($1) and $ent->[0]->is_tree
$path =~ /(.*?)\.tar\.gz\z/u and $ent = $c->archive_tree->get_path("$1.meta") and $ent->[0]->is_blob and $ent = $c->archive_tree->get_path($1)
$path =~ /(.*?)\.tar\.gz\z/u and $ent = $c->archive_tree->get_path("$1.meta") and $ent->[0]->is_blob
$path =~ /(.*?)\.tar\.gz\z/u and $ent = $c->archive_tree->get_path("$1.meta")
MC/DC0%0/5
$path =~ /(.*?)\.tar\.gz\z/u and $ent = $c->archive_tree->get_path("$1.meta") and $ent->[0]->is_blob and $ent = $c->archive_tree->get_path($1) and $ent->[0]->is_tree
$path =~ /(.*?)\.tar\.gz\z/u
$ent = $c->archive_tree->get_path("$1.meta")
$ent->[0]->is_blob
$ent = $c->archive_tree->get_path($1)
$ent->[0]->is_tree
Truth table16%1/6
A and B and C and D and E
A= $path =~ /(.*?)\.tar\.gz\z/uB= $ent = $c->archive_tree->get_path("$1.meta")C= $ent->[0]->is_blobD= $ent = $c->archive_tree->get_path($1)E= $ent->[0]->is_tree
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 253 | # Don't auto-tar trees that don't look like distributions | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 254 | && ($ent= $c->archive_tree->get_path("$1.meta")) && $ent->[0]->is_blob | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 255 | && ($ent= $c->archive_tree->get_path($1)) && $ent->[0]->is_tree | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 256 | ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 257 | 1 | $c->log->debug("Path $1 is ".$ent->[0]->id.', will tar+gzip it'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 258 | 1 | my $tar= Archive::Tar->new; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 259 | 1 | $c->cpan_repo->add_git_tree_to_tar($tar, substr($basename, 0, -7), $ent->[0]); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 260 | 1 | $c->render_gzipped($tar->write, $basename); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 261 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 262 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 263 | 0 | $c->render(status => 404, text => 'No such path in branch'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 264 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 265 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 266 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 267 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 268 | 2 | ▶ | sub render_gzipped($c, $data, $filename='') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
render_gzipped: called CC=4 SCAR=14.2
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 269 | 2 | my $gzipped; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 270 | 2 | ▶ | gzip \$data => \$gzipped | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 271 | or return $c->reply->exception("gzip failed: $GzipError"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 272 | 2 | $c->res->headers->content_type('application/gzip'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 273 | 2 | ▶ | $c->res->headers->content_disposition(qq{attachment; filename="$filename"}) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 274 | if length $filename; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 275 | 2 | return $c->render(data => $gzipped); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 276 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 277 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 278 | 3 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 279 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 280 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||