X-Git-Url: http://git.vpit.fr/?p=perl%2Fmodules%2FCPANPLUS-Dist-Gentoo.git;a=blobdiff_plain;f=lib%2FCPANPLUS%2FDist%2FGentoo%2FMaps.pm;fp=lib%2FCPANPLUS%2FDist%2FGentoo%2FMaps.pm;h=c564c4ba7fea79c0a8b3f7e1527b74d0714db9ea;hp=957450dd6621206e832dde99186d5705b4223eae;hb=d5ec73d3500d10154218a91cab682ff97287a21d;hpb=363cb060a54409c7ae3032978b3db8eadbead176 diff --git a/lib/CPANPLUS/Dist/Gentoo/Maps.pm b/lib/CPANPLUS/Dist/Gentoo/Maps.pm index 957450d..c564c4b 100644 --- a/lib/CPANPLUS/Dist/Gentoo/Maps.pm +++ b/lib/CPANPLUS/Dist/Gentoo/Maps.pm @@ -3,6 +3,9 @@ package CPANPLUS::Dist::Gentoo::Maps; use strict; use warnings; +use File::Spec; +use POSIX (); + =head1 NAME CPANPLUS::Dist::Gentoo::Maps - Map CPAN distribution names, version numbers and license identifiers to their Gentoo counterparts. @@ -313,6 +316,56 @@ sub perl_version_c2g { return join '.', map int, @parts; } +=head2 C + +Get the numerical timestamp associated with the portage tree located at C<$portage>. +Requires L, and returns C if it is not available. + +=cut + +sub get_portage_timestamp { + my ($portage) = @_; + + { + local $@; + eval { require POSIX::strptime } or return; + } + + my $file = File::Spec->catfile($portage, 'metadata', 'timestamp.chk'); + return unless -e $file; + + my $timestamp = do { + open my $fh, '<', $file or return; + local $/; + <$fh>; + }; + s/^\s*//, s/\s*$// for $timestamp; + + my $shift = 0; + if ($timestamp =~ s/\s+([+-])([0-9]{2})([0-9]{2})$//) { + $shift = ($2 * 60 + $3) * 60; + $shift = -$shift if $1 eq '-'; + } + + my $old_lc_all = POSIX::setlocale(POSIX::LC_ALL()); + POSIX::setlocale(POSIX::LC_ALL(), 'C'); + $timestamp = POSIX::mktime( + POSIX::strptime($timestamp, '%a, %d %b %Y %H:%M:%S') + ); + POSIX::setlocale(POSIX::LC_ALL(), $old_lc_all); + $timestamp += $shift; + + return $timestamp; +} + +=head2 C + +Numerical timestamp associated with the revision of the portage tree that was used for generating the corrections to the natural cpan-to-gentoo mapping listed in this module. + +=cut + +sub TIMESTAMP () { 1339737301 } + =head1 SEE ALSO L.