blib/lib/App/CPANIDX/HTTP/Server.pm

filter: Statementstmt 35.2% 24 / 68 Branchbran 0.0% 0 / 24 Conditioncond 0.0% 0 / 24 MC/DCmcdc 0.0% 0 / 13 Subroutinesub 70.0% 7 / 10 Podpod 100% 2 / 2 totaltotal 23.4% 33 / 141 CC 21 SCAR 41.1
CC
21
Cov
21%
_search_db
110.0
handle_request
72.0
dsn
30.0
CRAP 61.1
↑ Summary
1 package App::CPANIDX::HTTP::Server;
2 {
3 1 $App::CPANIDX::HTTP::Server::VERSION = '0.08';
4 }
5
6 #ABSTRACT: HTTP::Server::Simple based server for CPANIDX
7  
8 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 1 ▶use DBI;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 1 ▶use App::CPANIDX::Renderer;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 1 ▶use App::CPANIDX::Queries;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 1 ▶use HTTP::Server::Simple::CGI;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 1 ▶use base qw(HTTP::Server::Simple::CGI);
Subroutine BEGIN: called CC=1 SCAR=0.0
15
16 0 ▶sub dsn {
Subroutine dsn: not called CC=5 SCAR=34.0
Pod documented
17 0 my ($self,$dsn,$user,$pass) = @_;
18 0 ▶ if ( $dsn and $self->{_dbh} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($dsn and $self->{"_dbh"}) 0 0 0
Condition0%0/3
$dsn and $self->{"_dbh"}
!ll&&!rl&&r
000
MC/DC0%0/2
$dsn and $self->{"_dbh"}
$dsn $self->{"_dbh"}
Truth table0%0/3
A and B
A= $dsnB= $self->{"_dbh"}
ABresult
0X0
100
111
19 0 warn "Already have a database connection, thanks\n";
20 0 return;
21 }
22 0 ▶ if ( $dsn ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($dsn) 0 0 0
23 0 ▶ $self->{_dbh} = DBI->connect($dsn,$user,$pass) or die $DBI::errstr, "\n";
Branch: 1 branch
BranchTrueFalseTotal
$self->{"_dbh"} = "DBI"->connect($dsn, $user, $pass) or die $DBI::errstr, "\n" 0 0 0
24 0 $self->{_dsn} = $dsn;
25 0 return;
26 }
27 0 return $self->{_dsn};
28 }
29  
30 0 ▶sub handle_request {
Subroutine handle_request: not called CC=8 SCAR=42.8
Pod documented
31 0 my $self = shift;
32 0 my $cgi = shift;
33
34 0 my $path = $cgi->path_info();
35 0 $path =~ s!/+!/!g;
36 0 warn $path, "\n";
37 0 my ($root,$enc,$type,$search) = grep { $_ } split m#/#, $path;
38  
39 0 ▶ if ( $root eq 'cpanidx' and $enc and $type ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($root eq 'cpanidx' and $enc and $type) { } 0 0 0
Condition0%0/6
$root eq "cpanidx" and $enc and $type
!ll&&!rl&&r
000
$root eq "cpanidx" and $enc
!ll&&!rl&&r
000
MC/DC0%0/3
$root eq "cpanidx" and $enc and $type
$root eq "cpanidx" $enc $type
Truth table0%0/4
A and B and C
A= $root eq "cpanidx"B= $encC= $type
ABCresult
0XX0
10X0
1100
1111
40 0 ▶ $search = '0' if $type =~ /^next/ and !$search;
Branch: 1 branch
BranchTrueFalseTotal
if $type =~ /^next/ and not $search 0 0 0
Condition0%0/3
$type =~ /^next/ and not $search
!ll&&!rl&&r
000
MC/DC0%0/2
$type =~ /^next/ and not $search
$type =~ /^next/ not $search
Truth table0%0/3
A and not(B)
A= $type =~ /^next/B= not $search
ABresult
0X0
100
111
41 0 my @results = $self->_search_db( $type, $search );
42 0 ▶ $enc = 'yaml' unless $enc and grep { lc($enc) eq $_ } App::CPANIDX::Renderer->renderers();
Branch: 1 branch
BranchTrueFalseTotal
unless $enc and grep {lc $enc eq $_;} "App::CPANIDX::Renderer"->renderers 0 0 0
Condition0%0/3
$enc and grep {lc $enc eq $_;} "App::CPANIDX::Renderer"->renderers
!ll&&!rl&&r
000
MC/DC0%0/2
$enc and grep {lc $enc eq $_;} "App::CPANIDX::Renderer"->renderers
$enc grep {lc $enc eq $_;} "App::CPANIDX::Renderer"->renderers
Truth table0%0/3
A and B
A= $encB= grep {lc $enc eq $_;} "App::CPANIDX::Renderer"->renderers
ABresult
0X0
100
111
43 0 my $ren = App::CPANIDX::Renderer->new( \@results, $enc );
44 0 my ($ctype, $string) = $ren->render( $type );
45 0 print "HTTP/1.0 200 OK\r\n";
46 0 print "Content-type: $ctype\r\n\r\n";
47 0 print $string;
48 }
49 else {
50 0 print "HTTP/1.0 404 Not found\r\n";
51 0 print $cgi->header,
52 $cgi->start_html('Not found'),
53 $cgi->h1('Not found'),
54 $cgi->end_html;
55 }
56 }
57  
58 0 ▶sub _search_db {
Subroutine _search_db: not called CC=10 SCAR=47.0
59 0 my ($self,$type,$search) = @_;
60 0 my @results;
61 0 ▶ if ( my $sql = App::CPANIDX::Queries->query( $type ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $sql = "App::CPANIDX::Queries"->query($type)) 0 0 0
62 0 ▶ if ( ( $type eq 'mod' or $type eq 'corelist' or $type eq 'perms' )
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq "mod" || $type eq "corelist" || $type eq "perms" and not $search =~ /\A[a-zA-Z_][0-9a-zA-Z_]*(?:(::|')[0-9a-zA-Z_]+)*\z/) 0 0 0
Condition0%0/9
$type eq "mod" || $type eq "corelist" || $type eq "perms" and not $search =~ /\A[a-zA-Z_][0-9a-zA-Z_]*(?:(::|')[0-9a-zA-Z_]+)*\z/
!ll&&!rl&&r
000
$type eq "mod" or $type eq "corelist" or $type eq "perms"
l!l&&r!l&&!r
000
$type eq "mod" or $type eq "corelist"
l!l&&r!l&&!r
000
MC/DC0%0/4
$type eq "mod" || $type eq "corelist" || $type eq "perms" and not $search =~ /\A[a-zA-Z_][0-9a-zA-Z_]*(?:(::|')[0-9a-zA-Z_]+)*\z/
$type eq "mod" $type eq "corelist" $type eq "perms" not $search =~ /\A[a-zA-Z_][0-9a-zA-Z_]*(?:(::|')[0-9a-zA-Z_]+)*\z/
Truth table0%0/7
A or B or C and not(D)
A= $type eq "mod"B= $type eq "corelist"C= $type eq "perms"D= not $search =~ /\A[a-zA-Z_][0-9a-zA-Z_]*(?:(::|')[0-9a-zA-Z_]+)*\z/
ABCDresult
000X0
1XX00
01X00
00100
1XX11
01X11
00111
63 and !( $search =~ m#\A[a-zA-Z_][0-9a-zA-Z_]*(?:(::|')[0-9a-zA-Z_]+)*\z# ) ) {
64 0 return @results;
65 }
66 # send query to dbi
67 0 ▶ if ( my $sth = $self->{_dbh}->prepare_cached( $sql->[0] ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $sth = $self->{'_dbh'}->prepare_cached($sql->[0])) { } 0 0 0
68 0 ▶ $sth->execute( ( $sql->[1] ? $search : () ) );
Branch: 1 branch
BranchTrueFalseTotal
$sql->[1] ? : 0 0 0
69 0 ▶ while ( my $row = $sth->fetchrow_hashref() ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $row = $sth->fetchrow_hashref) 0 0 0
70 0 push @results, { %{ $row } };
71 }
72 0 ▶ if ( $type eq 'mod' ) { # sanity check
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq "mod") 0 0 0
73 0 @results = grep { $_->{mod_name} eq $search } @results;
74 }
75 }
76 else {
77 0 warn $DBI::errstr, "\n";
78 0 return @results;
79 }
80 }
81 0 return @results;
82 }
83  
84 1 1;
85  
86  
87 __END__
↑ Summary