Permalink
Browse files

Merge branch 'master' of git://github.com/sukria/Dancer

  • Loading branch information...
2 parents 930f678 + a798e5b commit 98aec09a9ed3509aeb1055b9faa6416efacd17da sawyer committed Jan 29, 2010
View
@@ -1,3 +1,8 @@
+Dancer 1.123~
+ * Fix a memory leak that could occur between two
+ requests under mod_perl (Thanks to Nicolas Rennert for
+ the report and diagnosis).
+
Dancer 1.122
* Fix the test suite under Perl 5.8.x
View
46 TODO
@@ -13,49 +13,3 @@
1 - GET / -> first call, so browse the route tree
2 - GET / -> second call, return cache('/');
-* Conditions support for route matching:
-
- get '/foo', {agent => 'Songbird (\d\.\d)[\d\/]*?'} => sub {
- ...
- };
-
-* Prefix support
-
- Could be great to be able to define a prefix path for each
- route hanlder defined then.
-
- Would work like the following:
-
- prefix '/home';
-
- # any route handler and before filter is applied to /home/*
-
- get '/page1' => sub { }; # will match '/home/page1';
-
- prefix undef;
- # no more prefix
-
- get '/page1' => sub { }; # will match /page1
-
- And that should also work for before filters:
-
- prefix '/home';
- before sub { must_be_authenticated }; # this filter only applies to /home/* paths
-
-
-* Headers modifier helper
-
- A route handler should be able to alter any response
- header by hand.
-
- get '/' => sub {
- ...
-
- # a user-defined header
- header 'X-User-Header1' => 'Some Random Value';
- };
-
- Those inputs will go through the
- Dancer::Response::sanitize() method in order not to let
- go an invalid response.
-
View
@@ -22,44 +22,47 @@ use Dancer::Handler;
use base 'Exporter';
$AUTHORITY = 'SUKRIA';
-$VERSION = '1.122';
-@EXPORT = qw(
- any
- before
- cookies
- content_type
- dance
- debug
- del
- dirname
- error
- false
- get
- layout
- load
- logger
- mime_type
- options
- params
- pass
- path
- post
- put
- r
- redirect
- request
- send_file
- send_error
- set
- set_cookie
- session
- splat
- status
- template
- true
- var
- vars
- warning
+$VERSION = '1.123';
+@EXPORT = qw(
+ any
+ before
+ cookies
+ content_type
+ dance
+ debug
+ del
+ dirname
+ error
+ false
+ get
+ header
+ headers
+ layout
+ load
+ logger
+ mime_type
+ options
+ params
+ pass
+ path
+ post
+ prefix
+ put
+ r
+ redirect
+ request
+ send_file
+ send_error
+ set
+ set_cookie
+ session
+ splat
+ status
+ template
+ true
+ var
+ vars
+ warning
);
# Dancer's syntax
@@ -72,57 +75,65 @@ sub debug { Dancer::Logger->debug(@_) }
sub dirname { Dancer::FileUtils::dirname(@_) }
sub error { Dancer::Logger->error(@_) }
sub send_error { Dancer::Helpers->error(@_) }
-sub false { 0 }
-sub get { Dancer::Route->add('head', @_);
- Dancer::Route->add('get', @_);}
-sub layout { set(layout => shift) }
-sub logger { set(logger => @_) }
-sub load { require $_ for @_ }
-sub mime_type { Dancer::Config::mime_types(@_) }
-sub params { Dancer::SharedData->params }
+sub false {0}
+
+sub get {
+ Dancer::Route->add('head', @_);
+ Dancer::Route->add('get', @_);
+}
+sub headers { Dancer::Response::headers(@_); }
+sub header { goto &headers; } # goto ftw!
+sub layout { set(layout => shift) }
+sub logger { set(logger => @_) }
+sub load { require $_ for @_ }
+sub mime_type { Dancer::Config::mime_types(@_) }
+sub params { Dancer::SharedData->params }
+
# sub pass { Dancer::Response::pass() }
-sub pass { pass_exception }
-sub path { Dancer::FileUtils::path(@_) }
-sub post { Dancer::Route->add('post', @_) }
-sub del { Dancer::Route->add('delete', @_) }
-sub options { Dancer::Route->add('options', @_) }
-sub put { Dancer::Route->add('put', @_) }
-sub r { {regexp => $_[0]} }
-sub redirect { Dancer::Helpers::redirect(@_) }
-sub request { Dancer::SharedData->request }
-sub send_file { Dancer::Helpers::send_file(@_) }
-sub set { setting(@_) }
-sub set_cookie { Dancer::Helpers::set_cookie(@_) }
-sub session {
+sub pass {pass_exception}
+sub path { Dancer::FileUtils::path(@_) }
+sub post { Dancer::Route->add('post', @_) }
+sub prefix { Dancer::Route->prefix(@_) }
+sub del { Dancer::Route->add('delete', @_) }
+sub options { Dancer::Route->add('options', @_) }
+sub put { Dancer::Route->add('put', @_) }
+sub r { {regexp => $_[0]} }
+sub redirect { Dancer::Helpers::redirect(@_) }
+sub request { Dancer::SharedData->request }
+sub send_file { Dancer::Helpers::send_file(@_) }
+sub set { setting(@_) }
+sub set_cookie { Dancer::Helpers::set_cookie(@_) }
+
+sub session {
if (@_ == 0) {
return Dancer::Session->get;
}
else {
return (@_ == 1)
- ? Dancer::Session->read(@_)
- : Dancer::Session->write(@_)
+ ? Dancer::Session->read(@_)
+ : Dancer::Session->write(@_);
}
}
-sub splat { @{ Dancer::SharedData->params->{splat} } }
-sub status { Dancer::Response::status(@_) }
-sub template { Dancer::Helpers::template(@_) }
-sub true { 1 }
-sub var { Dancer::SharedData->var(@_) }
-sub vars { Dancer::SharedData->vars }
-sub warning { Dancer::Logger->warning(@_) }
+sub splat { @{Dancer::SharedData->params->{splat}} }
+sub status { Dancer::Response::status(@_) }
+sub template { Dancer::Helpers::template(@_) }
+sub true {1}
+sub var { Dancer::SharedData->var(@_) }
+sub vars { Dancer::SharedData->vars }
+sub warning { Dancer::Logger->warning(@_) }
# When importing the package, strict and warnings pragma are loaded,
# and the appdir detection is performed.
sub import {
- my ($class, $symbol) = @_;
+ my ($class, $symbol) = @_;
my ($package, $script) = caller;
strict->import;
warnings->import;
- $class->export_to_level( 1, $class, @EXPORT );
+ $class->export_to_level(1, $class, @EXPORT);
# if :syntax option exists, don't change settings
- if ( $symbol && $symbol eq ':syntax' ) {
+ if ($symbol && $symbol eq ':syntax') {
return;
}
@@ -247,6 +258,21 @@ Routes may include some matching conditions (on the useragent and the hostname a
'all browsers except songbird'
}
+=head2 PREFIX
+
+A prefix can be defined for each route handler, like this:
+
+ prefix '/home';
+
+From here, any route handler is defined to /home/*
+
+ get '/page1' => sub {}; # will match '/home/page1'
+
+You can unset the prefix value
+
+ prefix undef;
+ get '/page1' => sub {}; will match /page1
+
=head2 NAMED MATCHING
A route pattern can contain one or more tokens (a word prefixed with ':'). Each
@@ -369,6 +395,23 @@ keyword B<content_type>
# here we can dump the contents of params->{txtfile}
};
+=head2 header(s)
+
+It is possible to add custom headers to responses with the B<header> (or B<headers>)
+keyword:
+
+ get '/send/header', sub {
+ header 'X-My-Header' => 'shazam!';
+ }
+
+or...
+
+ get '/send/headers', sub {
+ headers 'X-Foo' => 'bar', X-Bar => 'foo';
+ }
+
+You can use both undistinctly, they do exactly what you expect them to do.
+
=head1 ERROR HANDLING
=head2 DEFAULT ERROR PAGES
View
@@ -14,10 +14,11 @@ use Carp 'confess';
# singleton for storing settings
my $SETTINGS = {
- # default mime_types
- mime_types => Dancer::FileUtils->mime_types,
+
+ # default mime_types
+ mime_types => Dancer::FileUtils->mime_types,
};
-sub settings { $SETTINGS }
+sub settings {$SETTINGS}
my $setters = {
logger => sub {
@@ -37,25 +38,25 @@ my $setters = {
# public accessor for get/set
sub setting {
my ($setting, $value) = @_;
-
+
# run the hook if setter
- $setters->{$setting}->(@_)
- if (@_ == 2) && defined $setters->{$setting};
+ $setters->{$setting}->(@_)
+ if (@_ == 2) && defined $setters->{$setting};
# setter/getter
- (@_ == 2)
- ? $SETTINGS->{$setting} = $value
- : $SETTINGS->{$setting} ;
+ (@_ == 2)
+ ? $SETTINGS->{$setting} = $value
+ : $SETTINGS->{$setting};
}
sub mime_types {
my ($ext, $content_type) = @_;
$SETTINGS->{mime_types} ||= {};
return $SETTINGS->{mime_types} if @_ == 0;
- return (@_ == 2)
- ? $SETTINGS->{mime_types}{$ext} = $content_type
- : $SETTINGS->{mime_types}{$ext};
+ return (@_ == 2)
+ ? $SETTINGS->{mime_types}{$ext} = $content_type
+ : $SETTINGS->{mime_types}{$ext};
}
sub conffile { path(setting('appdir'), 'config.yml') }
@@ -65,7 +66,8 @@ sub environment_file {
return path(setting('appdir'), 'environments', "$env.yml");
}
-sub load {
+sub load {
+
# look for the conffile
return 1 unless -f conffile;
@@ -89,8 +91,8 @@ sub load {
sub load_settings_from_yaml {
my ($file) = @_;
- my $config = YAML::LoadFile($file) or
- confess "Unable to parse the configuration file: $file";
+ my $config = YAML::LoadFile($file)
+ or confess "Unable to parse the configuration file: $file";
@{$SETTINGS}{keys %$config} = values %$config;
return scalar(keys %$config);
@@ -114,6 +116,7 @@ load_default_settings();
1;
__END__
+
=pod
=head1 NAME
Oops, something went wrong.

0 comments on commit 98aec09

Please sign in to comment.