Repo/Server.pm

filter: Statementstmt 28.5% 16 / 56 Branchbran 0.0% 0 / 8 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 33.3% 3 / 9 Podpod 0.0% 0 / 1 totaltotal 25.6% 19 / 74 CC 11 SCAR 24.8
CC
11
Cov
25%
__ANON__
20.0
__ANON__
20.0
__ANON__
12.2
CRAP 12.0
↑ Summary Repo.pm »
1 package CPAN::Repo::Server;
2 1 ▶use CPAN::Repo;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 1 ▶use Dancer ':syntax';
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 our $REPO_ROOT;
5  
6 0 ▶get '/' => sub { # home page
Subroutine __ANON__: not called CC=4 SCAR=25.0
7 0 set content_type => 'text/html';
8 0 my $ret = '<h1>list of available repos</h1>';
9 0 my @l;
10 0 ▶ for my $i (<$REPO_ROOT/*>){
Subroutine BEGIN: called CC=1 SCAR=0.2
11 0 ▶ next unless -d $i;
Branch: 1 branch
BranchTrueFalseTotal
unless -d $i 0 0 0
12 0 s/.*\/// for $i;
13 0 push @l, $i
14 }
15 0 $ret.='<ul>'.( join "\n", map {"<li><a href=/repo/$_/>$_</a></li>"} @l ).'</ul>'.signature();
16 0 return $ret;
17
18 1 };
19  
20 0 ▶get '/list/$' => sub { # list of repos (a-la rest api, called from in CPAN::Repo pluggins)
Subroutine __ANON__: not called CC=4 SCAR=30.0
21 0 set content_type => 'text/plain';
22 # template 'index';
23 0 my @l;
24 0 for my $i (<$REPO_ROOT/*>){
25 0 ▶ next unless -d $i;
Branch: 1 branch
BranchTrueFalseTotal
unless -d $i 0 0 0
26 0 s/.*\/// for $i;
27 0 push @l, $i
28 }
29 0 return join "\n", @l;
30
31 1 };
32  
33 0 ▶get qr{/(\S+)/packages\.txt} => sub { # repo packages.txt
Subroutine __ANON__: not called CC=4 SCAR=30.0
34 0 set content_type => 'text/plain';
35 0 my ($path) = splat;
36 0 my $ret;
37 0 for my $p (split /\//, $path ){
38 0 $ret.="# $p repository\n";
39 0 ▶ if(open F, "$REPO_ROOT/$p/packages.txt"){
Branch: 1 branch
BranchTrueFalseTotal
if (open F, "$CPAN::Repo::Server::REPO_ROOT/$p/packages.txt") 0 0 0
40 0 ▶ while (my $l = <F>){
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $l = readline F)) 0 0 0
41 0 $ret.="~$p/$l";
42 0 }; close F;
43 }
44 0 $ret.="\n";
45 }
46 0 return $ret;
47 1 };
48  
49 0 ▶get qr{^/repo/(\w+)/$} => sub { # repo index page
Subroutine __ANON__: not called CC=2 SCAR=17.9
50 0 set content_type => 'text/html';
51 0 my ($cs_id) = splat;
52 0 my $ret = "<h1><a href='/'>$cs_id</a></h1>\n";
53 0 $ret.="<i><a href='/$cs_id/packages.txt'>packages.txt</a></i><br><br>\n";
54 0 for my $d (<$REPO_ROOT/$cs_id/*.gz>){
55 0 (my $l = $d)=~s/.*\/(.*)/$1/;
56 0 $ret.="<a href='~$cs_id/$l'>$l</a><br>\n";
57 }
58 0 $ret.=signature();
59 0 return $ret;
60 1 };
61  
62 0 ▶get qr{/.*/~(\w+)/(.*\.tar\.gz)} => sub { # distros
Subroutine __ANON__: not called CC=1 SCAR=6.9
63  
64 0 my ($cs_id,$distro) = splat;
65 0 redirect "$cs_id/$distro"
66 1 };
67  
68 0 ▶sub signature {
Subroutine signature: not called CC=1 SCAR=6.9
Pod undocumented
69 0 return "\n\n<hr noshade>cpan repo server version $CPAN::Repo::VERSION</hr>\n\n";
70 }
71  
72 1 1;
73  
↑ Summary Repo.pm »