Skip to content

Commit

Permalink
Merge branch 'feature/unicode-utf8'
Browse files Browse the repository at this point in the history
  • Loading branch information
cromedome committed May 5, 2022
2 parents 9374f57 + 25c730d commit b802279
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 8 deletions.
1 change: 1 addition & 0 deletions Changes
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions cpanfile
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
2 changes: 1 addition & 1 deletion lib/Dancer2/Core/App.pm
Original file line number Diff line number Diff line change
Expand Up @@ -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 >;

Expand Down
19 changes: 14 additions & 5 deletions lib/Dancer2/Core/Request.pm
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -37,10 +36,20 @@ sub $_ { \$_[0]->env->{ 'HTTP_' . ( uc "$_" ) } }
1;
_EVAL

eval {
require Unicode::UTF8;
no warnings qw<redefine once>;
*__decode = sub { Unicode::UTF8::decode_utf8($_[0]) };
1;
} or do {
no warnings qw<redefine once>;
*__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; };
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;

Expand Down Expand Up @@ -392,7 +401,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));
Expand Down
2 changes: 1 addition & 1 deletion lib/Dancer2/Plugin.pm
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions share/skel/cpanfile
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion tools/perf.pl
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ sub check_app {
$bench->report;
} else {
print << "_END_HELP";
$0 -- <-s | --speed 1|2|3|4|5> <profile | bench | compare>
$0 -- <-s | --speed 1|2|3|4|5> <--profile | --bench | --compare>
("--" is required before parameters because D1 parses ARGV)
Commands:
Expand Down

0 comments on commit b802279

Please sign in to comment.