summaryrefslogtreecommitdiff
path: root/dist/Locale-Maketext/t
diff options
context:
space:
mode:
authorTodd Rinaldo <toddr@cpanel.net>2010-07-06 01:28:00 -0400
committerDavid Golden <dagolden@cpan.org>2010-07-06 01:30:30 -0400
commitace47d680c1383b41a705467fadb2c64e7f39c71 (patch)
tree2ab4754109d2da986b31f4a74142a027498088c3 /dist/Locale-Maketext/t
parenta519c2cf8a56d92061e00b715b65a73dd66692c6 (diff)
downloadperl-ace47d680c1383b41a705467fadb2c64e7f39c71.tar.gz
Locale::Maketext external cache support
This patch with tests provides RO support for lexicon hashes in Locale::Maketext. This allows you to have GDBM language files owned by root which can be accessed by non-root, but not altered. If your lexicon is a tied hash the simple act of caching the compiled value can be fatal. For example a GDBM_File GDBM_READER tied hash will die with something like: gdbm store returned -1, errno 2, key "..." at ... All you need to do is turn on caching outside of the lexicon hash itself like so: sub init { my ($lh) = @_; ... $lh->{'use_external_lex_cache'} = 1; ... } And then instead of storing the compiled value in the lexicon hash it will store it in $lh->{'_external_lex_cache'} I've verified that blead is the authoritative location for Locale::Maketext source. Signed-off-by: David Golden <dagolden@cpan.org>
Diffstat (limited to 'dist/Locale-Maketext/t')
-rw-r--r--dist/Locale-Maketext/t/04_use_external_lex_cache.t40
1 files changed, 40 insertions, 0 deletions
diff --git a/dist/Locale-Maketext/t/04_use_external_lex_cache.t b/dist/Locale-Maketext/t/04_use_external_lex_cache.t
new file mode 100644
index 0000000000..f290a5cfb3
--- /dev/null
+++ b/dist/Locale-Maketext/t/04_use_external_lex_cache.t
@@ -0,0 +1,40 @@
+use Test::More tests => 11;
+
+BEGIN {
+ chdir 't';
+ unshift @INC, qw(lib ../lib);
+ use_ok('Locale::Maketext');
+};
+
+package MyTestLocale;
+
+@MyTestLocale::ISA = qw(Locale::Maketext);
+%MyTestLocale::Lexicon = ();
+%MyTestLocale::Lexicon = (); # to avoid warnings
+
+package MyTestLocale::fr;
+
+@MyTestLocale::fr::ISA = qw(MyTestLocale);
+
+%MyTestLocale::fr::Lexicon = (
+ '_AUTO' => 1,
+ 'Hello World' => 'Bonjour Monde',
+);
+
+package main;
+
+my $lh = MyTestLocale->get_handle('fr');
+$lh->{'use_external_lex_cache'} = 1;
+ok(exists $MyTestLocale::fr::Lexicon{'Hello World'} && !ref $MyTestLocale::fr::Lexicon{'Hello World'}, 'lex value not a ref');
+
+is($lh->maketext('Hello World'), 'Bonjour Monde', 'renders correctly first time');
+ok(exists $lh->{'_external_lex_cache'}{'Hello World'} && ref $lh->{'_external_lex_cache'}{'Hello World'}, 'compiled into lex_cache');
+ok(exists $MyTestLocale::fr::Lexicon{'Hello World'} && !ref $MyTestLocale::fr::Lexicon{'Hello World'}, 'lex value still not a ref');
+
+is($lh->maketext('Hello World'), 'Bonjour Monde', 'renders correctly second time time');
+ok(exists $lh->{'_external_lex_cache'}{'Hello World'} && ref $lh->{'_external_lex_cache'}{'Hello World'}, 'still compiled into lex_cache');
+ok(exists $MyTestLocale::fr::Lexicon{'Hello World'} && !ref $MyTestLocale::fr::Lexicon{'Hello World'}, 'lex value still not a ref');
+
+is($lh->maketext('This is not a key'), 'This is not a key', '_AUTO renders correctly first time');
+ok(exists $lh->{'_external_lex_cache'}{'This is not a key'} && ref $lh->{'_external_lex_cache'}{'This is not a key'}, '_AUTO compiled into lex_cache');
+ok(!exists $MyTestLocale::fr::Lexicon{'This is not a key'}, '_AUTO lex value not added to lex');