blib/lib/Combust/Spontaneously.pm

filter: Statementstmt 41.0% 32 / 78 Branchbran 0.0% 0 / 14 Conditioncond 0.0% 0 / 11 MC/DCmcdc 0.0% 0 / 6 Subroutinesub 33.3% 6 / 18 Podpod 100% 3 / 3 totaltotal 31.5% 41 / 130 CC 11 SCAR 39.7
CC
11
Cov
31%
handler
132.0
new
2.0
fakeup_request_class
2.0
CRAP 52.8
↑ Summary
1 package Combust::Spontaneously;
2 1 $VERSION = v0.0.1;
3  
4 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 1 ▶use base 'HTTP::Server::Simple::Er';
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 # "pretend" we already loaded some stuff we're not going to need
11 1 $INC{do{my $x = $_; $x =~ s#::#/#g; $x.".pm"}} = '/dev/null' for(
12 'Apache2::SubRequest',
13 'DBI',
14 );
15  
16 1 $INC{'Cache/Memcached.pm'} = 1;
17 0 ▶*Cache::Memcached::new = sub {shift};
Subroutine __ANON__: not called CC=1 SCAR=1.2
18  
19 1 ▶use Class::Accessor::Classy;
Subroutine BEGIN: called CC=1 SCAR=0.0
20 1 ro 'site';
21 1 ro 'control';
22 1 ▶no Class::Accessor::Classy;
Subroutine BEGIN: called CC=1 SCAR=0.0
23  
24 =head1 NAME
25  
26 Combust::Spontaneously - combust standalone server class
27  
28 =head1 SYNOPSIS
29  
30 See `perldoc combustier` for recommended usage.
31  
32 =cut
33  
34 =begin pretend_coverage
35  
36 =head2 new
37  
38 =end pretend_coverage
39  
40 =cut
41  
42 0 ▶sub new {
Subroutine new: not called CC=1 SCAR=6.9
Pod documented
43 0 my $self = shift->SUPER::new(@_);
44  
45 0 $self->fakeup_request_class;
46 0 require Combust::Control::Basic;
47  
48 0 my $control = $self->{control} = Combust::Control::Basic->new;
49 0 ($control->{site} = $self->site) =~ s#/$##;
50 0 my $path = $control->get_include_path;
51 # warn join(', ', @$path);
52 0 $control->tt->set_include_path([$self->site, 'shared', @$path]);
53 0 return($self);
54 }
55  
56 my %types = (
57 2 map({$_ => "image/$_"} qw(png jpg)),
58 ico => 'image/x-icon',
59 1 map({$_ => "application/"} qw(pdf)),
60 ps => 'application/postscript',
61 1 map({$_ => "text/$_"} qw(css)),
62 );
63  
64 =head2 handler
65  
66 Called by the superclass to handle requests.
67  
68 $server->handler;
69  
70 =cut
71  
72 0 ▶sub handler {
Subroutine handler: not called CC=11 SCAR=48.8
Pod documented
73 0 my $self = shift;
74  
75 0 my $path = $self->path;
76 0 $path =~ s{/$}{/index.html};
77 0 $path =~ s#^/##;
78  
79 # support runtime dep analysis
80 0 ▶ exit if(Devel::TraceDeps->can('import') and $path eq 'exit');
Branch: 1 branch
BranchTrueFalseTotal
if "Devel::TraceDeps"->can("import") and $path eq "exit" 0 0 0
Condition0%0/3
"Devel::TraceDeps"->can("import") and $path eq "exit"
!ll&&!rl&&r
000
MC/DC0%0/2
"Devel::TraceDeps"->can("import") and $path eq "exit"
"Devel::TraceDeps"->can("import") $path eq "exit"
Truth table0%0/3
A and B
A= "Devel::TraceDeps"->can("import")B= $path eq "exit"
ABresult
0X0
100
111
81  
82 0 local $self->control->request->{path} = '/' . $path;
83  
84 0 ▶ if($path !~ m/\.html$/) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($path =~ /\.html$/) 0 0 0
85 0 my %params;
86 0 my ($ext) = $path =~ m/\.([^\.]+)$/;
87 0 ▶ if(my $type = $types{$ext}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $type = $types{$ext}) 0 0 0
88 0 $params{content_type} = $type;
89 }
90 0 my $data = $self->control->tt->provider->expand_filename($path);
91  
92 0 ▶ my $file = $data->{path} or warn "no data for $path";
Branch: 1 branch
BranchTrueFalseTotal
my $file = $data->{"path"} or warn "no data for $path" 0 0 0
93  
94 0 ▶ return $self->output(404, "no $path") unless($file and -e $file);
Branch: 1 branch
BranchTrueFalseTotal
unless $file and -e $file 0 0 0
Condition0%0/3
$file and -e $file
!ll&&!rl&&r
000
MC/DC0%0/2
$file and -e $file
$file -e $file
Truth table0%0/3
A and B
A= $fileB= -e $file
ABresult
0X0
100
111
95  
96 0 my $content = do {
97 0 ▶ open(my $fh, '<', $file) or
Branch: 1 branch
BranchTrueFalseTotal
open my $fh, "<", $file or warn "cannot open $file" and return $self->output(403, "fail") 0 0 0
Condition0%0/5
open(my $fh, '<', $file) || warn("cannot open $file") && (return $self->output(403, 'fail'))
l!l&&r!l&&!r
000
warn "cannot open $file" and return $self->output(403, "fail")
!ll
00
MC/DC0%0/2
open(my $fh, '<', $file) || warn("cannot open $file") && (return $self->output(403, 'fail'))
open(my $fh, '<', $file) warn "cannot open $file"
Truth table0%0/3
A || B
A= open(my $fh, '<', $file)B= warn "cannot open $file"
ABresult
1X1
011
000
98 warn "cannot open $file" and return $self->output(403, 'fail');
99 0 warn "static: $file\n";
100 0 local $/; <$fh>;
101 };
102  
103 0 return $self->output(\%params, $content);
104 }
105  
106 0 warn "$path\n";
107 0 my $out = eval {$self->control->evaluate_template($path)};
108 0 ▶ if(my $err = $@) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $err = $@) 0 0 0
109 0 return $self->output(404, $err);
110 }
111 #warn $out;
112 0 $self->output($out);
113 } ######################################################################
114  
115  
116 =begin internal
117  
118 =head2 fakeup_request_class
119  
120 this useless class is just deferring things until after the construction
121  
122 =end internal
123  
124 =cut
125  
126 0 ▶sub fakeup_request_class {
Subroutine fakeup_request_class: not called CC=1 SCAR=6.9
Pod documented
127 package Combust::Request::Spontaneously;
128 0 $INC{'Combust/Request/Spontaneously.pm'} = __FILE__;
129  
130 0 require Combust::Request;
131 0 our @ISA = ('Combust::Request');
132  
133 0 ▶ sub _r {shift}
Subroutine _r: not called CC=1 SCAR=6.9
134 0 ▶ sub pnotes {shift->notes(@_)}
Subroutine pnotes: not called CC=1 SCAR=6.9
135 0 ▶ sub dir_config {'.'}
Subroutine dir_config: not called CC=1 SCAR=6.9
136 0 ▶ sub document_root {'.'}
Subroutine document_root: not called CC=1 SCAR=6.9
137  
138 0 ▶ sub req_param {''}
Subroutine req_param: not called CC=1 SCAR=6.9
139 0 ▶ sub get_cookie {''}
Subroutine get_cookie: not called CC=1 SCAR=6.9
140 0 ▶ sub args { 'thbbt' }
Subroutine args: not called CC=1 SCAR=6.9
141 0 ▶ sub uri { shift->{path} }
Subroutine uri: not called CC=1 SCAR=6.9
142  
143 }
144  
145  
146  
147 =head1 AUTHOR
148  
149 Eric Wilhelm @ <ewilhelm at cpan dot org>
150  
151 http://scratchcomputing.com/
152  
153 =head1 BUGS
154  
155 If you found this module on CPAN, please report any bugs or feature
156 requests through the web interface at L<http://rt.cpan.org>. I will be
157 notified, and then you'll automatically be notified of progress on your
158 bug as I make changes.
159  
160 If you pulled this development version from my /svn/, please contact me
161 directly.
162  
163 =head1 COPYRIGHT
164  
165 Copyright (C) 2009 Eric L. Wilhelm, All Rights Reserved.
166  
167 =head1 NO WARRANTY
168  
169 Absolutely, positively NO WARRANTY, neither express or implied, is
170 offered with this software. You use this software at your own risk. In
171 case of loss, no person or entity owes you anything whatsoever. You
172 have been warned.
173  
174 =head1 LICENSE
175  
176  
177  
178 =cut
179  
180 # vi:ts=2:sw=2:et:sta
181 1 1;
↑ Summary