3 use Web::Simple __PACKAGE__;
7 use HTML::Zoom::FilterBuilder::Template;
14 my ( $self, $filename ) = @_;
15 return do { local (@ARGV, $/) = $filename; <> };
18 sub template_filename_for {
19 my ( $self, $name ) = @_;
20 return "root/html/${name}.html";
25 return $self->{'template_zoom_for_template'}{'layout'} ||= HTML::Zoom->from_file(
26 $self->template_filename_for('layout')
30 sub template_zoom_for {
31 my ( $self, $template_name ) = @_;
32 $self->{'template_zoom_for_template'}{$template_name} ||= do {
34 HTML::Zoom->from_file(
35 $self->template_filename_for($template_name)
36 )->select('#content')->collect_content({ into => \@body })->run;
38 ->select('#content')->replace_content(\@body)
45 return $self->slurp( $self->template_filename_for('error_404') );
49 my ( $self, $args ) = @_;
50 my ( $status, $header, $body ) = @$args{qw/status_code header body/};
51 return [ $status || 200, [
52 $header ? ( %$header ) : (),
53 'Content-type' => 'text/html',
54 ], ref $body ? $body->to_fh : [ $body ] ];
57 sub index_page_content {
59 my $index_filename = $self->template_filename_for('index');
60 my $index_st = stat($index_filename)
61 or die "No $index_filename: $!";
62 $self->html_response({
63 header => { 'Last-Modified' => $index_st->mtime },
64 body => $self->slurp($index_filename),
68 sub dispatch_request {
72 $self->index_page_content;
75 sub ( /about|/about/ ) {
76 my $about_filename = $self->template_filename_for('about');
77 my $about_st = stat($about_filename)
78 or die "No $about_filename: $!";
79 $self->html_response({
81 'Last-Modified' => $about_st->mtime,
83 body => $self->slurp($about_filename),
87 sub ( /releases|/releases/ + ?* ) {
88 $self->index_page_content;
91 sub ( /dists|/dists/ + ?* ) {
92 $self->index_page_content;
95 sub ( /distribution/*|/distribution/*/ + ?* ) {
96 $self->index_page_content;
99 sub ( /authors|/authors/ + ?* ) {
100 $self->index_page_content;
103 sub ( /search|/search/ + ?q=&* ) {
104 $self->index_page_content;
109 around to_psgi_app => sub {
110 my ($orig, $self) = (shift, shift);
111 my $app = $self->$orig(@_);
113 enable_if { $ENV{PLACK_ENV} ne 'deployment' } 'Static',
114 path => qr{^/static},
116 enable 'ContentLength';
117 enable 'ConditionalGET';
118 enable 'ErrorDocument',
119 500 => 'root/html/error_500.html',
120 404 => 'root/html/index.html';
121 enable 'HTTPExceptions';
129 Wallace Reis, C<< <wreis at cpan.org> >>
131 =head1 LICENSE AND COPYRIGHT
133 © Copyright 2010-2011 Wallace Reis.
137 __PACKAGE__->run_if_script;