| 1 | package CPAN::InGit::Server; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | 1 | our $VERSION = '0.003'; # VERSION | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | # ABSTRACT: A Mojolicious::Controller that serves the ArchiveTrees from a git repo | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | 1 | ▶ | use Carp; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | 1 | ▶ | use Scalar::Util 'refaddr', 'blessed'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | 1 | ▶ | use JSON::PP; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | 1 | ▶ | use Time::Piece; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | 1 | ▶ | use Log::Any '$log'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | 1 | ▶ | use Archive::Tar; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | 1 | ▶ | use IO::Compress::Gzip qw( gzip $GzipError ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | 1 | ▶ | use CPAN::InGit; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | 1 | ▶ | use Mojo::Base 'Mojolicious::Controller'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | 1 | ▶ | use v5.36; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | 8 | ▶ | sub cpan_repo($c) { $c->stash('cpan_repo') } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
cpan_repo: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | 15 | ▶ | sub archive_tree($c) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
archive_tree: called CC=9 SCAR=23.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | 15 | ▶ | $c->stash->{archive_tree} //= do { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/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/DC0%0/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 table66%2/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
}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | 6 | my $branch_name= $c->branch_name; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | 6 | my $cache= $c->branch_cache; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | 6 | my $atree= $cache->{$branch_name}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | 6 | ▶ | if ($atree) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | # check whether branch has updated since cached | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | 5 | my $current_tree= $c->cpan_repo->lookup_tree($branch_name); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | 5 | ▶ | 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | 1 | delete $cache->{$branch_name}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | 1 | $atree= undef; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | 6 | ▶ | if (!$atree && ($atree= $c->cpan_repo->get_archive_tree($branch_name))) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
not $atree and $atree = $c->cpan_repo->get_archive_tree($branch_name)
MC/DC50%1/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 table66%2/3
not(A) and B
A= not $atreeB= $atree = $c->cpan_repo->get_archive_tree($branch_name)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | 2 | ▶ | 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | 0 | $c->log->debug("Branch '$branch_name' is not a branch HEAD"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | 0 | $atree= undef; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | 2 | $cache->{$branch_name}= $atree; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | 6 | $atree; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | 6 | ▶ | sub branch_name($c) { $c->stash('branch_name') } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
branch_name: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | 6 | ▶ | sub branch_cache($c) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
branch_cache: called CC=2 SCAR=11.6
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | 6 | ▶ | $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
}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | 0 | warn "no branch_cache, creating temporary"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | 0 | $c->_new_cache | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | 2 | ▶ | sub branch_head_only($c) { $c->stash('branch_head_only') } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
branch_head_only: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | 1 | ▶ | sub _new_cache { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_new_cache: called CC=2 SCAR=7.6
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | # the 'recent_limit' feature was added in 0.20 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | 1 | ▶ | state $have_tree_rb_xs= eval 'use Tree::RB::XS 0.20'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=1.2
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | 1 | my %hash; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | 1 | ▶ | tie %hash, 'Tree::RB::XS', track_recent => 1, recent_limit => 20 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | if $have_tree_rb_xs; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | 1 | \%hash; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | 1 | ▶ | sub mount($class, $base_route, $cpan_repo, %options) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
mount: called CC=6 SCAR=23.5
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | 1 | my $atree= $options{archive_tree}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | 1 | ▶ | if ($atree) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | 0 | ▶ | croak "Not an ArchiveTree" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/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 table0%0/3
A and B
A= builtin::blessed($atree)B= $atree->can("get_path")
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | unless blessed($atree) && $atree->can('get_path'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | # Ensure there is a cache if serving all branches | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | 1 | ▶ | $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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | 1 | $base_route= $base_route->to(namespace => '', controller => $class, cpan_repo => $cpan_repo, %options); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | 1 | ▶ | my $tree_route= $atree? $base_route | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | : $base_route->any('/:branch_name'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | 1 | $tree_route->get('/modules/02packages.details', [ format => ['txt','txt.gz'] ]) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | ->to(action => 'serve_package_details'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | 1 | $tree_route->get('/authors/id/*author_path')->to(action => 'serve_author_file'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | 6 | ▶ | sub check_branch_exists($c) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
check_branch_exists: called CC=2 SCAR=9.2
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | 6 | ▶ | unless ($c->archive_tree) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | 0 | $c->render(text => 'Git branch does not exist', status => 404); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | 0 | return undef; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | 6 | return 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | 2 | ▶ | sub serve_package_details($c) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
serve_package_details: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | 2 | ▶ | return undef unless $c->check_branch_exists; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | 2 | my $blob= $c->archive_tree->package_details_blob; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | $c->respond_to( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | 1 | ▶ | txt => sub { $c->render(text => $blob->content) }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | 1 | ▶ | 'txt.gz' => sub { $c->render_gzipped($blob->content, '02packages.details.txt.gz') }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | 2 | ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | 4 | ▶ | sub serve_author_file($c) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
serve_author_file: called CC=14 SCAR=33.5
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | 4 | ▶ | return undef unless $c->check_branch_exists; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | 4 | my $path= 'authors/id/'.$c->stash->{author_path}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | # cpanm adds extra '/' when the path name doesn't match the expected A/AU/AUTHOR format | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | 4 | $path =~ s,//+,/,g; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | 4 | my ($basename)= ($path =~ m,([^/]+)\z,); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | # Does the exact file exist? | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | 4 | my $ent= $c->archive_tree->get_path($path); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | 4 | ▶ | $c->log->debug("Path $path is ".($ent? ($ent->[0]->is_blob? 'blob ':'tree ').$ent->[0]->id : '<undef>')); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | 4 | ▶ | if ($ent) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | 3 | ▶ | if ($ent->[0]->is_blob) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | 3 | $c->res->headers->content_disposition(qq{attachment; filename="$basename"}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | 3 | $c->render(data => $ent->[0]->content); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | 0 | $c->render(status => 403, text => 'not a file'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | ▶ | 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | && ($ent= $c->archive_tree->get_path($1)) && $ent->[0]->is_blob | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | 0 | $c->log->debug("Path $1 is ".$ent->[0]->id.', will gzip it'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | 0 | $c->render_gzipped($ent->[0]->content, $basename); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | ▶ | 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | # Don't auto-tar trees that don't look like distributions | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | && ($ent= $c->archive_tree->get_path("$1.meta")) && $ent->[0]->is_blob | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | && ($ent= $c->archive_tree->get_path($1)) && $ent->[0]->is_tree | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | 1 | $c->log->debug("Path $1 is ".$ent->[0]->id.', will tar+gzip it'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | 1 | my $tar= Archive::Tar->new; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | 1 | $c->cpan_repo->add_git_tree_to_tar($tar, substr($basename, 0, -7), $ent->[0]); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | 1 | $c->render_gzipped($tar->write, $basename); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | 0 | $c->render(status => 404, text => 'No such path in branch'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | 2 | ▶ | sub render_gzipped($c, $data, $filename='') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
render_gzipped: called CC=4 SCAR=14.2
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | 2 | my $gzipped; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | 2 | ▶ | gzip \$data => \$gzipped | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | or return $c->reply->exception("gzip failed: $GzipError"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 146 | 2 | $c->res->headers->content_type('application/gzip'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 147 | 2 | ▶ | $c->res->headers->content_disposition(qq{attachment; filename="$filename"}) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 148 | if length $filename; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 149 | 2 | return $c->render(data => $gzipped); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 150 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 151 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 152 | 1 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 153 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 154 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||