Skip to content

Commit

Permalink
Merge branch 'release/1.3001'
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexis Sukrieh committed Jan 27, 2011
2 parents 9455e2d + 7b6d9ed commit 36ea7e8
Show file tree
Hide file tree
Showing 33 changed files with 1,263 additions and 1,037 deletions.
1,420 changes: 729 additions & 691 deletions CHANGES

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion MANIFEST
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ lib/Dancer/Logger.pm
lib/Dancer/Logger/Abstract.pm
lib/Dancer/Logger/Console.pm
lib/Dancer/Logger/File.pm
lib/Dancer/MIME.pm
lib/Dancer/ModuleLoader.pm
lib/Dancer/Object.pm
lib/Dancer/Object/Singleton.pm
Expand Down Expand Up @@ -66,7 +67,6 @@ lib/Dancer/Template/TemplateToolkit.pm
lib/Dancer/Test.pm
lib/Dancer/Timer.pm
lib/Dancer/Tutorial.pod
lib/Dancer/Tutorial/WebSockets.pod
LICENSE
Makefile.PL
MANIFEST This list of files
Expand Down
53 changes: 47 additions & 6 deletions lib/Dancer.pm
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,14 @@ use Dancer::Session;
use Dancer::SharedData;
use Dancer::Handler;
use Dancer::ModuleLoader;

use Dancer::MIME;
use File::Spec;
use File::Basename 'basename';

use base 'Exporter';

$AUTHORITY = 'SUKRIA';
$VERSION = '1.3000_02';
$VERSION = '1.3001';
@EXPORT = qw(
after
any
Expand Down Expand Up @@ -129,7 +129,12 @@ sub header { goto &headers; } # goto ftw!
sub layout { set(layout => shift) }
sub load { require $_ for @_ }
sub logger { set(logger => @_) }
sub mime_type { Dancer::Config::mime_types(@_) }
sub mime_type {
my $mime = Dancer::MIME->instance();
if (scalar(@_)==2) { $mime->add_mime_type(@_) }
elsif (scalar(@_)==1) { $mime->mime_type_for(@_) }
else { $mime->aliases }
}
sub params { Dancer::SharedData->request->params(@_) }
sub pass { Dancer::Response->pass }
sub path { realpath(Dancer::FileUtils::path(@_)) }
Expand All @@ -138,7 +143,7 @@ sub prefix { Dancer::App->current->set_prefix(@_) }
sub del { Dancer::App->current->registry->universal_add('delete', @_) }
sub options { Dancer::App->current->registry->universal_add('options', @_) }
sub put { Dancer::App->current->registry->universal_add('put', @_) }
sub r { carp "'r' is DEPRECATED use qr{} instead"; return {regexp => $_[0]} }
sub r { croak "'r' is DEPRECATED use qr{} instead"; }
sub redirect { Dancer::Helpers::redirect(@_) }
sub render_with_layout { Dancer::Helpers::render_with_layout(@_); }
sub request { Dancer::SharedData->request }
Expand Down Expand Up @@ -329,18 +334,21 @@ Dancer apps can be used with a an embedded web server (great for easy testing),
and can run under PSGI/Plack for easy deployment in a variety of webserver
environments.
=head1 DISCLAIMER
=head1 MORE DOCUMENTATION
This documentation describes all the exported symbols of Dancer. If you want
a quick start guide to discover the framework, you should look at
L<Dancer::Introduction>.
L<Dancer::Introduction>, or L<Dancer::Tutorial> to learn by example.
If you want to have specific examples of code for real-life problems, see the
L<Dancer::Cookbook>.
If you want to see configuration examples of different deployment solutions
involving Dancer and Plack, see L<Dancer::Deployment>.
You can find out more about the many useful plugins available for Dancer in
L<Dancer::Plugins>.
=head1 METHODS
=head2 after
Expand Down Expand Up @@ -412,6 +420,14 @@ Accesses cookies values, which returns a hashref of L<Dancer::Cookie> objects:
return $cookie->value;
};
In the case you have stored something else than a scalar in your cookie:
get '/some_action' => sub {
my $cookie = cookies->{oauth};
my %values = $cookie->value;
return ($values{token}, $values{token_secret});
};
=head2 config
Accesses the configuration of the application:
Expand All @@ -430,6 +446,14 @@ Sets the B<content-type> rendered, for the current route handler:
# here we can dump the contents of params->{txtfile}
};
You can use abbreviations for content types. For instance:
get '/svg/:id' => sub {
content_type 'svg';
# here we can dump the image with id params->{id}
};
Note that if you want to change the default content-type for every route, you
have to change the setting C<content_type> instead.
Expand Down Expand Up @@ -777,6 +801,8 @@ Lets the current route handler send a file to the client.
The content-type will be set depending on the current mime-types definition
(see C<mime_type> if you want to define your own).
The path of the file must be relative to the B<public> directory.
=head2 set
Defines a setting:
Expand All @@ -801,6 +827,18 @@ Creates or updates cookie values:
In the example above, only 'name' and 'value' are mandatory.
You can also store more complex structure in your cookies:
get '/some_auth' => sub {
set_cookie oauth => {
token => $twitter->request_token,
token_secret => $twitter->secret_token,
...
};
};
You can't store more complex structure than this. All your keys in your hash should be scalar.
=head2 session
Provides access to all data stored in the current
Expand Down Expand Up @@ -1015,6 +1053,9 @@ L<http://github.com/sukria/Dancer>
The Dancer development team can be found on #dancer on irc.perl.org:
L<irc://irc.perl.org/dancer>
If you don't have an IRC client installed/configured, there is a simple web chat
client at L<http://www.perldancer.org/irc> for you.
There is also a Dancer users mailing list available - subscribe at:
L<http://lists.perldancer.org/cgi-bin/listinfo/dancer-users>
Expand Down
27 changes: 10 additions & 17 deletions lib/Dancer/Config.pm
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,11 @@ use Encode;

@EXPORT_OK = qw(setting mime_types);

my $SETTINGS = {};

# mergeable settings
my %MERGEABLE = map { ($_ => 1) } qw( plugins handlers );

# singleton for storing settings
my $SETTINGS = {

# user defined mime types
mime_types => {},
};

sub settings {$SETTINGS}

my $setters = {
Expand Down Expand Up @@ -89,6 +84,14 @@ my $normalizers = {
},
};

sub mime_types {
carp "DEPRECATED: use 'mime_type' from Dancer.pm";
my $mime = Dancer::MIME->instance();
if (scalar(@_)==2) { $mime->add_mime_type(@_) }
elsif (scalar(@_)==1) { $mime->mime_type_for(@_) }
else { $mime->aliases }
}

sub normalize_setting {
my ($class, $setting, $value) = @_;

Expand Down Expand Up @@ -135,16 +138,6 @@ sub _get_setting {
return $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};
}

sub conffile { path(setting('confdir') || setting('appdir'), 'config.yml') }

sub environment_file {
Expand Down
23 changes: 20 additions & 3 deletions lib/Dancer/Cookie.pm
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@ package Dancer::Cookie;
use strict;
use warnings;

use URI::Escape;

use base 'Dancer::Object';
__PACKAGE__->attributes('name', 'value', 'expires', 'domain', 'path');
__PACKAGE__->attributes('name', 'expires', 'domain', 'path');

sub init {
my $self = shift;
my ($self, %args) = @_;
$self->value($args{value});
if ($self->expires) {
$self->expires(_epoch_to_gmtstring($self->expires))
if $self->expires =~ /^\d+$/;
Expand All @@ -17,13 +20,27 @@ sub init {
sub to_header {
my $self = shift;
my $header = '';
$header .= $self->name . '=' . $self->value . '; ';

my $value = join('&', map {uri_escape($_)} $self->value);
$header .= $self->name . '=' . $value . '; ';
$header .= "path=" . $self->path . "; " if $self->path;
$header .= "expires=" . $self->expires . "; " if $self->expires;
$header .= "domain=" . $self->domain . "; " if $self->domain;
$header .= 'HttpOnly';
}

sub value {
my ( $self, $value ) = @_;
if ( defined $value ) {
my @values =
ref $value eq 'ARRAY' ? @$value
: ref $value eq 'HASH' ? %$value
: ($value);
$self->{'value'} = [@values];
}
return wantarray ? @{ $self->{'value'} } : $self->{'value'}->[0];
}

sub _epoch_to_gmtstring {
my ($epoch) = @_;

Expand Down
13 changes: 10 additions & 3 deletions lib/Dancer/Cookies.pm
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ use warnings;
use Dancer::Cookie;
use Dancer::SharedData;

use URI::Escape;

# all cookies defined by the application are store in that singleton
# this is a hashref the represent all key/value pairs to store as cookies
my $COOKIES = {};
Expand All @@ -21,11 +23,16 @@ sub parse_cookie_from_env {
return {} unless defined $env_str;

my $cookies = {};
foreach my $cookie (split('; ', $env_str)) {
my ($name, $value) = split('=', $cookie);
foreach my $cookie ( split( '; ', $env_str ) ) {
my ( $name, $value ) = split( '=', $cookie );
my @values;
if ( $value ne '' ) {
@values = map { uri_unescape($_) } split( /[&;]/, $value );
}
$cookies->{$name} =
Dancer::Cookie->new(name => $name, value => $value);
Dancer::Cookie->new( name => $name, value => \@values );
}

return $cookies;
}

Expand Down
Loading

0 comments on commit 36ea7e8

Please sign in to comment.