Skip Menu |

This queue is for tickets about the CPANPLUS-Dist-RPM CPAN distribution.

Report information
The Basics
Id: 44417
Status: open
Priority: 0/
Queue: CPANPLUS-Dist-RPM

People
Owner: Nobody in particular
Requestors: dolmen [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: Important
Broken in: 0.0.8
Fixed in: (no value)



Subject: [PATCH] Dates in %changelog should be locale independent
Version 0.08 generates the %changelog section of the spec file with locale dependent dates (with strftime() line 288). RPM does not like dates in french such as "jeu mar 19 2009". Compare: LANG=en_US cpan2dist --format=CPANPLUS::Dist::RPM --buildprereq --force Storable with: LANG=fr_FR cpan2dist --format=CPANPLUS::Dist::RPM --buildprereq --force Storable Workaround: force an english locale. *** FIX *** The date is currently formatted using POSIX::strftime (line 288 of RPM.pm): strftime("%a %b %d %Y", localtime) Use this instead: do { my $d = scalar localtime; substr($d, 0, 11) . substr($d, 20) }
On Thu Mar 19 05:04:05 2009, DOLMEN wrote: Show quoted text
> Version 0.08 generates the %changelog section of the spec file with > locale dependent dates (with strftime() line 288). > RPM does not like dates in french such as "jeu mar 19 2009". > > Compare: > LANG=en_US cpan2dist --format=CPANPLUS::Dist::RPM --buildprereq --force > Storable > with: > LANG=fr_FR cpan2dist --format=CPANPLUS::Dist::RPM --buildprereq --force > Storable > > > Workaround: force an english locale. > > *** FIX *** > The date is currently formatted using POSIX::strftime (line 288 of
RPM.pm): Show quoted text
> strftime("%a %b %d %Y", localtime) > Use this instead: > do { my $d = scalar localtime; substr($d, 0, 11) . substr($d, 20) }
Another patch: --- RPM.pm.orig 2010-03-15 22:12:50.000000000 +0100 +++ RPM.pm 2010-03-15 22:41:02.000000000 +0100 @@ -28,7 +28,7 @@ use Path::Class; use Pod::POM; use Pod::POM::View::Text; -use POSIX qw{ strftime }; +use POSIX qw{ strftime setlocale LC_ALL LC_TIME}; use Readonly; use Software::LicenseUtils; use Text::Autoformat; @@ -279,6 +279,11 @@ my $tmpl = Template->new; # Process template into spec + # Use "C" strftime + my $oldlcall = setlocale( LC_ALL ); + my $oldltime = setlocale( LC_TIME ); + setlocale( LC_ALL, "C" ); + setlocale( LC_TIME, "C" ); $tmpl->process( $self->section_data('spec'), { @@ -293,6 +298,8 @@ }, $self->status->specpath, ); + setlocale( LC_ALL, $oldlcall ); + setlocale( LC_TIME, $oldltime ); } sub _package_exists {
Hi, try this: diff -ruN CPANPLUS-Dist-RPM-0.0.8-orig/lib/CPANPLUS/Dist/RPM.pm CPANPLUS-Dist-RPM-0.0.8/lib/CPANPLUS/Dist/RPM.pm --- CPANPLUS-Dist-RPM-0.0.8-orig/lib/CPANPLUS/Dist/RPM.pm 2009-01-17 21:19:29.000000000 +0100 +++ CPANPLUS-Dist-RPM-0.0.8/lib/CPANPLUS/Dist/RPM.pm 2010-08-08 16:53:35.000000000 +0200 @@ -28,12 +28,17 @@ use Path::Class; use Pod::POM; use Pod::POM::View::Text; -use POSIX qw{ strftime }; +use POSIX qw{ strftime locale_h}; use Readonly; use Software::LicenseUtils; use Text::Autoformat; use Template; +# Set locale to en_US.UTF8 so that dates in changelog will be correct +# if using another locale. Also ensures writing out UTF8. (Thanks to +# Roy-Magne Mo for pointing out the problem and providing a solution.) +setlocale(LC_ALL, "en_US.UTF-8"); + our $VERSION = '0.0.8'; # debugging
Thanks Jimmy and Nito for the patches. However I already proposed a less intrusive patch in the description of the bug report. Your patches have problems that mine doesn't: - setting the locale for the whole application may have side effects elsewhere in the application (including not being able to provide localized messages to the user) - using setlocale must be avoided in general to protect against multithread issues - the locale you are hardcoding may not be available on the user system (en_US.utf8): for example AIX has RPM but no UTF8 in locales. So here is my proposed fix which is much simpler and does not depend on the POSIX module. The date is currently formatted using POSIX::strftime (line 288 of RPM.pm): strftime("%a %b %d %Y", localtime) Use this instead: do { my $d = scalar localtime; substr($d, 0, 11) . substr($d, 20) } -- Olivier Mengué - http://o.mengue.free.fr/
Hi, you're right. diff -ruN CPANPLUS-Dist-RPM-0.0.8-orig/lib/CPANPLUS/Dist/RPM.pm CPANPLUS-Dist-RPM-0.0.8/lib/CPANPLUS/Dist/RPM.pm --- CPANPLUS-Dist-RPM-0.0.8-orig/lib/CPANPLUS/Dist/RPM.pm 2009-01-17 21:19:29.000000000 +0100 +++ CPANPLUS-Dist-RPM-0.0.8/lib/CPANPLUS/Dist/RPM.pm 2010-08-17 10:17:30.000000000 +0200 @@ -285,7 +285,7 @@ status => $self->status, module => $self->parent, buildreqs => $self->_buildreqs, - date => strftime("%a %b %d %Y", localtime), + date => do { my $d = scalar localtime; substr($d, 0, 11) . substr($d, 20) }, packager => $PACKAGER, docfiles => join(' ', @{ $self->_docfiles }),