Permalink
Browse files

page rendering support

  • Loading branch information...
1 parent 6f866e2 commit ca023038e3633ca7e54f38f9fc1387e6aeb30426 @typester committed Nov 18, 2009
View
@@ -1,4 +1,4 @@
Revision history for Perl extension Nim
- 0.01 Wed Jan 14 10:31:43 2009
+ 0.01 Thu Nov 5 20:48:07 2009
- original version
View
@@ -1,26 +0,0 @@
-Changes
-inc/Module/Install.pm
-inc/Module/Install/Base.pm
-inc/Module/Install/Can.pm
-inc/Module/Install/Fetch.pm
-inc/Module/Install/Include.pm
-inc/Module/Install/Makefile.pm
-inc/Module/Install/Metadata.pm
-inc/Module/Install/TestBase.pm
-inc/Module/Install/Win32.pm
-inc/Module/Install/WriteAll.pm
-inc/Spiffy.pm
-inc/Test/Base.pm
-inc/Test/Base/Filter.pm
-inc/Test/Builder.pm
-inc/Test/Builder/Module.pm
-inc/Test/More.pm
-lib/Nim.pm
-LICENSE
-Makefile.PL
-MANIFEST This list of files
-META.yml
-README
-t/00_compile.t
-t/pod.t
-t/pod_coverage.t
View
@@ -4,5 +4,9 @@ all_from 'lib/Nim.pm';
test_requires 'Test::More';
use_test_base;
+author_tests('xt');
+
auto_include;
+auto_set_repository;
+
WriteAll;
View
@@ -9,37 +9,65 @@ use Getopt::Long;
use Nim;
+use Carp;
+
+local $SIG{__DIE__} = sub { Carp::confess(@_) };
+
GetOptions(
\my %options,
- qw/help flavour=s debug/
+ qw/help server port=i host=s/
);
pod2usage(0) if $options{help};
my $nim = Nim->new;
$nim->run;
-__END__
-
-=head1 NAME
-
-nim - minimal command-line based contents generator
-
-=head1 SYNOPSIS
-
- nim [options]
-
-=head1 AUTHOR
-
-Daisuke Murase <typester@cpan.org>
-
-=head1 COPYRIGHT & LICENSE
-
-Copyright (c) 2009 KAYAC Inc. All rights reserved.
-
-This program is free software; you can redistribute
-it and/or modify it under the same terms as Perl itself.
-
-The full text of the license can be found in the
-LICENSE file included with this module.
-
-=cut
+# delay the build process for reloader
+sub build(&;$) {
+ my $block = shift;
+ my $app = shift || sub { };
+ return sub { $block->($app->()) };
+}
+
+if ($options{server}) {
+ $nim->log->info('Starting build-in server');
+
+ my $handler = sub {
+ sub {
+ my $env = shift;
+ my @path = grep { $_ } split '/', $env->{PATH_INFO};
+ my $fn = pop @path || 'index.html';
+
+ my $dir = $nim->conf->site_dir;
+ $dir = $dir->subdir(@path) if @path;
+
+ my $file = $dir->file($fn);
+ $file = $dir->subdir($file->basename)->file('index.html') if -d $file;
+
+ if (-f $file) {
+ require Plack::App::File;
+ my $type = Plack::App::File->mime_type_for($file);
+
+ my $fh = $file->openr or die $!;
+ return [
+ 200,
+ [ 'Content-Type' => $type, 'Content-Length' => -s $fh ],
+ $fh
+ ];
+ }
+ else {
+ return [ 404, [ "Content-Type" => "text/plain" ], [ "Not Found" ] ];
+ }
+ };
+ };
+ require Plack::Middleware::AccessLog;
+ $handler = build {
+ Plack::Middleware::AccessLog->wrap( $_[0], logger => sub { print STDERR @_ } );
+ } $handler;
+
+ require Plack::Loader;
+ $options{port} ||= 4423;
+ $options{host} ||= '0.0.0.0';
+
+ Plack::Loader->auto(%options)->run($handler->());
+}
Oops, something went wrong.

0 comments on commit ca02303

Please sign in to comment.