[Jifty-commit] r6563 - in jifty/trunk: lib/Jifty t/TestApp-Plugin-PasswordAuth/t

Jifty commits jifty-commit at lists.jifty.org
Fri Mar 6 23:06:29 EST 2009


Author: clkao
Date: Fri Mar  6 23:06:28 2009
New Revision: 6563

Modified:
   jifty/trunk/lib/Jifty/I18N.pm
   jifty/trunk/lib/Jifty/Test.pm
   jifty/trunk/t/TestApp-Plugin-PasswordAuth/t/12-i18n.t
   jifty/trunk/t/TestApp/t/i18n-standalone.t

Log:
* do not load po files by default.
* provide l10n => 1 for tests requiring po loading.


Modified: jifty/trunk/lib/Jifty/I18N.pm
==============================================================================
--- jifty/trunk/lib/Jifty/I18N.pm	(original)
+++ jifty/trunk/lib/Jifty/I18N.pm	Fri Mar  6 23:06:28 2009
@@ -94,6 +94,16 @@
     $DynamicLH = \$lh unless @$lang; 
     $self->init;
 
+    __PACKAGE__->install_global_loc($DynamicLH);
+    return $self;
+}
+
+=head2 install_global_loc
+
+=cut
+
+sub install_global_loc {
+    my ($class, $dlh) = @_;
     my $loc_method = sub {
         # Retain compatibility with people using "-e _" etc.
         return \*_ unless @_; # Needed for perl 5.8
@@ -106,7 +116,7 @@
         # Force stringification to stop Locale::Maketext from choking on
         # things like DateTime objects.
         my @stringified_args = map {"$_"} @_;
-        my $result = eval { $lh->maketext(@stringified_args) };
+        my $result = eval { ${$dlh}->maketext(@stringified_args) };
         if ($@) {
             warn $@;
             # Sometimes Locale::Maketext fails to localize a string and throws
@@ -121,7 +131,6 @@
         no warnings 'redefine';
         *_ = $loc_method;
     }
-    return $self;
 }
 
 =head2 available_languages
@@ -201,6 +210,12 @@
 
 my $LAST_MODIFED = '';
 sub refresh {
+    if ( Jifty->config->framework('L10N')->{'Disable'} && !$loaded) {
+        # skip loading po
+        __PACKAGE__->install_global_loc(\__PACKAGE__->get_handle);
+        return;
+    }
+
     my $modified = join(
         ',',
         #   sort map { $_ => -M $_ } map { glob("$_/*.po") } ( Jifty->config->framework('L10N')->{'PoDir'}, Jifty->config->framework('L10N')->{'DefaultPoDir'}

Modified: jifty/trunk/lib/Jifty/Test.pm
==============================================================================
--- jifty/trunk/lib/Jifty/Test.pm	(original)
+++ jifty/trunk/lib/Jifty/Test.pm	Fri Mar  6 23:06:28 2009
@@ -21,6 +21,8 @@
 =head1 SYNOPSIS
 
     use Jifty::Test tests => 5;
+    # to load po for test:
+    # use Jifty::Test tests => 5, l10n => 1;
 
     # ...all of Test::More's functionality...
     my $model = MyApp::Model::MyModel->new;
@@ -33,6 +35,7 @@
     my $server_url = $server->started_ok;
     # You're probably also interested in Jifty::Test::WWW::Mechanize
 
+
 =head1 DESCRIPTION
 
 Jifty::Test is a superset of L<Test::More>.  It provides all of
@@ -184,7 +187,7 @@
     $class->builder->{no_handle} = $args{no_handle};
 
     my $test_config = File::Temp->new( UNLINK => 0 );
-    Jifty::YAML::DumpFile("$test_config", $class->test_config(Jifty::Config->new));
+    Jifty::YAML::DumpFile("$test_config", $class->test_config(Jifty::Config->new, \%args));
     # Invoking bin/jifty and friends will now have the test config ready.
     $ENV{'JIFTY_TEST_CONFIG'} ||= "$test_config";
     $class->builder->{test_config} = $test_config;
@@ -376,13 +379,16 @@
 
 sub test_config {
     my $class = shift;
-    my ($config) = @_;
+    my ($config, $args) = @_;
 
     my $defaults = {
         framework => {
             Database => {
                 Database => $config->framework('Database')->{Database} . $class->_testfile_to_dbname(),
             },
+            L10N => {
+                Disable => $args->{l10n} ? 0 : 1,
+            },
             Web => {
                 Port => ($$ % 5000) + 10000,
                 DataDir => File::Temp::tempdir('masonXXXXXXXXXX', CLEANUP => 1)

Modified: jifty/trunk/t/TestApp-Plugin-PasswordAuth/t/12-i18n.t
==============================================================================
--- jifty/trunk/t/TestApp-Plugin-PasswordAuth/t/12-i18n.t	(original)
+++ jifty/trunk/t/TestApp-Plugin-PasswordAuth/t/12-i18n.t	Fri Mar  6 23:06:28 2009
@@ -8,7 +8,7 @@
 
 =cut
 
-use Jifty::Test::Dist tests => 7;
+use Jifty::Test::Dist tests => 7, l10n => 1;
 use Jifty::Test::WWW::Mechanize;
 
 use Encode 'decode';

Modified: jifty/trunk/t/TestApp/t/i18n-standalone.t
==============================================================================
--- jifty/trunk/t/TestApp/t/i18n-standalone.t	(original)
+++ jifty/trunk/t/TestApp/t/i18n-standalone.t	Fri Mar  6 23:06:28 2009
@@ -2,7 +2,7 @@
 use warnings;
 use strict;
 
-use Jifty::Test::Dist tests => 20;
+use Jifty::Test::Dist tests => 20, l10n => 1;
 use Jifty::Test::WWW::Mechanize;
 use Net::HTTP;
 use URI;


More information about the Jifty-commit mailing list