Hi,
With DateTime::Locale 0.21, when you register a custom locale with
another name the Locale is incompletely registered, indeed, you miss
some data (those passed to register())
Below is a patch proposal using _load_class_from_id() for custom Classes
too.
Yann
diff -r -u DateTime-Locale-0.21/lib/DateTime/Locale.pm
DateTime-Locale-0.21-patched/lib/DateTime/Local
e.pm
--- DateTime-Locale-0.21/lib/DateTime/Locale.pm Mon Feb 28 21:36:19 2005
+++ DateTime-Locale-0.21-patched/lib/DateTime/Locale.pm Thu May 26
20:19:57 2005
@@ -204,7 +204,7 @@
# Custom class registered by user
if ( $Class{$name} )
{
- return $LoadCache{$key} = $Class{$name}->new;
+ return $LoadCache{$key} = $class->_load_class_from_id( $name,
$Class{$name} )
}
# special case for backwards compatibility with DT::Language
@@ -290,6 +290,7 @@
{
my $class = shift;
my $id = shift;
+ my $real_class = shift;
# We want the first alias for which there is data, even if it has
# no corresponding .pm file. There may be multiple levels of
@@ -303,7 +304,7 @@
my $data = $DataForID{$data_id};
my $subclass = $data->{real_class} ? $data->{real_class} : $data_id;
- my $real_class = "DateTime::Locale::$subclass";
+ $real_class ||= "DateTime::Locale::$subclass";
unless ( $real_class->can('new') )
{
diff -r -u DateTime-Locale-0.21/t/05register.t
DateTime-Locale-0.21-patched/t/05register.t
--- DateTime-Locale-0.21/t/05register.t Mon Feb 28 21:36:19 2005
+++ DateTime-Locale-0.21-patched/t/05register.t Fri May 27 09:55:37 2005
@@ -1,7 +1,7 @@
#!/usr/bin/perl -w
use strict;
-use Test::More tests => 8;
+use Test::More tests => 14;
use DateTime::Locale;
@@ -29,6 +29,17 @@
use base qw(DateTime::Locale::root);
}
+{
+ package DateTime::Locale::fr_FR_BZH2;
+ @DateTime::Locale::fr_FR_BZH2::ISA = qw(DateTime::Locale::root);
+ sub short_date_format { 'test test2' }
+}
+{
+ package Other::Locale::fr_FR_BZH;
+ @Other::Locale::fr_FR_BZH::ISA = qw(DateTime::Locale::root);
+ sub short_date_format { 'test test2' }
+}
+
DateTime::Locale->register
( id => 'en_GB_RIDAS',
en_language => 'English',
@@ -78,4 +89,36 @@
my $l = DateTime::Locale->load('en_QUUX_QUAX');
ok( $l, 'was able to load en_QUUX_QUAX' );
is( $l->variant, 'Wacko', 'variant is set properly' );
+}
+
+## Bug register if 'class' used
+# with an explicit DateTime:: namespace
+{
+ DateTime::Locale->register
+ ( id => 'fr_FR_BZH2',
+ en_language => 'French2',
+ en_territory => 'French2',
+ en_variant => 'Britanny2',
+ class => 'DateTime::Locale::fr_FR_BZH2',
+ );
+
+ my $l = DateTime::Locale->load('fr_FR_BZH2');
+ ok( $l, 'was able to load fr_FR_BZH2' );
+ cmp_ok( $l->short_date_format, 'eq', 'test test2', "short date" );
+ cmp_ok( $l->name, 'eq', 'French2 French2 Britanny2', 'name is also
set' );
+}
+# with a custom namespace
+{
+ DateTime::Locale->register
+ ( id => 'fr_FR_BZH',
+ en_language => 'French',
+ en_territory => 'French',
+ en_variant => 'Britanny',
+ class => 'Other::Locale::fr_FR_BZH',
+ );
+
+ my $l = DateTime::Locale->load('fr_FR_BZH');
+ ok( $l, 'was able to load fr_FR_BZH' );
+ cmp_ok( $l->short_date_format, 'eq', 'test test2', "short date" );
+ cmp_ok( $l->name, 'eq', 'French French Britanny', 'name is also set' );
}