Skip to content

Commit

Permalink
Start using Template toolkit to show the empty pages
Browse files Browse the repository at this point in the history
  • Loading branch information
szabgab committed Oct 20, 2014
1 parent 94db292 commit 0ce8f29
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 1 deletion.
3 changes: 3 additions & 0 deletions Makefile.PL
Expand Up @@ -7,7 +7,10 @@ my %conf = (
AUTHOR => 'Gabor Szabo <szabgab@cpan.org>', AUTHOR => 'Gabor Szabo <szabgab@cpan.org>',
VERSION_FROM => 'lib/MetaCPAN/SCO.pm', VERSION_FROM => 'lib/MetaCPAN/SCO.pm',
PREREQ_PM => { PREREQ_PM => {
'Cwd' => '0',
'File::Basename' => '0',
'Plack::Request' => '0', 'Plack::Request' => '0',
'Template' => '0',
}, },
); );


Expand Down
26 changes: 25 additions & 1 deletion lib/MetaCPAN/SCO.pm
Expand Up @@ -2,7 +2,10 @@ package MetaCPAN::SCO;
use strict; use strict;
use warnings; use warnings;


use Cwd qw(abs_path);
use File::Basename qw(dirname);
use Plack::Request; use Plack::Request;
use Template;


our $VERSION = '0.01'; our $VERSION = '0.01';


Expand All @@ -18,13 +21,34 @@ sub run {


my $request = Plack::Request->new($env); my $request = Plack::Request->new($env);
if ($request->path_info eq '/') { if ($request->path_info eq '/') {
return [ '200', [ 'Content-Type' => 'text/plain' ], ['Hello'], ]; return template('index');
} }


return [ '404', [ 'Content-Type' => 'text/html' ], ['404 Not Found'], ]; return [ '404', [ 'Content-Type' => 'text/html' ], ['404 Not Found'], ];
}; };
} }


sub template {
my ( $file ) = @_;

my $root = dirname(dirname(dirname( abs_path(__FILE__) )));

my $tt = Template->new(
INCLUDE_PATH => "$root/tt",
INTERPOLATE => 0,
POST_CHOMP => 1,
EVAL_PERL => 1,
START_TAG => '<%',
END_TAG => '%>',
PRE_PROCESS => 'incl/header.tt',
POST_PROCESS => 'incl/footer.tt',
);
my $out;
$tt->process( "$file.tt", {}, \$out )
|| die $tt->error();
return [ '200', [ 'Content-Type' => 'text/html' ], [$out], ];
}



1; 1;


2 changes: 2 additions & 0 deletions tt/incl/footer.tt
@@ -0,0 +1,2 @@
</body>
</html>
5 changes: 5 additions & 0 deletions tt/incl/header.tt
@@ -0,0 +1,5 @@
<html>
<head>
<title>The CPAN Search Site - search.cpan.org</title>
</head>
<body>
1 change: 1 addition & 0 deletions tt/index.tt
@@ -0,0 +1 @@
MetaCPAN::SCO

0 comments on commit 0ce8f29

Please sign in to comment.