diff --git a/Build.PL b/Build.PL index 33fe42e..eb27f4e 100755 --- a/Build.PL +++ b/Build.PL @@ -4,7 +4,7 @@ use Module::Build; my $build = Module::Build->new( dist_name => "Locale-Maketext-Gettext", - dist_version => "1.28", + dist_version => "1.29", dist_abstract => "Joins gettext and Maketext frameworks", dist_author => "imacat ", license => "perl", diff --git a/Changes b/Changes index b58f006..216d149 100644 --- a/Changes +++ b/Changes @@ -1,5 +1,14 @@ Locale-Maketext-Gettext change log +2019-09-09 version 1.29 + Fix after 10 years. + 1. Gettext.pm: Added support to purge the lexicon cache and + reread the MO file on calling textdomain() when MO file is + updated automatically. This enables MO file live update with + persistant applications like Mojolicious or mod_perl. + 2. Source is now on Github. See: + https://github.com/imacat/Locale-Maketext-Gettext + 2009-06-27 version 1.28 Build script fix. No code changes. 1. Build.PL: Removed the build_requires, as they are not diff --git a/INSTALL b/INSTALL index c64d3aa..d973a55 100644 --- a/INSTALL +++ b/INSTALL @@ -34,8 +34,8 @@ http://www.activestate.com/ ** Install with ExtUtils::MakeMaker - arclog uses standard Perl installation with ExtUtils::MakeMaker. -Follow these steps: + Locale-Maketext-Gettext uses standard Perl installation with +ExtUtils::MakeMaker. Follow these steps: % perl Makefile.PL % make @@ -141,6 +141,6 @@ commands (by running perldoc cpanp). imacat -2008-11-11 +2008/11/11, updated 2019/9/9 imacat@mail.imacat.idv.tw http://www.imacat.idv.tw/ diff --git a/MANIFEST b/MANIFEST index fec98ae..8683bea 100644 --- a/MANIFEST +++ b/MANIFEST @@ -24,6 +24,7 @@ t/08-f-errors.t t/09-f-encodings.t t/10-f-switching.t t/11-command-line.t +t/12-cache.t t/99-pod.t t/locale/C/LC_MESSAGES/test.mo t/locale/en/LC_MESSAGES/bad.mo @@ -41,3 +42,4 @@ t/locale/zh_TW/LC_MESSAGES/test_utf8.mo t/T_L10N.pm THANKS TODO +META.json diff --git a/META.json b/META.json new file mode 100644 index 0000000..c99bab3 --- /dev/null +++ b/META.json @@ -0,0 +1,46 @@ +{ + "abstract" : "Joins gettext and Maketext frameworks", + "author" : [ + "imacat " + ], + "dynamic_config" : 1, + "generated_by" : "Module::Build version 0.422", + "license" : [ + "perl_5" + ], + "meta-spec" : { + "url" : "http://search.cpan.org/perldoc?CPAN::Meta::Spec", + "version" : "2" + }, + "name" : "Locale-Maketext-Gettext", + "prereqs" : { + "configure" : { + "requires" : { + "Module::Build" : "0.42" + } + }, + "runtime" : { + "requires" : { + "perl" : "v5.8.0" + } + } + }, + "provides" : { + "Locale::Maketext::Gettext" : { + "file" : "lib/Locale/Maketext/Gettext.pm", + "version" : "1.29" + }, + "Locale::Maketext::Gettext::Functions" : { + "file" : "lib/Locale/Maketext/Gettext/Functions.pm", + "version" : "0.13" + } + }, + "release_status" : "stable", + "resources" : { + "license" : [ + "http://dev.perl.org/licenses/" + ] + }, + "version" : "1.29", + "x_serialization_backend" : "JSON::PP version 2.27300_01" +} diff --git a/META.yml b/META.yml index 7bf5be4..3c393cc 100644 --- a/META.yml +++ b/META.yml @@ -1,21 +1,27 @@ ---- #YAML:1.0 -name: Locale-Maketext-Gettext -version: 1.28 -abstract: Joins gettext and Maketext frameworks +--- +abstract: 'Joins gettext and Maketext frameworks' author: - - imacat -license: perl -distribution_type: module + - 'imacat ' +build_requires: {} configure_requires: - ExtUtils::MakeMaker: 0 -build_requires: - ExtUtils::MakeMaker: 0 -requires: {} -no_index: - directory: - - t - - inc -generated_by: ExtUtils::MakeMaker version 6.52 + Module::Build: '0.42' +dynamic_config: 1 +generated_by: 'Module::Build version 0.422, CPAN::Meta::Converter version 2.150005' +license: perl meta-spec: - url: http://module-build.sourceforge.net/META-spec-v1.4.html - version: 1.4 + url: http://module-build.sourceforge.net/META-spec-v1.4.html + version: '1.4' +name: Locale-Maketext-Gettext +provides: + Locale::Maketext::Gettext: + file: lib/Locale/Maketext/Gettext.pm + version: '1.29' + Locale::Maketext::Gettext::Functions: + file: lib/Locale/Maketext/Gettext/Functions.pm + version: '0.13' +requires: + perl: v5.8.0 +resources: + license: http://dev.perl.org/licenses/ +version: '1.29' +x_serialization_backend: 'CPAN::Meta::YAML version 0.018' diff --git a/Makefile.PL b/Makefile.PL index 686e348..e75fbde 100755 --- a/Makefile.PL +++ b/Makefile.PL @@ -12,7 +12,7 @@ $eummver =~ s/_//; WriteMakefile( NAME => "Locale-Maketext-Gettext", - VERSION => "1.28", + VERSION => "1.29", ABSTRACT => "Joins gettext and Maketext frameworks", AUTHOR => "imacat ", %license, diff --git a/README b/README index b4eb9cf..09c7475 100644 --- a/README +++ b/README @@ -38,17 +38,23 @@ like the command-line program gettext. * Installation - Read INSTALL for instructions on how to install +Read INSTALL for instructions on how to install Locale::Maketext::Gettext. +* Source + +Source is now on Github. See +https://github.com/imacat/Locale-Maketext-Gettext + + * News, Changes and Updates - Refer to the Changes for changes, bug fixes, updates, new functions, etc. +Refer to the Changes for changes, bug fixes, updates, new functions, etc. * Copyright -Copyright (c) 2003-2007 imacat. All rights reserved. This program is free +Copyright (c) 2003-2019 imacat. All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. diff --git a/SIGNATURE b/SIGNATURE index 43a6aa5..05fa214 100644 --- a/SIGNATURE +++ b/SIGNATURE @@ -16,20 +16,21 @@ Hash: SHA1 SHA1 be0627fff2e8aef3d2a14d5d7486babc8a4873ba Artistic SHA1 f044bfe71c57b6f25c659bc0a6067aa854bc8343 BUGS -SHA1 7d6278e57e33472b167335a5435081f307f0dc70 Build.PL +SHA1 b90670f4f18c5fc6f31a54cfc70cc1768f78231c Build.PL SHA1 8624bcdae55baeef00cd11d5dfcfa60f68710a02 COPYING -SHA1 5863e86e8a20bbb63b3fd295520b861fa87db0c7 Changes -SHA1 e9345adfeb32db567cd1be52f3f27307943a36bc INSTALL -SHA1 c7d9c9b334b816e6f06473647cd9a054152a44c9 MANIFEST -SHA1 39589ded15e1d09a79c41391392d249de3708f4a META.yml -SHA1 ec92e11b76afaa05f67d83a6e32056505a45c99e Makefile.PL -SHA1 b699f73f5fa33123b2f4f1b210665e295900c74d README +SHA1 52e62d6d9ecb0a0bcf6415b47dac732d08bef2b7 Changes +SHA1 db0a35525a84c33ed78ab4f59df93b20fa31c8cf INSTALL +SHA1 c3d0ffec086f8f4b993ca18d13e245cd8bd0897e MANIFEST +SHA1 e92ba33ca5de51688c225ade02d547c60ccc773c META.json +SHA1 98494a81340535c15b51d135641f5e19995048af META.yml +SHA1 9f6cc97aaa34f3e33968fd6c0a5c470d1b43b8e9 Makefile.PL +SHA1 d9b790a6c16c3ed5be90396ec345fc18b6964e3a README SHA1 3db402b52e04cf5a6e60291c23aac8c16f2db810 THANKS SHA1 85dd5ac895cc0a5b95827060999578d8ce8d41dd TODO -SHA1 ae54c66b3661c21ab99cc96e511bc13bc54bb6bc lib/Locale/Maketext/Gettext.pm +SHA1 45c670256cc3918914ef5007f066a8c91f471190 lib/Locale/Maketext/Gettext.pm SHA1 b88b6bad1e8cb0ba825594c233c006c1b297646f lib/Locale/Maketext/Gettext/Functions.pm SHA1 f89afd70fdcbaeeab44fada7ed3087d5c7f6f018 script/maketext -SHA1 525f414c7a0aadc61240a4b0959ca2cda7514c75 t/00-signature.t +SHA1 983e35d916266240ac038431217066232a9f9144 t/00-signature.t SHA1 7bc2bf2d3ef2befd48a457fb3d90c7c7bdcc4854 t/01-basic.t SHA1 73ce1e3ba168373318655b3f4fbca1847e49fd75 t/02-big-endian.t SHA1 4b07656e4c35bfce793c96b59bb9ae2917be335e t/03-errors.t @@ -41,6 +42,7 @@ SHA1 a4491ef77b899c4988b8ab34fb8f945a8d06c285 t/08-f-errors.t SHA1 8fb7ecbce36daaf81ac9c197dab6834b25233cc5 t/09-f-encodings.t SHA1 2c1641cc6fff792fb83826486050acab23a1db51 t/10-f-switching.t SHA1 4afe4980e7ed4d326009b8257e01320abfb33d14 t/11-command-line.t +SHA1 a79a59f283d0f4cbac868443a34aa132c38a357d t/12-cache.t SHA1 b85626024d610808bd0909989dcfb9fb20a40485 t/99-pod.t SHA1 97dad77dee7f751d09efdb6900b077d68c853d46 t/T_L10N.pm SHA1 676b87d7a8edc735ba676d2901827eb52532b418 t/locale/C/LC_MESSAGES/test.mo @@ -58,7 +60,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----- -iF0EARECAB0WIQSBin4eTeP7OclnnAOL2C5vMLlLXAUCXXY9rAAKCRCL2C5vMLlL -XOFMAJ9+q/8hoCXsWHf67crLWy9mKH439ACeKDvX07Gyac+c+/nzmgErUodrPeo= -=AA1R +iF0EARECAB0WIQSBin4eTeP7OclnnAOL2C5vMLlLXAUCXXZi2AAKCRCL2C5vMLlL +XGjsAJ4uek7Y/xxMkGmuHZ1UXhAWWoxMBACffY/hG/seBDmCFrCsJWeZ4DpFhYI= +=cRCX -----END PGP SIGNATURE----- diff --git a/lib/Locale/Maketext/Gettext.pm b/lib/Locale/Maketext/Gettext.pm index 196e0be..12ba78d 100644 --- a/lib/Locale/Maketext/Gettext.pm +++ b/lib/Locale/Maketext/Gettext.pm @@ -1,6 +1,6 @@ # Locale::Maketext::Gettext - Joins the gettext and Maketext frameworks -# Copyright (c) 2003-2009 imacat. All rights reserved. This program is free +# Copyright (c) 2003-2019 imacat. All rights reserved. This program is free # software; you can redistribute it and/or modify it under the same terms # as Perl itself. # First written: 2003-04-23 @@ -11,7 +11,7 @@ use strict; use warnings; use base qw(Locale::Maketext Exporter); use vars qw($VERSION @ISA %Lexicon @EXPORT @EXPORT_OK); -$VERSION = 1.28; +$VERSION = 1.29; @EXPORT = qw(read_mo); @EXPORT_OK = @EXPORT; # Prototype declaration @@ -192,8 +192,8 @@ sub textdomain : method { # Read the MO file # Cached - if (!exists $CACHE{$mo_file}) { - my $enc; + if (!$self->_is_using_cache($mo_file)) { + my ($enc, @stats, $mtime, $size); # Read it %_ = read_mo($mo_file); @@ -212,9 +212,17 @@ sub textdomain : method { } # Cache them + @stats = stat $mo_file; + if (@stats > 0) { + ($mtime, $size) = @stats[9,7]; + } else { + ($mtime, $size) = (undef, undef); + } $CACHE{$mo_file} = { "Lexicon" => {%_}, "encoding" => $enc, + "mtime" => $mtime, + "size" => $size, }; } @@ -239,6 +247,31 @@ sub textdomain : method { return $DOMAIN; } +# _is_using_cache: Return whether we are using our cache. +sub _is_using_cache : method { + local ($_, %_); + my ($self, $mo_file, @stats, $mtime, $size); + ($self, $mo_file) = @_; + + # NO if we do not have such a cache. + return undef unless exists $CACHE{$mo_file}; + + @stats = stat $mo_file; + # The MO file does not exist previously. + if (!defined $CACHE{$mo_file}->{"mtime"} + || !defined $CACHE{$mo_file}->{"size"}) { + # Use the cache if the MO file still does not exist. + return (@stats == 0); + + # The MO file exists previously. + } else { + # Use the cache if the MO file did not change. + ($mtime, $size) = @stats[9,7]; + return $mtime == $CACHE{$mo_file}->{"mtime"} + && $size == $CACHE{$mo_file}->{"size"}; + } +} + # maketext: Encode after maketext sub maketext : method { local ($_, %_); @@ -809,7 +842,7 @@ imacat =head1 COPYRIGHT -Copyright (c) 2003-2008 imacat. All rights reserved. This program is free +Copyright (c) 2003-2019 imacat. All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. diff --git a/t/12-cache.t b/t/12-cache.t new file mode 100755 index 0000000..71ccc66 --- /dev/null +++ b/t/12-cache.t @@ -0,0 +1,71 @@ +#! /usr/bin/perl -w +# Basic test suite +# Copyright (c) 2019 imacat. All rights reserved. This program is free +# software; you can redistribute it and/or modify it under the same terms +# as Perl itself. + +use 5.008; +use strict; +use warnings; +use Test; + +BEGIN { plan tests => 4 } + +use FindBin; +use File::Spec::Functions qw(catdir catfile); +use lib $FindBin::Bin; +use vars qw($LOCALEDIR $r); +$LOCALEDIR = catdir($FindBin::Bin, "locale"); + +# bindtextdomain +$r = eval { + my ($mo_file0, $mo_file1, $size, $atime, $mtime0, $mtime1); + my ($FH, $content); + + $mo_file0 = catfile($LOCALEDIR, "en", "LC_MESSAGES", "test.mo"); + $mo_file1 = catfile($LOCALEDIR, "en", "LC_MESSAGES", "test-cache.mo"); + ($atime, $mtime0, $size) = (stat $mo_file0)[8,9,7]; + open $FH, $mo_file0 or die "$mo_file0: $!"; + read $FH, $content, $size or die "$mo_file0: $!"; + close $FH or die "$mo_file0: $!"; + open $FH, ">$mo_file1" or die "$mo_file1: $!"; + print $FH $content or die "$mo_file1: $!"; + close $FH or die "$mo_file1: $!"; + utime $atime, $mtime0, $mo_file1 or die "$mo_file1: $!"; + + require T_L10N; + @_ = qw(); + $_ = T_L10N->get_handle("en"); + $_->bindtextdomain("test-cache", $LOCALEDIR); + $_->textdomain("test-cache"); + $_[0] = $_->maketext("Hello, world!"); + + # Update the file but keep the size and mtime + open $FH, "+<$mo_file1" or die "$mo_file1: $!"; + read $FH, $content, $size or die "$mo_file1: $!"; + $content =~ s/Hiya/HiYa/; + seek $FH, 0, 0 or die "$mo_file1: $!"; + print $FH $content or die "$mo_file1: $!"; + close $FH or die "$mo_file1: $!"; + ($mtime1, $size) = (stat $mo_file1)[9,7]; + utime $atime, $mtime0, $mo_file1 or die "$mo_file1: $!"; + $_->textdomain("test-cache"); + $_[1] = $_->maketext("Hello, world!"); + + # Update the mtime + utime $atime, $mtime1, $mo_file1 or die "$mo_file1: $!"; + $_->textdomain("test-cache"); + $_[2] = $_->maketext("Hello, world!"); + + # Remove the file + unlink $mo_file1 or die "$mo_file1: $!"; + return 1; +}; +# 1 +ok($r, 1); +# 2 +ok($_[0], "Hiya :)"); +# 3 - cache not updated +ok($_[1], "Hiya :)"); +# 4 - cache updated +ok($_[2], "HiYa :)");