Skip to content

Commit

Permalink
Merge branch 'release/1.3011'
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexis Sukrieh committed Feb 14, 2011
2 parents 61aa0c0 + 6c9fd85 commit 7df377b
Show file tree
Hide file tree
Showing 8 changed files with 87 additions and 30 deletions.
17 changes: 17 additions & 0 deletions CHANGES
@@ -1,3 +1,20 @@
1.3011 14.02.2011

[ BUG FIXES ]
* Set binmode in write_data_to_file() to fix image corruption in
Windows
(Rowan Thorpe)
* GH#319, GH#278, GH#276, GH#217: Fix file issues on Cygwin and
Win32 platforms
(Rowan Thorpe)
* GH#322: Detect errors in scaffolded dispatchers
(Alberto Simões)
* Fix tests so that they don't fail if JSON is not installed
(Damien Krotkine)

[ DOCUMENTATION ]
* Small spaces fix (Alberto Simões).

1.3010_01 12.02.2011 1.3010_01 12.02.2011


[ BUG FIXES ] [ BUG FIXES ]
Expand Down
8 changes: 3 additions & 5 deletions lib/Dancer.pm
Expand Up @@ -3,11 +3,11 @@ package Dancer;
use strict; use strict;
use warnings; use warnings;
use Carp; use Carp;
use Cwd 'abs_path', 'realpath'; use Cwd 'realpath';


use vars qw($VERSION $AUTHORITY @EXPORT); use vars qw($VERSION $AUTHORITY @EXPORT);


$VERSION = '1.3010_01'; $VERSION = '1.3011';
$AUTHORITY = 'SUKRIA'; $AUTHORITY = 'SUKRIA';


use Dancer::Config; use Dancer::Config;
Expand All @@ -30,7 +30,6 @@ use Dancer::Handler;
use Dancer::ModuleLoader; use Dancer::ModuleLoader;
use Dancer::MIME; use Dancer::MIME;
use File::Spec; use File::Spec;
use File::Basename 'basename';


use base 'Exporter'; use base 'Exporter';


Expand Down Expand Up @@ -186,7 +185,6 @@ sub load_app {
$app->prefix($options{prefix}) if $options{prefix}; $app->prefix($options{prefix}) if $options{prefix};
$app->settings($options{settings}) if $options{settings}; $app->settings($options{settings}) if $options{settings};



# load the application # load the application
my ($package, $script) = caller; my ($package, $script) = caller;
_init($script); _init($script);
Expand Down Expand Up @@ -240,7 +238,7 @@ sub _init {
my ($script_vol, $script_dirs, $script_name) = my ($script_vol, $script_dirs, $script_name) =
File::Spec->splitpath(File::Spec->rel2abs($script)); File::Spec->splitpath(File::Spec->rel2abs($script));
my @script_dirs = File::Spec->splitdir($script_dirs); my @script_dirs = File::Spec->splitdir($script_dirs);
my $script_path = File::Spec->catdir($script_vol, $script_dirs); my $script_path = Dancer::FileUtils::d_catdir($script_vol, $script_dirs);


my $LAYOUT_PRE_DANCER_1_2 = 1; my $LAYOUT_PRE_DANCER_1_2 = 1;


Expand Down
31 changes: 26 additions & 5 deletions lib/Dancer/FileUtils.pm
Expand Up @@ -13,16 +13,37 @@ use vars '@EXPORT_OK';


@EXPORT_OK = qw(path dirname read_file_content read_glob_content open_file); @EXPORT_OK = qw(path dirname read_file_content read_glob_content open_file);


sub path { # Undo UNC special-casing catfile-voodoo on cygwin in the next three functions
File::Spec->catfile(@_); sub d_catfile {
my $root = shift;
$root =~ s{^[/\\]+([/\\])}{$1};
File::Spec->catfile($root, @_);
} }
sub d_catdir {
my $root = shift;
$root =~ s{^[/\\]+([/\\])}{$1};
File::Spec->catdir($root, @_);
}
sub d_canonpath {
my $root = shift;
$root =~ s{^[/\\]+([/\\])}{$1};
File::Spec->canonpath($root, @_);
}

sub path { d_catfile(@_) }


sub path_no_verify { sub path_no_verify {
my @nodes = @_; my @nodes = @_;
my $path = '';


# [0->?] path(must exist),[last] file(maybe exists) # [0->?] path(must exist),[last] file(maybe exists)
return realpath(File::Spec->catdir(@nodes[0 .. ($#nodes - 1)])) . '/' if($#nodes > 0) {
. $nodes[-1]; $path = realpath(d_catdir(@nodes[0 .. ($#nodes - 1)])).'/';
} elsif(not File::Spec->file_name_is_absolute($nodes[0])) {
$path = Cwd::cwd.'/';
}
$path .= d_canonpath($nodes[$#nodes]);
return $path;
} }


sub dirname { File::Basename::dirname(@_) } sub dirname { File::Basename::dirname(@_) }
Expand All @@ -44,7 +65,7 @@ sub read_file_content {


if ($file) { if ($file) {
$fh = open_file('<', $file); $fh = open_file('<', $file);

return wantarray ? read_glob_content($fh) : scalar read_glob_content($fh); return wantarray ? read_glob_content($fh) : scalar read_glob_content($fh);
} }
else { else {
Expand Down
34 changes: 23 additions & 11 deletions lib/Dancer/Logger/File.pm
Expand Up @@ -6,31 +6,43 @@ use base 'Dancer::Logger::Abstract';


use File::Spec; use File::Spec;
use Dancer::Config 'setting'; use Dancer::Config 'setting';
use Dancer::FileUtils qw(path open_file); use Dancer::FileUtils qw(open_file);
use IO::File; use IO::File;


sub logdir { sub logdir {
my $appdir = setting('appdir');
my $altpath = setting('log_path'); my $altpath = setting('log_path');
my $logroot = $appdir || File::Spec->tmpdir(); return $altpath if($altpath);
return ($altpath ? $altpath : path($logroot, 'logs')); my $appdir = setting('appdir');
my $logroot = $appdir;
unless($logroot) {
$logroot = Dancer::FileUtils::d_canonpath(File::Spec->tmpdir().'/dancer-'.$$);
if (!-d $logroot and not mkdir $logroot) {
carp "log directory $logroot doesn't exist, unable to create";
return;
}
}
return Dancer::FileUtils::path_no_verify($logroot, 'logs');
} }


sub init { sub init {
my ($self) = @_; my ($self) = @_;
my $logdir = logdir(); my $logdir = logdir();


if (!-d $logdir) { if (!-d $logdir && not mkdir $logdir) {
if (not mkdir $logdir) { carp "log directory $logdir doesn't exist, unable to create";
carp "log directory $logdir doesn't exist, unable to create"; return;
return; }
} if (!-w $logdir or !-x $logdir) {
my $perm = (stat $logdir)[2] & 07777;
chmod($perm | 0700, $logdir);
carp "log directory $logdir isn't writable/executable, can't chmod it";
return;
} }


my $logfile = setting('environment'); my $logfile = setting('environment');
$logfile = path($logdir, "$logfile.log"); $logfile = Dancer::FileUtils::path_no_verify($logdir, "$logfile.log");


my $fh = open_file('>>', $logfile); my $fh = open_file('>>', $logfile) or carp "unable to create or append to $logfile";


$fh->autoflush; $fh->autoflush;
$self->{logfile} = $logfile; $self->{logfile} = $logfile;
Expand Down
2 changes: 1 addition & 1 deletion lib/Dancer/Test.pm
Expand Up @@ -327,7 +327,7 @@ Asserts that the response content is equal to the C<$expected> string.
Asserts that the response content is not equal to the C<$not_expected> string. Asserts that the response content is not equal to the C<$not_expected> string.
response_content_is [GET => '/'], "Hello, World", response_content_isnt [GET => '/'], "Hello, World",
"got expected response content for GET /"; "got expected response content for GET /";
=head2 response_content_is_deeply([$method, $path], $expected_struct, $test_name) =head2 response_content_is_deeply([$method, $path], $expected_struct, $test_name)
Expand Down
10 changes: 7 additions & 3 deletions script/dancer
Expand Up @@ -60,7 +60,7 @@ sub validate_app_name {
if ($name =~ /[^\w:]/ || $name =~ /^\d/ || $name =~ /\b:\b|:{3,}/) { if ($name =~ /[^\w:]/ || $name =~ /^\d/ || $name =~ /\b:\b|:{3,}/) {
print STDERR "Error: Invalid application name.\n"; print STDERR "Error: Invalid application name.\n";
print STDERR "Application names must not contain colons," print STDERR "Application names must not contain colons,"
." dots or start with a number.\n"; ." dots or start with a number.\n";
exit; exit;
} }
} }
Expand Down Expand Up @@ -209,6 +209,7 @@ sub write_data_to_file {
my ($data, $path) = @_; my ($data, $path) = @_;
open(my $fh, '>', $path) open(my $fh, '>', $path)
or warn "Failed to write favicon to $path - $!" and return; or warn "Failed to write favicon to $path - $!" and return;
binmode($fh);
print {$fh} unpack 'u*', $data; print {$fh} unpack 'u*', $data;
close $fh; close $fh;
} }
Expand Down Expand Up @@ -487,12 +488,14 @@ set apphandler => 'PSGI';
set environment => 'production'; set environment => 'production';
my \$psgi = path(\$RealBin, '..', 'bin', 'app.pl'); my \$psgi = path(\$RealBin, '..', 'bin', 'app.pl');
die \"Unable to read startup script: \$psgi\" unless -r \$psgi;
Plack::Runner->run(\$psgi); Plack::Runner->run(\$psgi);
", ",




"dispatch.fcgi" => "dispatch.fcgi" =>
"$PERL_INTERPRETER qq{$PERL_INTERPRETER
use Dancer ':syntax'; use Dancer ':syntax';
use FindBin '\$RealBin'; use FindBin '\$RealBin';
use Plack::Handler::FCGI; use Plack::Handler::FCGI;
Expand All @@ -505,10 +508,11 @@ set environment => 'production';
my \$psgi = path(\$RealBin, '..', 'bin', 'app.pl'); my \$psgi = path(\$RealBin, '..', 'bin', 'app.pl');
my \$app = do(\$psgi); my \$app = do(\$psgi);
die "Unable to read startup script: \$@" if \$@;
my \$server = Plack::Handler::FCGI->new(nproc => 5, detach => 1); my \$server = Plack::Handler::FCGI->new(nproc => 5, detach => 1);
\$server->run(\$app); \$server->run(\$app);
", },


"app.pl" => "app.pl" =>


Expand Down
10 changes: 6 additions & 4 deletions t/01_config/03_logger.t
@@ -1,8 +1,11 @@
use Test::More tests => 15, import => ['!pass']; use Test::More tests => 15, import => ['!pass'];


use Dancer ':syntax'; use Dancer ':syntax';
use Dancer::FileUtils;


use File::Temp qw/tempdir/; use File::Temp qw/tempdir/;
use File::Spec qw/catfile/;

my $dir = tempdir(CLEANUP => 1); my $dir = tempdir(CLEANUP => 1);
set appdir => $dir; set appdir => $dir;


Expand All @@ -17,10 +20,10 @@ ok(debug($message), "debug sent");
ok(warning($message), "warning sent"); ok(warning($message), "warning sent");
ok(error($message), "error sent"); ok(error($message), "error sent");


my $logdir = path(setting('appdir'), 'logs'); my $logdir = Dancer::FileUtils::path_no_verify(setting('appdir'), 'logs');
ok((-d $logdir), "log directory exists"); ok((-d $logdir), "log directory exists");


my $logfile = path($logdir, "development.log"); my $logfile = Dancer::FileUtils::d_catfile($logdir, "development.log");
ok((-r $logfile), "logfile exists"); ok((-r $logfile), "logfile exists");


open LOGFILE, '<', $logfile; open LOGFILE, '<', $logfile;
Expand All @@ -36,14 +39,13 @@ unlink $logfile;
set environment => 'test'; set environment => 'test';
logger 'file'; logger 'file';


$logfile = path($logdir, "test.log"); $logfile = Dancer::FileUtils::d_catfile($logdir, "test.log");
ok((-r $logfile), "environment logfile exists"); ok((-r $logfile), "environment logfile exists");


open LOGFILE, '<', $logfile; open LOGFILE, '<', $logfile;
@content = <LOGFILE>; @content = <LOGFILE>;
close LOGFILE; close LOGFILE;



ok(set(log => 'warning'), 'log level set to warning'); ok(set(log => 'warning'), 'log level set to warning');


ok(!debug($message), 'debug message is dropped'); ok(!debug($message), 'debug message is dropped');
Expand Down
5 changes: 4 additions & 1 deletion t/12_response/06_filter_halt_status.t
@@ -1,6 +1,9 @@
use strict; use strict;
use warnings; use warnings;
use Test::More; use Test::More import => ['!pass'];;

plan skip_all => "JSON is needed to run this tests"
unless Dancer::ModuleLoader->load('JSON');


# make sure we keep the status when halt is used # make sure we keep the status when halt is used


Expand Down

0 comments on commit 7df377b

Please sign in to comment.