From 36f7ee29bfc02c1f2e26b283f409f38fd389bb14 Mon Sep 17 00:00:00 2001 From: Sawyer X Date: Mon, 19 Sep 2016 17:41:30 +0200 Subject: [PATCH 1/6] small cleanups --- lib/Dancer2/Core/App.pm | 2 +- lib/Dancer2/Plugin.pm | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/Dancer2/Core/App.pm b/lib/Dancer2/Core/App.pm index 6c9ea6737..af1147040 100644 --- a/lib/Dancer2/Core/App.pm +++ b/lib/Dancer2/Core/App.pm @@ -8,7 +8,7 @@ use Module::Runtime 'is_module_name'; use Safe::Isa; use Sub::Quote; use File::Spec; -use Module::Runtime 'use_module'; +use Module::Runtime qw< require_module use_module >; use List::Util (); use Ref::Util qw< is_ref is_globref is_scalarref >; diff --git a/lib/Dancer2/Plugin.pm b/lib/Dancer2/Plugin.pm index 38cd3165f..9c28af7c6 100644 --- a/lib/Dancer2/Plugin.pm +++ b/lib/Dancer2/Plugin.pm @@ -501,7 +501,7 @@ sub _find_consumer { # or croak('Could not find Dancer2 app'); return $class; -}; +} # This has to be called for now at the end of every plugin package, in order to # map the keywords of the associated app to the plugin, so that these keywords From c16e75183c3f226158d7ce99992bc0663c1ae5ef Mon Sep 17 00:00:00 2001 From: Sawyer X Date: Mon, 19 Sep 2016 17:43:06 +0200 Subject: [PATCH 2/6] Automatically load and use Unicode::UTF8 --- lib/Dancer2/Core/Request.pm | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/lib/Dancer2/Core/Request.pm b/lib/Dancer2/Core/Request.pm index b545437ab..216f5999a 100644 --- a/lib/Dancer2/Core/Request.pm +++ b/lib/Dancer2/Core/Request.pm @@ -37,6 +37,16 @@ sub $_ { \$_[0]->env->{ 'HTTP_' . ( uc "$_" ) } } 1; _EVAL +eval { + require Unicode::UTF8; + no warnings qw; + *__decode = sub { Unicode::UTF8::decode_utf8($_[0]) }; + 1; +} or do { + no warnings qw; + *__decode = sub { decode( 'UTF-8', $_[0] ) }; +}; + # check presence of XS module to speedup request our $XS_URL_DECODE = eval { require_module('URL::Encode::XS'); 1; }; our $XS_PARSE_QUERY_STRING = eval { require_module('CGI::Deurl::XS'); 1; }; @@ -392,7 +402,7 @@ sub _decode { return if not defined $h; if ( !is_ref($h) && !utf8::is_utf8($h) ) { - return decode( 'UTF-8', $h ); + return __decode($h); } elsif ( ref($h) eq 'Hash::MultiValue' ) { return Hash::MultiValue->from_mixed(_decode($h->as_hashref_mixed)); From 4911ea9a8ce7582fc3349418d5825db9ba20c380 Mon Sep 17 00:00:00 2001 From: Sawyer X Date: Wed, 1 Mar 2017 21:18:57 +0100 Subject: [PATCH 3/6] clarify usage for benchmark --- tools/perf.pl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/perf.pl b/tools/perf.pl index b79a6f349..e8ab1ff01 100644 --- a/tools/perf.pl +++ b/tools/perf.pl @@ -132,7 +132,7 @@ sub check_app { $bench->report; } else { print << "_END_HELP"; -$0 -- <-s | --speed 1|2|3|4|5> +$0 -- <-s | --speed 1|2|3|4|5> <--profile | --bench | --compare> ("--" is required before parameters because D1 parses ARGV) Commands: From 0a663fabd15f4b99b3fe417e0d94bcbfd39bd464 Mon Sep 17 00:00:00 2001 From: Sawyer X Date: Tue, 5 Apr 2022 17:17:36 +0200 Subject: [PATCH 4/6] Remove unnecessary use of Module:Runtime for bareword require --- lib/Dancer2/Core/Request.pm | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/lib/Dancer2/Core/Request.pm b/lib/Dancer2/Core/Request.pm index 216f5999a..8ebe657f7 100644 --- a/lib/Dancer2/Core/Request.pm +++ b/lib/Dancer2/Core/Request.pm @@ -11,7 +11,6 @@ use URI; use URI::Escape; use Safe::Isa; use Hash::MultiValue; -use Module::Runtime 'require_module'; use Ref::Util qw< is_ref is_arrayref is_hashref >; use Dancer2::Core::Types; @@ -48,9 +47,9 @@ eval { }; # check presence of XS module to speedup request -our $XS_URL_DECODE = eval { require_module('URL::Encode::XS'); 1; }; -our $XS_PARSE_QUERY_STRING = eval { require_module('CGI::Deurl::XS'); 1; }; -our $XS_HTTP_COOKIES = eval { require_module('HTTP::XSCookies'); 1; }; +our $XS_URL_DECODE = eval { require URL::Encode::XS; 1; }; +our $XS_PARSE_QUERY_STRING = eval { require CGI::Deurl::XS; 1; }; +our $XS_HTTP_COOKIES = eval { require HTTP::XSCookies; 1; }; our $_id = 0; From 9843a79ffee42a7520513549a2897817640d39e7 Mon Sep 17 00:00:00 2001 From: Sawyer X Date: Wed, 4 May 2022 21:05:31 +0200 Subject: [PATCH 5/6] Add Unicode::UTF8 as a recommended module --- cpanfile | 1 + share/skel/cpanfile | 2 ++ 2 files changed, 3 insertions(+) diff --git a/cpanfile b/cpanfile index 3933401cf..884bd4450 100644 --- a/cpanfile +++ b/cpanfile @@ -69,6 +69,7 @@ recommends 'Scope::Upper'; recommends 'Type::Tiny::XS'; recommends 'URL::Encode::XS'; recommends 'YAML::XS'; +recommends 'Unicode::UTF8'; suggests 'Fcntl'; suggests 'MIME::Types'; diff --git a/share/skel/cpanfile b/share/skel/cpanfile index caeb697a3..f6b3d11c8 100644 --- a/share/skel/cpanfile +++ b/share/skel/cpanfile @@ -12,6 +12,7 @@ recommends "HTTP::XSHeaders" => "0"; recommends "Math::Random::ISAAC::XS" => "0"; recommends "MooX::TypeTiny" => "0"; recommends "Type::Tiny::XS" => "0"; +recommends "Unicode::UTF8" => "0"; feature 'accelerate', 'Accelerate Dancer2 app performance with XS modules' => sub { requires "URL::Encode::XS" => "0"; @@ -25,6 +26,7 @@ feature 'accelerate', 'Accelerate Dancer2 app performance with XS modules' => su requires "Math::Random::ISAAC::XS" => "0"; requires "MooX::TypeTiny" => "0"; requires "Type::Tiny::XS" => "0"; + requires "Unicode::UTF8" => "0"; }; on "test" => sub { From 25c730d9cc899ac2cbbef6b273e88500d162297d Mon Sep 17 00:00:00 2001 From: Sawyer X Date: Wed, 4 May 2022 21:08:45 +0200 Subject: [PATCH 6/6] Reflect changes --- Changes | 1 + 1 file changed, 1 insertion(+) diff --git a/Changes b/Changes index 1ab35fc29..b4e5a7040 100644 --- a/Changes +++ b/Changes @@ -6,6 +6,7 @@ [ ENHANCEMENTS ] * GH #769, PR #829, #1662: Rename show_errors as show_stacktrace (Nuno Ramos Carvalho, Sawyer X) + * GH #1594: Use Unicode::UTF8 if available (Sawyer X) [ DOCUMENTATION ] * GH #1657: Fix the Dancer2::DeprecationPolicy abstract (Jason A. Crome)