line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package JavaScript::Ectype::Handler::Apache2; |
2
|
1
|
|
|
1
|
|
39678
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
31
|
|
3
|
1
|
|
|
1
|
|
4
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
22
|
|
4
|
1
|
|
|
1
|
|
392
|
use JavaScript::Ectype::Loader; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
use Apache2::Const -compile => qw(OK); |
6
|
|
|
|
|
|
|
use Apache2::Request; |
7
|
|
|
|
|
|
|
use Apache2::RequestIO (); |
8
|
|
|
|
|
|
|
use Apache2::RequestRec (); |
9
|
|
|
|
|
|
|
use Apache2::RequestUtil (); |
10
|
|
|
|
|
|
|
use Apache2::Response (); |
11
|
|
|
|
|
|
|
use HTTP::Date; |
12
|
|
|
|
|
|
|
our $VERSION = q(0.0.1); |
13
|
|
|
|
|
|
|
use constant EXPIRE_TIME => 60*60*24*14; |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
sub _uri_to_path_and_file { |
17
|
|
|
|
|
|
|
my ( $request ) = @_; |
18
|
|
|
|
|
|
|
my $lib_path = $request->dir_config->get('EctypeLibPath'); |
19
|
|
|
|
|
|
|
my $prefix = $request->dir_config->get('EctypePrefix'); |
20
|
|
|
|
|
|
|
my $minify = $request->dir_config->get('EctypeMinify'); |
21
|
|
|
|
|
|
|
if( $request->uri =~ m/$prefix([a-zA-Z0-9_.]+)/ ){ |
22
|
|
|
|
|
|
|
my $uri = $1; |
23
|
|
|
|
|
|
|
return ( $lib_path , $uri, $minify); |
24
|
|
|
|
|
|
|
} |
25
|
|
|
|
|
|
|
} |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
sub _not_found { |
28
|
|
|
|
|
|
|
my ($class,$r ) = @_; |
29
|
|
|
|
|
|
|
$r->status(404); |
30
|
|
|
|
|
|
|
return Apache2::Const::OK; |
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
sub _not_modified { |
34
|
|
|
|
|
|
|
my ($class,$r ) = @_; |
35
|
|
|
|
|
|
|
$r->status(304); |
36
|
|
|
|
|
|
|
$r->err_headers_out->set('Expires', HTTP::Date::time2str( time() + &EXPIRE_TIME ) ); |
37
|
|
|
|
|
|
|
return Apache2::Const::OK; |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
sub handler : method { |
41
|
|
|
|
|
|
|
my ($class, $r) = @_; |
42
|
|
|
|
|
|
|
my ($lib_path,$fqn,$minify) = _uri_to_path_and_file( $r ); |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
my $jel = JavaScript::Ectype::Loader->new( |
45
|
|
|
|
|
|
|
path => $lib_path, |
46
|
|
|
|
|
|
|
target => $fqn, |
47
|
|
|
|
|
|
|
minify => int($minify) |
48
|
|
|
|
|
|
|
); |
49
|
|
|
|
|
|
|
my $ims = HTTP::Date::str2time($r->headers_in->{'If-Modified-Since'}) || 0; |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
return $class->_not_found($r) unless ( $lib_path or $fqn ); |
52
|
|
|
|
|
|
|
return $class->_not_found($r) unless -e $jel->file_path; |
53
|
|
|
|
|
|
|
return $class->_not_modified($r) unless $jel->is_modified_from($ims); |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
$jel->load_content; |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
my $content = $jel->get_content; |
58
|
|
|
|
|
|
|
my $last_modified = $jel->newest_mtime; |
59
|
|
|
|
|
|
|
$r->status(200); |
60
|
|
|
|
|
|
|
$r->content_type('text/javascript'); |
61
|
|
|
|
|
|
|
$r->headers_out->set('Content-length', length $content ); |
62
|
|
|
|
|
|
|
$r->headers_out->set('Last-Modified', HTTP::Date::time2str($last_modified) ); |
63
|
|
|
|
|
|
|
$r->headers_out->set('Expires', HTTP::Date::time2str( time() + &EXPIRE_TIME ) ); |
64
|
|
|
|
|
|
|
$r->print( $content ); |
65
|
|
|
|
|
|
|
return Apache2::Const::OK; |
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
1; |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
__END__ |