From 73de64874cf787e061f883102f3a5c300f3f903f Mon Sep 17 00:00:00 2001 From: Sawyer X Date: Sat, 1 Oct 2016 16:35:20 -0700 Subject: [PATCH 01/22] Normalize loading of Dancer2::FileUtils --- lib/Dancer2.pm | 1 - lib/Dancer2/Core/DSL.pm | 2 +- lib/Dancer2/Core/Role/HasLocation.pm | 2 +- 3 files changed, 2 insertions(+), 3 deletions(-) diff --git a/lib/Dancer2.pm b/lib/Dancer2.pm index 782c6f120..630ed6eba 100644 --- a/lib/Dancer2.pm +++ b/lib/Dancer2.pm @@ -10,7 +10,6 @@ use Import::Into; use Dancer2::Core; use Dancer2::Core::App; use Dancer2::Core::Runner; -use Dancer2::FileUtils; our $AUTHORITY = 'SUKRIA'; diff --git a/lib/Dancer2/Core/DSL.pm b/lib/Dancer2/Core/DSL.pm index fd29ac746..fc3a7dda9 100644 --- a/lib/Dancer2/Core/DSL.pm +++ b/lib/Dancer2/Core/DSL.pm @@ -7,7 +7,7 @@ use Carp; use Module::Runtime 'require_module'; use Ref::Util qw< is_arrayref >; use Dancer2::Core::Hook; -use Dancer2::FileUtils; +use Dancer2::FileUtils (); use Dancer2::Core::Response::Delayed; with 'Dancer2::Core::Role::DSL'; diff --git a/lib/Dancer2/Core/Role/HasLocation.pm b/lib/Dancer2/Core/Role/HasLocation.pm index e37d2e531..5d8eea419 100644 --- a/lib/Dancer2/Core/Role/HasLocation.pm +++ b/lib/Dancer2/Core/Role/HasLocation.pm @@ -3,7 +3,7 @@ package Dancer2::Core::Role::HasLocation; use Moo::Role; use Dancer2::Core::Types; -use Dancer2::FileUtils; +use Dancer2::FileUtils (); use File::Spec; use Sub::Quote 'quote_sub'; From d3a0d04592ce1db4eaca308dba25091844400524 Mon Sep 17 00:00:00 2001 From: Sawyer X Date: Sun, 19 Feb 2017 18:05:18 +0200 Subject: [PATCH 02/22] Use UTF-8 instead of utf-8 encoding --- lib/Dancer2/FileUtils.pm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Dancer2/FileUtils.pm b/lib/Dancer2/FileUtils.pm index b9ff681c8..fc7a96bd5 100644 --- a/lib/Dancer2/FileUtils.pm +++ b/lib/Dancer2/FileUtils.pm @@ -34,7 +34,7 @@ sub dirname { File::Basename::dirname(@_) } sub set_file_mode { my $fh = shift; - my $charset = 'utf-8'; + my $charset = 'UTF-8'; binmode $fh, ":encoding($charset)"; return $fh; } From e4ac234f400ea36cbacf7697fcc17be1df78fad0 Mon Sep 17 00:00:00 2001 From: Sawyer X Date: Sun, 19 Feb 2017 18:06:37 +0200 Subject: [PATCH 03/22] Suggest using Path::Tiny in documentation --- lib/Dancer2/Cookbook.pod | 12 ++++++------ lib/Dancer2/Manual.pod | 12 ++++++++++++ lib/Dancer2/Tutorial.pod | 15 +++++++-------- 3 files changed, 25 insertions(+), 14 deletions(-) diff --git a/lib/Dancer2/Cookbook.pod b/lib/Dancer2/Cookbook.pod index 0fc3aee0e..809551f2f 100644 --- a/lib/Dancer2/Cookbook.pod +++ b/lib/Dancer2/Cookbook.pod @@ -903,13 +903,13 @@ API and then displays it dynamically in a web page. Other than L for defining routes, we will use L to make the weather API request, L to decode it from JSON format, -and finally L to provide a fully-qualified path to our +and finally L to provide a fully-qualified path to our template engine. use JSON; use Dancer2; use HTTP::Tiny; - use File::Spec; + use Path::Tiny; =head4 Configuration @@ -919,16 +919,16 @@ to I directory in our current directory. Since we want to put our template in our current directory, we will configure that. However, I does not want us to provide a relative path without configuring it to allow it. This is a security issue. So, we're using -L to create a full path to where we are. +L to create a full path to where we are. We also unset the default layout, so Dancer won't try to wrap our template with another one. This is a feature in Dancer to allow you to wrap your templates with a layout when your templating system doesn't support it. Since we're not using a layout here, we don't need it. - set template => 'template_toolkit'; # set template engine - set layout => undef; # disable layout - set views => File::Spec->rel2abs('.'); # full path to views + set template => 'template_toolkit'; # set template engine + set layout => undef; # disable layout + set views => Path::Tiny->cwd->absolute; # full path to views Now, we define our URL: diff --git a/lib/Dancer2/Manual.pod b/lib/Dancer2/Manual.pod index aca2b893b..d10869b9f 100644 --- a/lib/Dancer2/Manual.pod +++ b/lib/Dancer2/Manual.pod @@ -2401,6 +2401,12 @@ Returns the dirname of the path given: my $dir = dirname($some_path); +This can be replaced by using L directly, which is what this DSL +will effectively do: + + use Path::Tiny qw< path >; + my $dir = path($some_path)->parent->stringify; + =head2 encode_json ($structure) Serializes a structure to a UTF-8 binary JSON string. @@ -2761,6 +2767,12 @@ operating system: It also normalizes (cleans) the path aesthetically. It does not verify whether the path exists, though. +This can also be done cleanly using L, which is what this will +effectively do: + + use Path::Tiny qw< path >; + path($0)->sibling( qw< lib File.pm > ); + =head2 post Defines a route for HTTP B requests to the given URL: diff --git a/lib/Dancer2/Tutorial.pod b/lib/Dancer2/Tutorial.pod index 3f6dd121d..07e2af342 100644 --- a/lib/Dancer2/Tutorial.pod +++ b/lib/Dancer2/Tutorial.pod @@ -192,10 +192,10 @@ installed on your machine. =head3 Required Perl modules Obviously you need L installed. You'll also need the -L