Skip to content

Commit

Permalink
new default settings: 'appdir' and 'public'
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexis Sukrieh committed Jul 23, 2009
1 parent a91b647 commit 3e6f5d7
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
2 changes: 2 additions & 0 deletions Makefile.PL
Expand Up @@ -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')))},
Expand Down
21 changes: 21 additions & 0 deletions lib/Dancer.pm
Expand Up @@ -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(
Expand All @@ -23,6 +27,8 @@ $VERSION = '0.1';
true
false
r
dirname
path
);

# syntax sugar for our fellow users :)
Expand All @@ -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 {
Expand Down Expand Up @@ -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__
Expand Down

0 comments on commit 3e6f5d7

Please sign in to comment.