pod_man_reproducible_date.diff 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. From 9057adc106d6bbef53c9e706523cd94f1a7a08d4 Mon Sep 17 00:00:00 2001
  2. From: Russ Allbery <rra@debian.org>
  3. Date: Sat, 30 Aug 2014 15:10:41 -0700
  4. Subject: Support POD_MAN_DATE in Pod::Man for the left-hand footer
  5. Honor the environment variable POD_MAN_DATE and use its contents, if
  6. set, as the value of the left-hand footer if the date option is not
  7. set, overriding the timestamp of the input file. This is primarily
  8. useful to ensure reproducible builds of the same output file given the
  9. same souce and Pod::Man version, even when file timestamps may not be
  10. consistent. Thanks, Niko Tyni.
  11. Bug-Debian: http://bugs.debian.org/759405
  12. Origin: upstream
  13. Patch-Name: fixes/pod_man_reproducible_date.diff
  14. Upstream-Status: Pending
  15. ---
  16. cpan/podlators/lib/Pod/Man.pm | 69 +++++++++++++++++++++++++++++++-----------
  17. cpan/podlators/t/devise-date.t | 29 +++++++++++++-----
  18. 2 files changed, 72 insertions(+), 26 deletions(-)
  19. diff --git a/cpan/podlators/lib/Pod/Man.pm b/cpan/podlators/lib/Pod/Man.pm
  20. index 72ca9ff..0536662 100644
  21. --- a/cpan/podlators/lib/Pod/Man.pm
  22. +++ b/cpan/podlators/lib/Pod/Man.pm
  23. @@ -876,25 +876,42 @@ sub devise_title {
  24. }
  25. # Determine the modification date and return that, properly formatted in ISO
  26. -# format. If we can't get the modification date of the input, instead use the
  27. -# current time. Pod::Simple returns a completely unuseful stringified file
  28. -# handle as the source_filename for input from a file handle, so we have to
  29. -# deal with that as well.
  30. +# format.
  31. +#
  32. +# If POD_MAN_DATE is set, that overrides anything else. This can be used for
  33. +# reproducible generation of the same file even if the input file timestamps
  34. +# are unpredictable or the POD coms from standard input.
  35. +#
  36. +# Otherwise, use the modification date of the input if we can stat it. Be
  37. +# aware that Pod::Simple returns the stringification of the file handle as
  38. +# source_filename for input from a file handle, so we'll stat some random ref
  39. +# string in that case. If that fails, instead use the current time.
  40. +#
  41. +# $self - Pod::Man object, used to get the source file
  42. +#
  43. +# Returns: YYYY-MM-DD date suitable for the left-hand footer
  44. sub devise_date {
  45. my ($self) = @_;
  46. +
  47. + # If POD_MAN_DATE is set, always use it.
  48. + if ($ENV{POD_MAN_DATE}) {
  49. + return $ENV{POD_MAN_DATE};
  50. + }
  51. +
  52. + # Otherwise, get the input filename and try to stat it. If that fails,
  53. + # use the current time.
  54. my $input = $self->source_filename;
  55. my $time;
  56. if ($input) {
  57. - $time = (stat $input)[9] || time;
  58. + $time = (stat($input))[9] || time();
  59. } else {
  60. - $time = time;
  61. + $time = time();
  62. }
  63. - # Can't use POSIX::strftime(), which uses Fcntl, because MakeMaker
  64. - # uses this and it has to work in the core which can't load dynamic
  65. - # libraries.
  66. - my ($year, $month, $day) = (localtime $time)[5,4,3];
  67. - return sprintf ("%04d-%02d-%02d", $year + 1900, $month + 1, $day);
  68. + # Can't use POSIX::strftime(), which uses Fcntl, because MakeMaker uses
  69. + # this and it has to work in the core which can't load dynamic libraries.
  70. + my ($year, $month, $day) = (localtime($time))[5,4,3];
  71. + return sprintf("%04d-%02d-%02d", $year + 1900, $month + 1, $day);
  72. }
  73. # Print out the preamble and the title. The meaning of the arguments to .TH
  74. @@ -1632,6 +1649,15 @@ argument.
  75. Sets the centered page header to use instead of "User Contributed Perl
  76. Documentation".
  77. +=item date
  78. +
  79. +Sets the left-hand footer. If this option is not set, the contents of the
  80. +environment variable POD_MAN_DATE, if set, will be used. Failing that,
  81. +the modification date of the input file will be used, or the current time
  82. +if stat() can't find that file (which will be the case if the input is
  83. +from C<STDIN>). If obtained from the file modification date or the
  84. +current time, he date will be formatted as C<YYYY-MM-DD>.
  85. +
  86. =item errors
  87. How to report errors. C<die> says to throw an exception on any POD
  88. @@ -1642,13 +1668,6 @@ POD errors entirely, as much as possible.
  89. The default is C<pod>.
  90. -=item date
  91. -
  92. -Sets the left-hand footer. By default, the modification date of the input
  93. -file will be used, or the current date if stat() can't find that file (the
  94. -case if the input is from C<STDIN>), and the date will be formatted as
  95. -C<YYYY-MM-DD>.
  96. -
  97. =item fixed
  98. The fixed-width font to use for verbatim text and code. Defaults to
  99. @@ -1810,6 +1829,20 @@ option was set to C<die>.
  100. =back
  101. +=head1 ENVIRONMENT
  102. +
  103. +=over 4
  104. +
  105. +=item POD_MAN_DATE
  106. +
  107. +If set, this will be used as the value of the left-hand footer unless the
  108. +C<date> option is explicitly set, overriding the timestamp of the input
  109. +file or the current time. This is primarily useful to ensure reproducible
  110. +builds of the same output file given the same souce and Pod::Man version,
  111. +even when file timestamps may not be consistent.
  112. +
  113. +=back
  114. +
  115. =head1 BUGS
  116. Encoding handling assumes that PerlIO is available and does not work
  117. diff --git a/cpan/podlators/t/devise-date.t b/cpan/podlators/t/devise-date.t
  118. index 3cce9f5..c610dd9 100644
  119. --- a/cpan/podlators/t/devise-date.t
  120. +++ b/cpan/podlators/t/devise-date.t
  121. @@ -1,15 +1,28 @@
  122. -#!/usr/bin/perl -w
  123. -
  124. -# In order for MakeMaker to build in the core, nothing can use
  125. -# Fcntl which includes POSIX. devise_date()'s use of strftime()
  126. -# was replaced. This tests that it's identical.
  127. +#!/usr/bin/perl
  128. +#
  129. +# In order for MakeMaker to build in the core, nothing can use Fcntl which
  130. +# includes POSIX. devise_date()'s use of strftime() was replaced. This tests
  131. +# that it's identical. It also tests special handling of the POD_MAN_DATE
  132. +# environment variable.
  133. +use 5.006;
  134. use strict;
  135. -
  136. -use Test::More tests => 1;
  137. +use warnings;
  138. use Pod::Man;
  139. use POSIX qw(strftime);
  140. +use Test::More tests => 2;
  141. +
  142. +# Check that the results of device_date matches strftime. There is no input
  143. +# file name, so this will use the current time.
  144. my $parser = Pod::Man->new;
  145. -is $parser->devise_date, strftime("%Y-%m-%d", localtime);
  146. +is(
  147. + $parser->devise_date,
  148. + strftime('%Y-%m-%d', localtime()),
  149. + 'devise_date matches strftime'
  150. +);
  151. +
  152. +# Set the override environment variable and ensure that it's honored.
  153. +local $ENV{POD_MAN_DATE} = '2014-01-01';
  154. +is($parser->devise_date, '2014-01-01', 'devise_date honors POD_MAN_DATE');