From 3e6f5d7af66df24fef53ae4f40b11dfa886cc511 Mon Sep 17 00:00:00 2001 From: Alexis Sukrieh Date: Thu, 23 Jul 2009 12:43:32 +0200 Subject: [PATCH] new default settings: 'appdir' and 'public' --- Makefile.PL | 2 ++ lib/Dancer.pm | 21 +++++++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/Makefile.PL b/Makefile.PL index 124b569e0..5b0e77b77 100644 --- a/Makefile.PL +++ b/Makefile.PL @@ -7,6 +7,8 @@ WriteMakefile( 'CGI' => '0', 'HTTP::Server::Simple' => '0.36', 'Test::More' => '0', + 'File::Basename' => '0', + 'File::Spec' => '0', }, ABSTRACT => "A minimal-effort oriented web application framework", test => {TESTS => join( ' ', (glob( 't/*.t'), glob('t/*/*.t')))}, diff --git a/lib/Dancer.pm b/lib/Dancer.pm index fa5d30619..3dd2cea25 100644 --- a/lib/Dancer.pm +++ b/lib/Dancer.pm @@ -8,9 +8,13 @@ use Dancer::Config 'setting'; use Dancer::HTTP; use Dancer::Route; use Dancer::Response; + use HTTP::Server::Simple::CGI; use base 'Exporter', 'HTTP::Server::Simple::CGI'; +use File::Basename (); +use File::Spec; + $AUTHORITY = 'SUKRIA'; $VERSION = '0.1'; @EXPORT = qw( @@ -23,6 +27,8 @@ $VERSION = '0.1'; true false r + dirname + path ); # syntax sugar for our fellow users :) @@ -35,6 +41,8 @@ sub pass { Dancer::Response::pass() } sub true { 1 } sub false { 0 } sub r { {regexp => $_[0]} } +sub dirname { File::Basename::dirname(@_) } +sub path { File::Spec->catfile(@_) } # The run method to call for starting the job sub dance { @@ -97,6 +105,19 @@ sub print_response { print STDERR "== $method $path $st"; } +# When importing the package, strict and warnings pragma are loaded, +# and the appdir detection is performed. +sub import { + my ($package, $script) = caller; + strict->import; + warnings->import; + + setting appdir => dirname(File::Spec->rel2abs($script)); + setting public => path(setting('appdir'), 'public'); + + Dancer->export_to_level(1, @_); +} + 'Dancer'; __END__