| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Combust::Spontaneously; |
|
2
|
|
|
|
|
|
|
$VERSION = v0.0.1; |
|
3
|
|
|
|
|
|
|
|
|
4
|
1
|
|
|
1
|
|
848
|
use warnings; |
|
|
1
|
|
|
|
|
1
|
|
|
|
1
|
|
|
|
|
36
|
|
|
5
|
1
|
|
|
1
|
|
5
|
use strict; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
35
|
|
|
6
|
1
|
|
|
1
|
|
16
|
use Carp; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
75
|
|
|
7
|
|
|
|
|
|
|
|
|
8
|
1
|
|
|
1
|
|
5
|
use base 'HTTP::Server::Simple::Er'; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
975
|
|
|
9
|
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
# "pretend" we already loaded some stuff we're not going to need |
|
11
|
|
|
|
|
|
|
$INC{do{my $x = $_; $x =~ s#::#/#g; $x.".pm"}} = '/dev/null' for( |
|
12
|
|
|
|
|
|
|
'Apache2::SubRequest', |
|
13
|
|
|
|
|
|
|
'DBI', |
|
14
|
|
|
|
|
|
|
); |
|
15
|
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
$INC{'Cache/Memcached.pm'} = 1; |
|
17
|
|
|
|
|
|
|
*Cache::Memcached::new = sub {shift}; |
|
18
|
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
use Class::Accessor::Classy; |
|
20
|
|
|
|
|
|
|
ro 'site'; |
|
21
|
|
|
|
|
|
|
ro 'control'; |
|
22
|
|
|
|
|
|
|
no Class::Accessor::Classy; |
|
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
|
|
|
|
|
|
|
sub new { |
|
43
|
|
|
|
|
|
|
my $self = shift->SUPER::new(@_); |
|
44
|
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
$self->fakeup_request_class; |
|
46
|
|
|
|
|
|
|
require Combust::Control::Basic; |
|
47
|
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
my $control = $self->{control} = Combust::Control::Basic->new; |
|
49
|
|
|
|
|
|
|
($control->{site} = $self->site) =~ s#/$##; |
|
50
|
|
|
|
|
|
|
my $path = $control->get_include_path; |
|
51
|
|
|
|
|
|
|
# warn join(', ', @$path); |
|
52
|
|
|
|
|
|
|
$control->tt->set_include_path([$self->site, 'shared', @$path]); |
|
53
|
|
|
|
|
|
|
return($self); |
|
54
|
|
|
|
|
|
|
} |
|
55
|
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
my %types = ( |
|
57
|
|
|
|
|
|
|
map({$_ => "image/$_"} qw(png jpg)), |
|
58
|
|
|
|
|
|
|
ico => 'image/x-icon', |
|
59
|
|
|
|
|
|
|
map({$_ => "application/"} qw(pdf)), |
|
60
|
|
|
|
|
|
|
ps => 'application/postscript', |
|
61
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
sub handler { |
|
73
|
|
|
|
|
|
|
my $self = shift; |
|
74
|
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
my $path = $self->path; |
|
76
|
|
|
|
|
|
|
$path =~ s{/$}{/index.html}; |
|
77
|
|
|
|
|
|
|
$path =~ s#^/##; |
|
78
|
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
# support runtime dep analysis |
|
80
|
|
|
|
|
|
|
exit if(Devel::TraceDeps->can('import') and $path eq 'exit'); |
|
81
|
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
local $self->control->request->{path} = '/' . $path; |
|
83
|
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
if($path !~ m/\.html$/) { |
|
85
|
|
|
|
|
|
|
my %params; |
|
86
|
|
|
|
|
|
|
my ($ext) = $path =~ m/\.([^\.]+)$/; |
|
87
|
|
|
|
|
|
|
if(my $type = $types{$ext}) { |
|
88
|
|
|
|
|
|
|
$params{content_type} = $type; |
|
89
|
|
|
|
|
|
|
} |
|
90
|
|
|
|
|
|
|
my $data = $self->control->tt->provider->expand_filename($path); |
|
91
|
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
my $file = $data->{path} or warn "no data for $path"; |
|
93
|
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
return $self->output(404, "no $path") unless($file and -e $file); |
|
95
|
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
my $content = do { |
|
97
|
|
|
|
|
|
|
open(my $fh, '<', $file) or |
|
98
|
|
|
|
|
|
|
warn "cannot open $file" and return $self->output(403, 'fail'); |
|
99
|
|
|
|
|
|
|
warn "static: $file\n"; |
|
100
|
|
|
|
|
|
|
local $/; <$fh>; |
|
101
|
|
|
|
|
|
|
}; |
|
102
|
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
return $self->output(\%params, $content); |
|
104
|
|
|
|
|
|
|
} |
|
105
|
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
warn "$path\n"; |
|
107
|
|
|
|
|
|
|
my $out = eval {$self->control->evaluate_template($path)}; |
|
108
|
|
|
|
|
|
|
if(my $err = $@) { |
|
109
|
|
|
|
|
|
|
return $self->output(404, $err); |
|
110
|
|
|
|
|
|
|
} |
|
111
|
|
|
|
|
|
|
#warn $out; |
|
112
|
|
|
|
|
|
|
$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
|
|
|
|
|
|
|
sub fakeup_request_class { |
|
127
|
|
|
|
|
|
|
package Combust::Request::Spontaneously; |
|
128
|
|
|
|
|
|
|
$INC{'Combust/Request/Spontaneously.pm'} = __FILE__; |
|
129
|
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
require Combust::Request; |
|
131
|
|
|
|
|
|
|
our @ISA = ('Combust::Request'); |
|
132
|
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
sub _r {shift} |
|
134
|
|
|
|
|
|
|
sub pnotes {shift->notes(@_)} |
|
135
|
|
|
|
|
|
|
sub dir_config {'.'} |
|
136
|
|
|
|
|
|
|
sub document_root {'.'} |
|
137
|
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
sub req_param {''} |
|
139
|
|
|
|
|
|
|
sub get_cookie {''} |
|
140
|
|
|
|
|
|
|
sub args { 'thbbt' } |
|
141
|
|
|
|
|
|
|
sub uri { shift->{path} } |
|
142
|
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
} |
|
144
|
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
=head1 AUTHOR |
|
148
|
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
Eric Wilhelm @ |
|
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. 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; |