blib/lib/Pod/Webserver/Source.pm

filter: Statementstmt 21.4% 15 / 70 Branchbran 0.0% 0 / 26 Conditioncond 0.0% 0 / 8 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 50.0% 3 / 6 Podpod n/a totaltotal 15.7% 18 / 114 CC 18 SCAR 44.8
CC
18
Cov
14%
_serve_thing
156.0
_serve_source
20.0
_add_header_backlink
20.0
CRAP 88.5
↑ Summary
1 package Pod::Webserver::Source;
2 # $Id: Source.pm,v 1.1 2005/01/05 12:26:39 cwest Exp $
3 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use vars qw[$LINK_PATH $PERLTIDY_ARGV $VERSION];
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 $PERLTIDY_ARGV = [qw[-html -npod -nnn]];
6 1 $VERSION = sprintf "%d.%02d", split m/\./, (qw$Revision: 1.1 $)[1];
7  
8 0 ▶sub _serve_thing {
Subroutine _serve_thing: not called CC=12 SCAR=50.5
9 0 my ($self, $conn, $req) = @_;
10 0 ▶ return $conn->send_error(405) unless $req->method eq 'GET'; # sanity
Branch: 1 branch
BranchTrueFalseTotal
unless $req->method eq "GET" 0 0 0
11  
12 0 my $path = $req->url;
13 0 ▶ $path .= substr( ($ENV{PATH} ||''), 0, 0); # to force-taint it.
Condition0%0/2
$ENV{'PATH'} || ''
l!l
00
MC/DC0%0/1
$ENV{'PATH'} || ''
$ENV{'PATH'}
Truth table0%0/2
A
A= $ENV{'PATH'}
Aresult
11
00
14
15 0 my $fs = $self->{'__daemon_fs'};
16 0 my $pods = $self->{'__modname2path'};
17 0 my $resp = HTTP::Response->new(200);
18 0 ▶ $resp->content_type( $fs->{"\e$path"} || 'text/html' );
Condition0%0/2
$$fs{"\e$path"} || 'text/html'
l!l
00
MC/DC0%0/1
$$fs{"\e$path"} || 'text/html'
$$fs{"\e$path"}
Truth table0%0/2
A
A= $$fs{"\e$path"}
Aresult
11
00
19  
20 0 my $path = $req->url;
21 0 ▶ $path .= substr( ($ENV{PATH} ||''), 0, 0); # to force-taint it.
Condition0%0/2
$ENV{'PATH'} || ''
l!l
00
MC/DC0%0/1
$ENV{'PATH'} || ''
$ENV{'PATH'}
Truth table0%0/2
A
A= $ENV{'PATH'}
Aresult
11
00
22 0 $path =~ s{:+}{/}g;
23 0 my $modname = $path;
24 0 $modname =~ s{/+}{::}g; $modname =~ s{^:+}{};
25 0 $modname =~ s{:+$}{}; $modname =~ s{:+$}{::}g;
26  
27 0 $Pod::Webserver::Source::LINK_PATH = $req->url;
28 0 ▶ return shift->_real_serve_thing(@_) unless $modname =~ /\.source$/;
Branch: 1 branch
BranchTrueFalseTotal
unless $modname =~ /\.source$/ 0 0 0
29  
30 0 $modname =~ s/\.source$//;
31 0 ▶ if ( $modname =~ m{^([a-zA-Z0-9_]+(?:::[a-zA-Z0-9_]+)*)$}s ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($modname =~ /^([a-zA-Z0-9_]+(?:::[a-zA-Z0-9_]+)*)$/s) { } 0 0 0
32 0 $modname = $1; # thus untainting
33 } else {
34 0 $modname = '';
35 }
36 0 ▶ Pod::Webserver::DEBUG() > 1 and print "Modname $modname source ($path)\n";
Branch: 1 branch
BranchTrueFalseTotal
&Pod::Webserver::DEBUG() > 1 and print "Modname $modname source ($path)\n" 0 0 0
37  
38 0 ▶ if ( $pods->{$modname} ) { # Is it known pod?
Branch: 1 branch
BranchTrueFalseTotal
if ($pods->{$modname}) { } 0 0 0
39 0 $self->muse("I know $modname source as ", $pods->{$modname});
40 0 __PACKAGE__->_serve_source($pods->{$modname}, $resp);
41 } else {
42 # If it's not known, look for it.
43 # This is necessary for indexless mode, and also useful just incase
44 # the user has just installed a new module (after the index was generated)
45 0 my $fspath = $Pod::Simple::HTMLBatch::SEARCH_CLASS->new->find($modname);
46
47 0 ▶ if( defined($fspath) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $fspath) { } 0 0 0
48 0 $self->muse("Found $modname source as $fspath");
49 0 __PACKAGE__->_serve_source($fspath, $resp);
50 } else {
51 0 $resp = '';
52 0 $self->muse("Can't find $modname in \@INC");
53 0 ▶ unless( $self->{'httpd_has_noted_inc_already'} ++ ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"httpd_has_noted_inc_already"}++) 0 0 0
54 0 $self->muse(" \@INC = [ @INC ]");
55 }
56 }
57 }
58
59 0 ▶ $resp ? $conn->send_response( $resp ) : $conn->send_error(404);
Branch: 1 branch
BranchTrueFalseTotal
$resp ? : 0 0 0
60 0 return;
61 }
62  
63 0 ▶sub _serve_source {
Subroutine _serve_source: not called CC=4 SCAR=30.0
64 0 my ($self, $fspath, $resp) = @_;
65
66 0 my $output = '';
67 0 ▶ if ( eval { require Perl::Tidy } ) {
Branch: 1 branch
BranchTrueFalseTotal
if (eval { do { require Perl::Tidy } }) { } 0 0 0
68 0 Perl::Tidy::perltidy(
69 source => $fspath,
70 destination => \$output,
71 argv => $Pod::Webserver::Source::PERLTIDY_ARGV,
72 );
73 } else {
74 0 $resp->header('Content-Type' => 'text/plain');
75 0 local *PODFH;
76 0 my $line = 1;
77 0 ▶ if ( open PODFH, "< $fspath" ) {
Branch: 1 branch
BranchTrueFalseTotal
if (open PODFH, "< $fspath") { } 0 0 0
78 0 ▶ $output .= sprintf "%5d %s",
Branch: 1 branch
BranchTrueFalseTotal
defined($_ = readline PODFH) and do { $output .= sprintf("%5d %s", $line++, $_) } 0 0 0
79 $line++,
80 $_ while <PODFH>;
81 0 close PODFH;
82 } else {
83 0 $output = "Can't locate sources ($!)!\n";
84 }
85 }
86 0 $resp->content($output);
87
88 0 return;
89 }
90  
91 0 ▶sub _add_header_backlink {
Subroutine _add_header_backlink: not called CC=4 SCAR=30.0
92 0 my $self = shift;
93 0 ▶ return if $self->no_contents_links;
Branch: 1 branch
BranchTrueFalseTotal
if $self->no_contents_links 0 0 0
94 0 my($page, $module, $infile, $outfile, $depth) = @_;
95 0 ▶ $page->html_header_after_title( join '',
Branch: 1 branch
BranchTrueFalseTotal
if $self->contents_file 0 0 0
Condition0%0/2
$page->html_header_after_title || ''
l!l
00
MC/DC0%0/1
$page->html_header_after_title || ''
$page->html_header_after_title
Truth table0%0/2
A
A= $page->html_header_after_title
Aresult
11
00
96 $page->html_header_after_title || '',
97 qq[<p class="backlinktop"><b><a name="___top" href="],
98 $self->url_up_to_contents($depth),
99 qq[" accesskey="1" title="All Documents">&lt;&lt;</a>],
100 qq[ <a href="$Pod::Webserver::Source::LINK_PATH.source">Source</a>],
101 qq[</b></p>\n],
102 ) if $self->contents_file;
103 0 return;
104 }
105  
106 package Pod::Webserver;
107 1 ▶no strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
108  
109 1 *_real_serve_thing = \&_serve_thing;
110 1 *_serve_thing = \&Pod::Webserver::Source::_serve_thing;
111 1 *add_header_backlink = \&Pod::Webserver::Source::_add_header_backlink;
112  
113 1 1;
114  
115 __END__
↑ Summary