Pārlūkot izejas kodu

Dpkg::Changelog: Add a getter for the Time::Piece object

Make it possible to retrieve the already parsed Time::Piece object,
instead of having to reparse it.
Guillem Jover 10 gadi atpakaļ
vecāks
revīzija
4e8550c8e2

+ 1 - 0
debian/changelog

@@ -8,6 +8,7 @@ dpkg (1.18.8) UNRELEASED; urgency=medium
     - Add new format_range() method and deprecate dpkg() and rfc822() methods
       in Dpkg::Changelog.
     - Replace changelog program parsers with perl modules.
+    - Add a getter for the Time::Piece object in Dpkg::Changelog.
   * Test suite:
     - Bump perlcritic ValuesAndExpressions::RequireNumberSeparators minimum
       to 99999.

+ 15 - 1
scripts/Dpkg/Changelog/Entry.pm

@@ -18,7 +18,7 @@ package Dpkg::Changelog::Entry;
 use strict;
 use warnings;
 
-our $VERSION = '1.00';
+our $VERSION = '1.01';
 
 use Carp;
 
@@ -281,6 +281,16 @@ sub get_timestamp {
     return;
 }
 
+=item $time = $entry->get_timepiece()
+
+Return the timestamp of the changelog entry as a Time::Piece object.
+
+=cut
+
+sub get_timepiece {
+    return;
+}
+
 =item $str = $entry->get_dpkg_changes()
 
 Returns a string that is suitable for usage in a C<Changes> field
@@ -299,6 +309,10 @@ sub get_dpkg_changes {
 
 =head1 CHANGES
 
+=head2 Version 1.01 (dpkg 1.18.8)
+
+New method: $entry->get_timepiece().
+
 =head2 Version 1.00 (dpkg 1.15.6)
 
 Mark the module as public.

+ 13 - 2
scripts/Dpkg/Changelog/Entry/Debian.pm

@@ -19,7 +19,7 @@ package Dpkg::Changelog::Entry::Debian;
 use strict;
 use warnings;
 
-our $VERSION = '1.02';
+our $VERSION = '1.03';
 our @EXPORT_OK = qw(
     $regex_header
     $regex_trailer
@@ -220,7 +220,8 @@ sub parse_trailer {
 	# Ignore the week day ('%a, '), as we have validated it above.
 	local $ENV{LC_ALL} = 'C';
 	eval {
-	    Time::Piece->strptime($7, '%d %b %Y %T %z');
+	    my $tp = Time::Piece->strptime($7, '%d %b %Y %T %z');
+	    $self->{trailer_timepiece} = $tp;
 	} or do {
 	    # Validate the month. Date::Parse used to accept both abbreviated
 	    # and full months, but Time::Piece strptime() implementation only
@@ -345,6 +346,12 @@ sub get_timestamp {
     return $self->{trailer_timestamp_date};
 }
 
+sub get_timepiece {
+    my $self = shift;
+
+    return $self->{trailer_timepiece};
+}
+
 =back
 
 =head1 UTILITY FUNCTIONS
@@ -403,6 +410,10 @@ sub find_closes {
 
 =head1 CHANGES
 
+=head2 Version 1.03 (dpkg 1.18.8)
+
+New methods: $entry->get_timepiece().
+
 =head2 Version 1.02 (dpkg 1.18.5)
 
 New methods: $entry->parse_header(), $entry->parse_trailer().