Replaced %Lexicons and %ENCODINGS with %CACHE, for code simplicity.

This commit is contained in:
依瑪貓 2019-09-09 19:55:59 +08:00
parent 9c1cdeed1e
commit 7254146bea
2 changed files with 16 additions and 14 deletions

View File

@ -26,7 +26,7 @@ SHA1 ec92e11b76afaa05f67d83a6e32056505a45c99e Makefile.PL
SHA1 b699f73f5fa33123b2f4f1b210665e295900c74d README
SHA1 3db402b52e04cf5a6e60291c23aac8c16f2db810 THANKS
SHA1 85dd5ac895cc0a5b95827060999578d8ce8d41dd TODO
SHA1 b10574ec35614c629b52b87c6d92b4683a5c1a6d lib/Locale/Maketext/Gettext.pm
SHA1 ae54c66b3661c21ab99cc96e511bc13bc54bb6bc lib/Locale/Maketext/Gettext.pm
SHA1 b88b6bad1e8cb0ba825594c233c006c1b297646f lib/Locale/Maketext/Gettext/Functions.pm
SHA1 f89afd70fdcbaeeab44fada7ed3087d5c7f6f018 script/maketext
SHA1 525f414c7a0aadc61240a4b0959ca2cda7514c75 t/00-signature.t
@ -58,7 +58,7 @@ SHA1 20f810c6229d0bd4064b27f9b3d86b61a20f0821 t/locale/zh_TW/LC_MESSAGES/test_be
SHA1 eb13887b005e3c3e9fab774dfea22de5c01ad1ef t/locale/zh_TW/LC_MESSAGES/test_utf8.mo
-----BEGIN PGP SIGNATURE-----
iF0EARECAB0WIQSBin4eTeP7OclnnAOL2C5vMLlLXAUCXXY83QAKCRCL2C5vMLlL
XHVLAKCdSD4iKO//dkJljfF6dt3dIFTU5gCeKI8Kry3iISYdbcwVwMP80gff9Wg=
=fz/R
iF0EARECAB0WIQSBin4eTeP7OclnnAOL2C5vMLlLXAUCXXY9rAAKCRCL2C5vMLlL
XOFMAJ9+q/8hoCXsWHf67crLWy9mKH439ACeKDvX07Gyac+c+/nzmgErUodrPeo=
=AA1R
-----END PGP SIGNATURE-----

View File

@ -21,7 +21,8 @@ use Encode qw(encode decode FB_DEFAULT);
use File::Spec::Functions qw(catfile);
no strict qw(refs);
use vars qw(%Lexicons %ENCODINGS $REREAD_MO $MO_FILE);
use vars qw(%CACHE $REREAD_MO $MO_FILE);
%CACHE = qw();
$REREAD_MO = 0;
$MO_FILE = "";
use vars qw(@SYSTEM_LOCALEDIRS);
@ -191,7 +192,7 @@ sub textdomain : method {
# Read the MO file
# Cached
if (!exists $ENCODINGS{$mo_file} || !exists $Lexicons{$mo_file}) {
if (!exists $CACHE{$mo_file}) {
my $enc;
# Read it
%_ = read_mo($mo_file);
@ -211,13 +212,15 @@ sub textdomain : method {
}
# Cache them
$Lexicons{$mo_file} = \%_;
$ENCODINGS{$mo_file} = $enc;
$CACHE{$mo_file} = {
"Lexicon" => {%_},
"encoding" => $enc,
};
}
# Respect the existing output encoding
if (defined $ENCODINGS{$mo_file}) {
$self->{"MO_ENCODING"} = $ENCODINGS{$mo_file};
if (defined $CACHE{$mo_file}->{"encoding"}) {
$self->{"MO_ENCODING"} = $CACHE{$mo_file}->{"encoding"};
} else {
delete $self->{"MO_ENCODING"};
}
@ -229,8 +232,8 @@ sub textdomain : method {
delete $self->{"ENCODING"};
}
}
$self->{"Lexicon"} = $Lexicons{$mo_file};
%{"$class\::Lexicon"} = %{$Lexicons{$mo_file}};
$self->{"Lexicon"} = $CACHE{$mo_file}->{"Lexicon"};
%{"$class\::Lexicon"} = %{$CACHE{$mo_file}->{"Lexicon"}};
$self->clear_isa_scan;
return $DOMAIN;
@ -366,8 +369,7 @@ sub reload_text : method {
local ($_, %_);
# Purge the text cache
%Lexicons = qw();
%ENCODINGS = qw();
%CACHE = qw();
$REREAD_MO = time;
return;