Unicode plugin - rework encoding default config
Wallace Reis [Fri, 24 May 2013 00:37:23 +0000 (02:37 +0200)]
The aim is to find a way to: 1) not bust people who are doing the right
thing, 2) force people to do the right thing going forward, with new
apps, 3) make it easy for people doing the wrong thing to keep doing
the wrong thing if they don't or can't fix their apps.

Thus, lets basically set "encoding" bit to 'UTF-8' for apps loading the
plugin directly (unless provided something else) and remove the default
value.

lib/Catalyst.pm
lib/Catalyst/Plugin/Unicode/Encoding.pm
t/lib/TestApp.pm
t/lib/TestApp2.pm
t/unicode_plugin_charset_utf8.t

index 0dd64a0..a6170d3 100644 (file)
@@ -2983,9 +2983,13 @@ the plugin name does not begin with C<Catalyst::Plugin::>.
         $plugins = [ grep {
             m/Unicode::Encoding/ ? do {
                 $class->log->warn(
-                    'Unicode::Encoding plugin is now part of core,'
+                    'Unicode::Encoding plugin is auto-applied,'
                     . ' please remove this from your appclass'
+                    . ' and make sure to define "encoding" config'
                 );
+                unless (exists $class->config->{'encoding'}) {
+                  $class->config->{'encoding'} = 'UTF-8';
+                }
                 () }
                 : $_
         } @$plugins ];
index ffcdfae..c1c67d9 100644 (file)
@@ -125,7 +125,7 @@ sub setup {
     my $conf = $self->config;
 
     # Allow an explict undef encoding to disable default of utf-8
-    my $enc = exists $conf->{encoding} ? delete $conf->{encoding} : 'UTF-8';
+    my $enc = delete $conf->{encoding};
     $self->encoding( $enc );
 
     return $self->next::method(@_);
index e548872..c1ec9b5 100644 (file)
@@ -50,6 +50,7 @@ TestApp->config(
             action_action_nine => { another_extra_arg => 13 }
         }
     },
+    encoding => 'UTF-8',
 );
 
 # Test bug found when re-adjusting the metaclass compat code in Moose
index 552b8c6..fcf92bd 100644 (file)
@@ -5,8 +5,8 @@ use base qw/Catalyst/;
 use Catalyst qw/Params::Nested/;
 
 __PACKAGE__->config(
-  encoding => $ENV{TESTAPP_ENCODING}
-) if $ENV{TESTAPP_ENCODING};
+  encoding => 'UTF-8'
+);
 
 __PACKAGE__->config('name' => 'TestApp2');
 
index 9700b73..81ba9f7 100644 (file)
@@ -27,6 +27,6 @@ is scalar(@TestLogger::LOGS), 1
     or diag Dumper(\@TestLogger::LOGS);
 like $TestLogger::LOGS[0], qr/content type is 'iso-8859-1'/;
 
-like $TestLogger::ELOGS[0], qr/plugin is now part of core/;
+like $TestLogger::ELOGS[0], qr/Unicode::Encoding plugin/;
 
 done_testing;