[libcpan-changes-perl] 01/01: Imported Upstream version 0.22

Salvatore Bonaccorso carnil at debian.org
Fri Aug 9 17:41:47 UTC 2013


This is an automated email from the git hooks/post-receive script.

carnil pushed a commit to annotated tag upstream/0.22
in repository libcpan-changes-perl.

commit 27819ddde6c38666b99dcdfeaf5b173a7bc4ec80
Author: Salvatore Bonaccorso <carnil at debian.org>
Date:   Fri Aug 9 18:14:12 2013 +0200

    Imported Upstream version 0.22
---
 Changes                          |   39 +++++++++++++++
 MANIFEST                         |    8 ++-
 META.yml                         |    4 +-
 MYMETA.json                      |   53 --------------------
 MYMETA.yml                       |   25 ---------
 Makefile.PL                      |    4 +-
 README                           |    9 ++--
 inc/Module/Install/ExtraTests.pm |    2 +-
 inc/Module/Install/Scripts.pm    |   29 +++++++++++
 lib/CPAN/Changes.pm              |   84 ++++++++++++++++++++-----------
 lib/CPAN/Changes/Release.pm      |   21 ++++++--
 lib/CPAN/Changes/Spec.pod        |   45 +++++++++++++++--
 lib/Test/CPAN/Changes.pm         |   14 ++++--
 script/tidy_changelog            |  103 ++++++++++++++++++++++++++++++++++++++
 t/corpus/long_preamble.changes   |    6 +++
 t/corpus/unknown_date.changes    |    9 ++++
 t/delete_empty_groups.t          |   33 ++++++++++--
 t/read_no_date.t                 |   30 +++++++++++
 t/read_preamble.t                |   67 ++++++++++++++++---------
 t/read_timestamp.t               |   16 ++++--
 t/read_unknown_date.t            |   29 +++++++++++
 t/self.t                         |    2 +-
 t/serialize.t                    |   50 +++++++++++++++++-
 t/sort_groups.t                  |    4 +-
 24 files changed, 523 insertions(+), 163 deletions(-)

diff --git a/Changes b/Changes
index d38b716..f934113 100644
--- a/Changes
+++ b/Changes
@@ -1,5 +1,44 @@
 Revision history for perl module CPAN::Changes
 
+0.22 2013-07-30
+
+  - Sync module versions (RT #87455)
+
+0.21 2013-07-30
+
+  [ Spec Changes ]
+
+  - Bump version to 0.02
+
+  - Added "unknown/dev" release date options (RT #67705)
+
+  - Added optional release note (RT #69321)
+
+  - Added another preamble example
+
+  - Added a note about line length
+
+  [ Code Changes ]
+
+  - Require Test::More 0.96 (RT #84994)
+
+  - Added --check and --help flags to tidy_changelog script (Gabor Szabo)
+
+  - Properly parse multi-line preamble
+
+  - Test::CPAN::Changes now warns about parsed dates not in spec-compliant form
+
+  - Handle unknown/dev release dates and release note from new spec
+
+0.20 2013-05-01
+
+  - 'delete_empty_groups' shouldn't erronously delete default group 
+    (Yanick Champoux)
+
+  - Add tidy_changelog utility script (Yanick Champoux)
+
+  - Minor pod fix
+
 0.19 2012-04-30
 
   - Test::CPAN::Changes now accepts version entries ending in '-TRIAL' (RT
diff --git a/MANIFEST b/MANIFEST
index 77b9663..914b384 100644
--- a/MANIFEST
+++ b/MANIFEST
@@ -6,6 +6,7 @@ inc/Module/Install/ExtraTests.pm
 inc/Module/Install/Fetch.pm
 inc/Module/Install/Makefile.pm
 inc/Module/Install/Metadata.pm
+inc/Module/Install/Scripts.pm
 inc/Module/Install/Win32.pm
 inc/Module/Install/WriteAll.pm
 lib/CPAN/Changes.pm
@@ -15,9 +16,8 @@ lib/Test/CPAN/Changes.pm
 Makefile.PL
 MANIFEST			This list of files
 META.yml
-MYMETA.json
-MYMETA.yml
 README
+script/tidy_changelog
 t/corpus/basic.changes
 t/corpus/different-indentation.changes
 t/corpus/dist-zilla.changes
@@ -25,11 +25,13 @@ t/corpus/dist-zilla_format.changes
 t/corpus/group-brackets.changes
 t/corpus/group.changes
 t/corpus/line-continuation.changes
+t/corpus/long_preamble.changes
 t/corpus/multiple_releases.changes
 t/corpus/no-leading-space-for-change.changes
 t/corpus/preamble.changes
 t/corpus/space-before-date.changes
 t/corpus/timestamp.changes
+t/corpus/unknown_date.changes
 t/delete_empty_groups.t
 t/dist-zilla-changes.t
 t/read_basic.t
@@ -40,9 +42,11 @@ t/read_group.t
 t/read_line-continuation.t
 t/read_multiple_releases.t
 t/read_no-leading-space-for-change.t
+t/read_no_date.t
 t/read_preamble.t
 t/read_space-before-date.t
 t/read_timestamp.t
+t/read_unknown_date.t
 t/self.t
 t/serialize.t
 t/sort_groups.t
diff --git a/META.yml b/META.yml
index fe94a84..a9a3b23 100644
--- a/META.yml
+++ b/META.yml
@@ -4,7 +4,7 @@ author:
   - 'Brian Cassidy <bricas at cpan.org>'
 build_requires:
   ExtUtils::MakeMaker: 6.59
-  Test::More: 0
+  Test::More: 0.96
 configure_requires:
   ExtUtils::MakeMaker: 6.59
 distribution_type: module
@@ -27,4 +27,4 @@ requires:
 resources:
   license: http://dev.perl.org/licenses/
   repository: http://github.com/bricas/cpan-changes
-version: 0.19
+version: 0.22
diff --git a/MYMETA.json b/MYMETA.json
deleted file mode 100644
index 85a8fad..0000000
--- a/MYMETA.json
+++ /dev/null
@@ -1,53 +0,0 @@
-{
-   "abstract" : "Read and write Changes files",
-   "author" : [
-      "Brian Cassidy <bricas at cpan.org>"
-   ],
-   "dynamic_config" : 0,
-   "generated_by" : "Module::Install version 1.06, CPAN::Meta::Converter version 2.120921",
-   "license" : [
-      "perl_5"
-   ],
-   "meta-spec" : {
-      "url" : "http://search.cpan.org/perldoc?CPAN::Meta::Spec",
-      "version" : "2"
-   },
-   "name" : "CPAN-Changes",
-   "no_index" : {
-      "directory" : [
-         "inc",
-         "t",
-         "xt"
-      ]
-   },
-   "prereqs" : {
-      "build" : {
-         "requires" : {
-            "ExtUtils::MakeMaker" : "6.59",
-            "Test::More" : "0"
-         }
-      },
-      "configure" : {
-         "requires" : {
-            "ExtUtils::MakeMaker" : "6.59"
-         }
-      },
-      "runtime" : {
-         "requires" : {
-            "Text::Wrap" : "0",
-            "perl" : "5.010",
-            "version" : "0.79"
-         }
-      }
-   },
-   "release_status" : "stable",
-   "resources" : {
-      "license" : [
-         "http://dev.perl.org/licenses/"
-      ],
-      "repository" : {
-         "url" : "http://github.com/bricas/cpan-changes"
-      }
-   },
-   "version" : "0.19"
-}
diff --git a/MYMETA.yml b/MYMETA.yml
deleted file mode 100644
index c0df0f2..0000000
--- a/MYMETA.yml
+++ /dev/null
@@ -1,25 +0,0 @@
----
-abstract: 'Read and write Changes files'
-author:
-  - 'Brian Cassidy <bricas at cpan.org>'
-build_requires:
-  ExtUtils::MakeMaker: 6.59
-  Test::More: 0
-configure_requires:
-  ExtUtils::MakeMaker: 0
-dynamic_config: 0
-generated_by: 'ExtUtils::MakeMaker version 6.62, CPAN::Meta::Converter version 2.120921'
-license: perl
-meta-spec:
-  url: http://module-build.sourceforge.net/META-spec-v1.4.html
-  version: 1.4
-name: CPAN-Changes
-no_index:
-  directory:
-    - t
-    - inc
-requires:
-  Text::Wrap: 0
-  perl: 5.010
-  version: 0.79
-version: 0.19
diff --git a/Makefile.PL b/Makefile.PL
index 2b166d1..d165f21 100644
--- a/Makefile.PL
+++ b/Makefile.PL
@@ -12,9 +12,11 @@ all_from 'lib/CPAN/Changes.pm';
 requires 'Text::Wrap';
 requires 'version' => '0.79';
 
-test_requires 'Test::More';
+test_requires 'Test::More' => '0.96';
 extra_tests;
 
+install_script 'tidy_changelog';
+
 repository 'http://github.com/bricas/cpan-changes';
 
 WriteAll;
diff --git a/README b/README
index c1505c5..272b68b 100644
--- a/README
+++ b/README
@@ -61,7 +61,7 @@ METHODS
     
         # Release object argument
         my $rel = CPAN::Changes::Release->new(
-            version => '0.01', date => '2009-07-06
+            version => '0.01', date => '2009-07-06'
         );
         $changes->releases( $rel );
 
@@ -77,10 +77,13 @@ METHODS
     Returns the release object for the specified version. Should there be no
     matching release object, undef is returned.
 
-  serialize( group_sort => \&sorting_function )
+  serialize( reverse => $boolean, group_sort => \&sorting_function )
     Returns all of the data as a string, suitable for saving as a Changes
     file.
 
+    If *reverse* is provided and true, the releases are printed in the
+    reverse order (oldest to latest).
+
     If *group_sort* is provided, change groups are sorted according to the
     given function. If not, groups are sorted alphabetically.
 
@@ -130,7 +133,7 @@ AUTHOR
     Brian Cassidy <bricas at cpan.org>
 
 COPYRIGHT AND LICENSE
-    Copyright 2011 by Brian Cassidy
+    Copyright 2011-2013 by Brian Cassidy
 
     This library is free software; you can redistribute it and/or modify it
     under the same terms as Perl itself.
diff --git a/inc/Module/Install/ExtraTests.pm b/inc/Module/Install/ExtraTests.pm
index 2883f5d..ff91f90 100644
--- a/inc/Module/Install/ExtraTests.pm
+++ b/inc/Module/Install/ExtraTests.pm
@@ -6,7 +6,7 @@ package Module::Install::ExtraTests;
 use Module::Install::Base;
 
 BEGIN {
-  our $VERSION = '0.007';
+  our $VERSION = '0.008';
   our $ISCORE  = 1;
   our @ISA     = qw{Module::Install::Base};
 }
diff --git a/inc/Module/Install/Scripts.pm b/inc/Module/Install/Scripts.pm
new file mode 100644
index 0000000..419286f
--- /dev/null
+++ b/inc/Module/Install/Scripts.pm
@@ -0,0 +1,29 @@
+#line 1
+package Module::Install::Scripts;
+
+use strict 'vars';
+use Module::Install::Base ();
+
+use vars qw{$VERSION @ISA $ISCORE};
+BEGIN {
+	$VERSION = '1.06';
+	@ISA     = 'Module::Install::Base';
+	$ISCORE  = 1;
+}
+
+sub install_script {
+	my $self = shift;
+	my $args = $self->makemaker_args;
+	my $exe  = $args->{EXE_FILES} ||= [];
+        foreach ( @_ ) {
+		if ( -f $_ ) {
+			push @$exe, $_;
+		} elsif ( -d 'script' and -f "script/$_" ) {
+			push @$exe, "script/$_";
+		} else {
+			die("Cannot find script '$_'");
+		}
+	}
+}
+
+1;
diff --git a/lib/CPAN/Changes.pm b/lib/CPAN/Changes.pm
index 2ef3464..90924c5 100644
--- a/lib/CPAN/Changes.pm
+++ b/lib/CPAN/Changes.pm
@@ -8,7 +8,7 @@ use Text::Wrap   ();
 use Scalar::Util ();
 use version      ();
 
-our $VERSION = '0.19';
+our $VERSION = '0.22';
 
 # From DateTime::Format::W3CDTF
 our $W3CDTF_REGEX = qr{(\d\d\d\d) # Year
@@ -28,6 +28,11 @@ our $W3CDTF_REGEX = qr{(\d\d\d\d) # Year
 my @m = qw( Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec );
 my %months = map { $m[ $_ ] => $_ + 1 } 0 .. 11;
 
+our $UNKNOWN_VALS = join( '|', (
+    'Unknown Release Date', 'Unknown', 'Not Released', 'Development Release', 
+    'Development', 'Developer Release', 
+) );
+
 sub new {
     my $class = shift;
     return bless {
@@ -63,65 +68,80 @@ sub load_string {
         ? qr/^(?:$version::LAX|$changes->{next_token})/
         : qr/^$version::LAX/;
 
-    $preamble .= shift @lines while @lines && $lines[ 0 ] !~ $version_line_re;
+    $preamble .= shift( @lines ) . "\n" while @lines && $lines[ 0 ] !~ $version_line_re;
 
     for my $l ( @lines ) {
 
         # Version & Date
         if ( $l =~ $version_line_re ) {
-            my ( $v, $d ) = split m{\s+}, $l, 2;
-
-            # munge date formats, ignore junk
-            if ( $d ) {
-
+            my ( $v, $n ) = split m{\s+}, $l, 2;
+            my $match = '';
+            my $d;
+
+            # munge date formats, save the remainder as note
+            if ( $n ) {
+                # unknown dates
+                if ( $n =~ m{^($UNKNOWN_VALS)}i ) {
+                    $d     = $1;
+                    $match = $d;
+                }
                 # handle localtime-like timestamps
-                if ( $d
-                    =~ m{\D{3}\s+(\D{3})\s+(\d{1,2})\s+([\d:]+)?\D*(\d{4})} )
+                elsif ( $n
+                    =~ m{^(\D{3}\s+(\D{3})\s+(\d{1,2})\s+([\d:]+)?\D*(\d{4}))} )
                 {
-                    if ( $3 ) {
+                    $match = $1;
+                    if ( $4 ) {
 
                         # unfortunately ignores TZ data
                         $d = sprintf(
                             '%d-%02d-%02dT%sZ',
-                            $4, $changes->{ months }->{ $1 },
-                            $2, $3
+                            $5, $changes->{ months }->{ $2 },
+                            $3, $4
                         );
                     }
                     else {
                         $d = sprintf( '%d-%02d-%02d',
-                            $4, $changes->{ months }->{ $1 }, $2 );
+                            $5, $changes->{ months }->{ $2 }, $3 );
                     }
                 }
 
                 # RFC 2822
-                elsif ( $d
-                    =~ m{\D{3}, (\d{1,2}) (\D{3}) (\d{4}) (\d\d:\d\d:\d\d) ([+-])(\d{2})(\d{2})}
+                elsif ( $n
+                    =~ m{^(\D{3}, (\d{1,2}) (\D{3}) (\d{4}) (\d\d:\d\d:\d\d) ([+-])(\d{2})(\d{2}))}
                     )
                 {
+                    $match = $1;
                     $d = sprintf(
                         '%d-%02d-%02dT%s%s%02d:%02d',
-                        $3, $changes->{ months }->{ $2 },
-                        $1, $4, $5, $6, $7
+                        $4, $changes->{ months }->{ $3 },
+                        $2, $5, $6, $7, $8
                     );
                 }
 
                 # handle dist-zilla style, again ingoring TZ data
-                elsif ( $d
-                    =~ m{(\d{4}-\d\d-\d\d)\s+(\d\d:\d\d(?::\d\d)?)(\s+\D+)?} )
+                elsif ( $n
+                    =~ m{^((\d{4}-\d\d-\d\d)\s+(\d\d:\d\d(?::\d\d)?)(\s+\D+)?)} )
                 {
-                    $d = sprintf( '%sT%sZ', $1, $2 );
+                    $match = $1;
+                    $d = sprintf( '%sT%sZ', $2, $3 );
                 }
 
                 # start with W3CDTF, ignore rest
-                elsif ( $d =~ m{^($W3CDTF_REGEX)}p ) {
-                    $d = ${^MATCH};
+                elsif ( $n =~ m{^($W3CDTF_REGEX)}p ) {
+                    $d     = ${^MATCH};
+                    $match = $d;
                 }
+
+                # clean date from note
+                $n =~ s{^$match\s*}{};
             }
 
             push @releases,
                 CPAN::Changes::Release->new(
-                version => $v,
-                date    => $d,
+                version      => $v,
+                date         => $d,
+                _parsed_date => $match,
+                note         => $n,
                 );
             $ingroup = undef;
             $indent  = undef;
@@ -262,8 +282,11 @@ sub serialize {
     my $output;
 
     $output = $self->preamble . "\n\n" if $self->preamble;
-    $output .= join "\n", $_->serialize( %release_args )
-        for reverse $self->releases;
+
+    my @r = $self->releases;
+    @r = reverse @r unless $args{reverse};  # not a typo!
+
+    $output .= $_->serialize( %release_args ) for @r;
 
     return $output;
 }
@@ -351,7 +374,7 @@ may be either a regular hashref, or a L<CPAN::Changes::Release> object.
     
     # Release object argument
     my $rel = CPAN::Changes::Release->new(
-        version => '0.01', date => '2009-07-06
+        version => '0.01', date => '2009-07-06'
     );
     $changes->releases( $rel );
 
@@ -369,11 +392,14 @@ Deletes all of the releases specified by the versions supplied to the method.
 Returns the release object for the specified version. Should there be no 
 matching release object, undef is returned.
 
-=head2 serialize( group_sort => \&sorting_function )
+=head2 serialize( reverse => $boolean, group_sort => \&sorting_function )
 
 Returns all of the data as a string, suitable for saving as a Changes 
 file.
 
+If I<reverse> is provided and true, the releases are
+printed in the reverse order (oldest to latest).
+
 If I<group_sort> is provided, change groups are
 sorted according to the given function. If not,
 groups are sorted alphabetically.
@@ -437,7 +463,7 @@ Brian Cassidy E<lt>bricas at cpan.orgE<gt>
 
 =head1 COPYRIGHT AND LICENSE
 
-Copyright 2011 by Brian Cassidy
+Copyright 2011-2013 by Brian Cassidy
 
 This library is free software; you can redistribute it and/or modify
 it under the same terms as Perl itself. 
diff --git a/lib/CPAN/Changes/Release.pm b/lib/CPAN/Changes/Release.pm
index 6869a58..93c183d 100644
--- a/lib/CPAN/Changes/Release.pm
+++ b/lib/CPAN/Changes/Release.pm
@@ -31,6 +31,16 @@ sub date {
     return $self->{ date };
 }
 
+sub note {
+    my $self = shift;
+
+    if ( @_ ) {
+        $self->{ note } = shift;
+    }
+
+    return $self->{ note };
+}
+
 sub changes {
     my $self = shift;
 
@@ -100,14 +110,15 @@ sub delete_group {
 sub delete_empty_groups {
     my $self = shift;
 
-    $self->delete_group( grep { !@{ $self->changes( $_ ) } } $self->groups );
+    $self->delete_group($_) 
+        for grep { !@{ $self->changes( $_ ) } } $self->groups;
 }
 
 sub serialize {
     my $self = shift;
     my %args = @_;
 
-    my $output = join( ' ', grep { defined } ( $self->version, $self->date ) )
+    my $output = join( ' ', grep { defined } ( $self->version, $self->date, $self->note ) )
         . "\n";
 
     $output .= join "\n",
@@ -171,6 +182,10 @@ Gets/sets the version number for this release.
 
 Gets/sets the date for this release.
 
+=head2 note( [ $note ] )
+
+Gets/sets the note for this release.
+
 =head2 changes( [ $group ] )
 
 Gets the list of changes for this release as a hashref of group/changes 
@@ -245,7 +260,7 @@ Brian Cassidy E<lt>bricas at cpan.orgE<gt>
 
 =head1 COPYRIGHT AND LICENSE
 
-Copyright 2011 by Brian Cassidy
+Copyright 2011-2013 by Brian Cassidy
 
 This library is free software; you can redistribute it and/or modify
 it under the same terms as Perl itself. 
diff --git a/lib/CPAN/Changes/Spec.pod b/lib/CPAN/Changes/Spec.pod
index 1488d91..9aa7fbc 100644
--- a/lib/CPAN/Changes/Spec.pod
+++ b/lib/CPAN/Changes/Spec.pod
@@ -7,7 +7,7 @@ CPAN::Changes::Spec - Specification for CPAN Changes files
 
 =head1 VERSION
 
-version 0.01
+version 0.02
 
 =head1 SYNOPSIS
 
@@ -23,7 +23,7 @@ version 0.01
 
 =head1 DESCRIPTION
 
-This document describes version 0.1 of the specification for Changes files
+This document describes version 0.02 of the specification for Changes files
 included in a CPAN distribution.
 
 It is intended as a guide for module authors to encourage them to write 
@@ -39,13 +39,30 @@ Versions should be formatted as described in L<CPAN::Meta::Spec/Version-Formats>
 =head2 Date
 
 A date/time in the format specified by L<http://www.w3.org/TR/NOTE-datetime> 
-aka W3CDTF.
+aka W3CDTF. In order to satisfy release events not made to the public, or dates 
+that are historically unknown, the following strings are also available:
+
+=over 4
+
+=item * Unknown Release Date
+
+=item * Unknown
+
+=item * Not Released
+
+=item * Development Release 
+
+=item * Development
+
+=item * Developer Release
+
+=back
 
 =head1 STRUCTURE
 
 =head2 Required Elements
 
-In its simplest form, the only required elements are a version, a date and
+In its simplest form, the only required elements are a C<Version>, a C<Date> and
 the noted changes. Blank lines between the C<Version> line and the first 
 C<Change> line are optional. Blank lines between C<Change> lines are also
 optional.
@@ -61,6 +78,20 @@ for multi-line changes. Example
     - This is a very very very long
       change line
 
+Although there is no limit on line length, authors generally wrap each line 
+at 78 columns.
+
+=head2 Optional Elements
+
+=head3 Release Note
+
+Any text following the C<Date> portion of the C<Version> line will be 
+considered the C<Release Note>. Example:
+
+    0.01 2013-04-01 Codename: April Fool
+    
+      - First Release
+
 =head2 Preamble
 
 Any amount of text before the first C<Version> line will be considered part 
@@ -69,6 +100,10 @@ lines of:
 
     Revision history for perl module My::Module
 
+Or
+
+    Revision history for perl distribution My-Distribution
+
 =head2 Groups
 
 Changelog entries may be grouped under headings. Heading lines begin with an
@@ -145,7 +180,7 @@ Brian Cassidy E<lt>bricas at cpan.orgE<gt>
 
 =head1 COPYRIGHT AND LICENSE
 
-Copyright 2011 by Brian Cassidy
+Copyright 2011-2013 by Brian Cassidy
 
 This is free software; you can redistribute it and/or modify
 it under the same terms as Perl itself. 
diff --git a/lib/Test/CPAN/Changes.pm b/lib/Test/CPAN/Changes.pm
index 46bc1f4..cf17fcf 100644
--- a/lib/Test/CPAN/Changes.pm
+++ b/lib/Test/CPAN/Changes.pm
@@ -7,7 +7,7 @@ use CPAN::Changes;
 use Test::Builder;
 use version ();
 
-our $VERSION = '0.19';
+our $VERSION = '0.22';
 
 my $Test     = Test::Builder->new;
 
@@ -53,12 +53,18 @@ sub changes_file_ok {
     $Test->ok( 1, "$file contains at least one release" );
 
     for ( @releases ) {
-        if ( $_->date !~ m[^${CPAN::Changes::W3CDTF_REGEX}\s*$] ) {
+        if ( !defined $_->date || $_->date eq ''  ) {
             $Test->ok( 0, "$file contains an invalid release date" );
-            $Test->diag( '  ERR: ' . $_->date );
+            $Test->diag( '  ERR: No date at version ' . $_->version );
             return;
         }
 
+        my $d = $_->{ _parsed_date };
+        if ( $d !~ m[^${CPAN::Changes::W3CDTF_REGEX}$]
+                && $d !~ m[^(${CPAN::Changes::UNKNOWN_VALS})$] ) {
+            $Test->carp( 'Date "' . $d . '" is not in the recommend format' );
+        }
+
         # strip off -TRIAL before testing
         (my $version = $_->version) =~ s/-TRIAL$//;
         if ( not version::is_lax($version) ) {
@@ -146,7 +152,7 @@ Brian Cassidy E<lt>bricas at cpan.orgE<gt>
 
 =head1 COPYRIGHT AND LICENSE
 
-Copyright 2011 by Brian Cassidy
+Copyright 2011-2013 by Brian Cassidy
 
 This library is free software; you can redistribute it and/or modify
 it under the same terms as Perl itself. 
diff --git a/script/tidy_changelog b/script/tidy_changelog
new file mode 100644
index 0000000..c2bcf0e
--- /dev/null
+++ b/script/tidy_changelog
@@ -0,0 +1,103 @@
+#!perl
+
+use CPAN::Changes;
+
+use Getopt::Long qw(GetOptions);
+use Pod::Usage   qw(pod2usage);
+
+GetOptions( \my %opt,
+   'next!',
+   'token:s',
+   'headers!',
+   'reverse',
+   'check',
+   'help',
+) or pod2usage( -verbose => 2 );
+pod2usage( -verbose => 2 ) if $opt{help};
+
+$opt{token} ||= qr/\{\{\$NEXT\}\}/;
+
+my $changelog = shift;
+
+unless ( $changelog ) {
+    # try to guess it
+    opendir my $dir, '.';
+    my @files = grep { -f $_ and /^change/i } readdir $dir;
+    die "changelog not provided and couldn't be guessed\n"
+        unless @files == 1;
+
+    $changelog = shift @files;
+    warn "changelog not provided, guessing '$changelog'\n\n";
+}
+
+if ($opt{check}) {
+    require Test::CPAN::Changes;
+    require Test::More;
+    Test::CPAN::Changes::changes_file_ok();
+    exit;
+}
+
+my $changes = CPAN::Changes->load(
+    $changelog,
+    ( next_token => $opt{token} ) x $opt{next},
+);
+
+if( $opt{headers} ) {
+    $_->clear_changes for $changes->releases;
+}
+
+print $changes->serialize(
+    reverse => $opt{reverse},
+);
+
+__END__
+
+=head1 NAME
+
+tidy_changelog - command-line tool for CPAN::Changes
+
+=head1 SYNOPSIS
+
+    $ tidy_changelog Changelog
+
+=head1 DESCRIPTION
+
+Takes a changelog file, parse it using L<CPAN::Changes> and prints out
+the resulting output.  If a file is not given, the program will see if
+there is one file in the current directory beginning by 'change'
+(case-insensitive) and, if so, assume it to be the changelog.
+
+=head1 ARGUMENTS
+
+=head2 --next
+
+If provided, assumes that there is a placeholder
+header for an upcoming next release. The placeholder token
+is given via I<--token>.
+
+=head2 --token
+
+Regular expression to use to detect the token for an upcoming
+release if I<--next> is used. If not explicitly given, defaults
+to C<\{\{\$NEXT\}\}>.
+
+=head2 --headers
+
+If given, only print out the release header lines, without any of the
+changes.
+
+=head2 --reverse
+
+Prints the releases in reverse order (from the oldest to latest).
+
+
+=head2 --check
+
+Only check if the changelog is formatted properly using the changes_file_ok
+function of L<Test::CPAN::Changes>.
+
+
+=head2 --help
+
+This help
+
diff --git a/t/corpus/long_preamble.changes b/t/corpus/long_preamble.changes
new file mode 100644
index 0000000..e962ab6
--- /dev/null
+++ b/t/corpus/long_preamble.changes
@@ -0,0 +1,6 @@
+Revision history for perl module Foo::Bar
+
+Yep.
+
+0.01 2010-06-16
+ - Initial release
diff --git a/t/corpus/unknown_date.changes b/t/corpus/unknown_date.changes
new file mode 100644
index 0000000..93e2ed6
--- /dev/null
+++ b/t/corpus/unknown_date.changes
@@ -0,0 +1,9 @@
+0.05 Developer Release
+
+0.04 Development Release
+
+0.03 Unknown Release Date
+
+0.02 Not Released
+
+0.01 Unknown
diff --git a/t/delete_empty_groups.t b/t/delete_empty_groups.t
index 1450f35..e0c95a5 100644
--- a/t/delete_empty_groups.t
+++ b/t/delete_empty_groups.t
@@ -5,7 +5,10 @@ use Test::More tests => 2;
 
 use CPAN::Changes;
 
-my $changes = CPAN::Changes->load_string(<<'END_CHANGES');
+subtest basic => sub {
+    plan tests => 2;
+
+    my $changes = CPAN::Changes->load_string(<<'END_CHANGES');
 0.2 2012-02-01
     [D]
     [E]
@@ -19,9 +22,31 @@ my $changes = CPAN::Changes->load_string(<<'END_CHANGES');
     - Blah
 END_CHANGES
 
-$changes->delete_empty_groups;
+    $changes->delete_empty_groups;
+
+    is_deeply( [ sort( ($changes->releases)[0]->groups ) ], [ qw/ A C / ] );
+    is_deeply( [ sort( ($changes->releases)[1]->groups ) ], [ 'E' ] );
+};
+
+subtest mixed => sub {
+    plan tests => 1;
+
+    my $changes = CPAN::Changes->load_string(<<'END_CHANGES');
+Revision history for {{$dist->name}}
+
+0.2.0
+    [BUGS FIXES]
+    - A
+    - B
+
+0.1.0     2012-03-19
+    - C
+END_CHANGES
 
-is_deeply( [ sort( ($changes->releases)[0]->groups ) ], [ qw/ A C / ] );
-is_deeply( [ sort( ($changes->releases)[1]->groups ) ], [ 'E' ] );
+    $changes->delete_empty_groups;
 
+    is_deeply( [ sort( ($changes->releases)[0]->changes ) ], [ { 
+        '' => [ 'C' ],
+    } ] );
 
+};
diff --git a/t/read_no_date.t b/t/read_no_date.t
new file mode 100644
index 0000000..b0d80b9
--- /dev/null
+++ b/t/read_no_date.t
@@ -0,0 +1,30 @@
+use strict;
+use warnings;
+
+use Test::More tests => 8;
+
+use CPAN::Changes;
+
+my $changes = CPAN::Changes->load_string(<<'END_CHANGES');
+1.01 Note
+    - Second
+
+1.00
+    - First
+END_CHANGES
+
+isa_ok( $changes, 'CPAN::Changes' );
+
+my @releases = $changes->releases;
+is( scalar @releases, 2, 'has 2 releases' );
+
+my @expected = (
+    { date => undef, note => undef },
+    { date => undef, note => 'Note' },
+);
+
+for ( 0.. at expected - 1 ) {
+    isa_ok( $releases[ $_ ], 'CPAN::Changes::Release' );
+    is( $releases[ $_ ]->date, $expected[ $_ ]->{ date }, 'date' );
+    is( $releases[ $_ ]->note, $expected[ $_ ]->{ note }, 'note' );
+}
diff --git a/t/read_preamble.t b/t/read_preamble.t
index 7d4e25a..f630057 100644
--- a/t/read_preamble.t
+++ b/t/read_preamble.t
@@ -1,30 +1,49 @@
 use strict;
 use warnings;
 
-use Test::More tests => 10;
+use Test::More tests => 19;
 
 use_ok( 'CPAN::Changes' );
 
-my $changes = CPAN::Changes->load( 't/corpus/preamble.changes' );
-
-isa_ok( $changes, 'CPAN::Changes' );
-is( $changes->preamble, 'Revision history for perl module Foo::Bar',
-    'preamble' );
-
-my @releases = $changes->releases;
-
-is( scalar @releases, 1, 'has 1 release' );
-isa_ok( $releases[ 0 ], 'CPAN::Changes::Release' );
-is( $releases[ 0 ]->version, '0.01',       'version' );
-is( $releases[ 0 ]->date,    '2010-06-16', 'date' );
-is_deeply(
-    $releases[ 0 ]->changes,
-    { '' => [ 'Initial release' ] },
-    'full changes'
-);
-is_deeply( [ $releases[ 0 ]->groups ], [ '' ], 'only the main group' );
-is_deeply(
-    $releases[ 0 ]->changes( '' ),
-    [ 'Initial release' ],
-    'one change line'
-);
+{
+    my $changes = CPAN::Changes->load( 't/corpus/preamble.changes' );
+
+    isa_ok( $changes, 'CPAN::Changes' );
+    is( $changes->preamble, 'Revision history for perl module Foo::Bar',
+        'preamble' );
+
+    check_releases( $changes );
+}
+
+{
+    my $changes = CPAN::Changes->load( 't/corpus/long_preamble.changes' );
+
+    isa_ok( $changes, 'CPAN::Changes' );
+    is( $changes->preamble, 'Revision history for perl module Foo::Bar
+
+Yep.',
+        'preamble' );
+
+    check_releases( $changes );
+}
+
+sub check_releases {
+    my $changes  = shift;
+    my @releases = $changes->releases;
+
+    is( scalar @releases, 1, 'has 1 release' );
+    isa_ok( $releases[ 0 ], 'CPAN::Changes::Release' );
+    is( $releases[ 0 ]->version, '0.01',       'version' );
+    is( $releases[ 0 ]->date,    '2010-06-16', 'date' );
+    is_deeply(
+        $releases[ 0 ]->changes,
+        { '' => [ 'Initial release' ] },
+        'full changes'
+    );
+    is_deeply( [ $releases[ 0 ]->groups ], [ '' ], 'only the main group' );
+    is_deeply(
+        $releases[ 0 ]->changes( '' ),
+        [ 'Initial release' ],
+        'one change line'
+    );
+}
diff --git a/t/read_timestamp.t b/t/read_timestamp.t
index 3af29e0..fab3608 100644
--- a/t/read_timestamp.t
+++ b/t/read_timestamp.t
@@ -1,7 +1,7 @@
 use strict;
 use warnings;
 
-use Test::More tests => 17;
+use Test::More tests => 18;
 
 use_ok( 'CPAN::Changes' );
 
@@ -12,8 +12,18 @@ isa_ok( $changes, 'CPAN::Changes' );
 my @releases = $changes->releases;
 is( scalar @releases, 7, 'has 7 releases' );
 
-my @expected = qw( 2011-03-25T12:16:25Z 2011-03-25T12:18:36Z 2011-03-25 2011-04-11T12:11:10Z 2011-04-11T15:14Z 2011-04-11T21:40:45-03:00 2011-04-12T12:00:00Z );
+my @expected = (
+    qw( 2011-03-25T12:16:25Z 2011-03-25T12:18:36Z 2011-03-25 2011-04-11T12:11:10Z 2011-04-11T15:14Z 2011-04-11T21:40:45-03:00 ),
+    { d => '2011-04-12T12:00:00Z', n => '# JUNK!' },
+);
 for ( 0.. at expected - 1 ) {
     isa_ok( $releases[ $_ ], 'CPAN::Changes::Release' );
-    is( $releases[ $_ ]->date,  $expected[ $_ ], 'date' );
+
+    if( ref $expected[ $_ ] ) {
+        is( $releases[ $_ ]->date,  $expected[ $_ ]->{ d }, 'date' );
+        is( $releases[ $_ ]->note,  $expected[ $_ ]->{ n }, 'note' );
+    }
+    else {
+        is( $releases[ $_ ]->date,  $expected[ $_ ], 'date' );
+    }
 }
diff --git a/t/read_unknown_date.t b/t/read_unknown_date.t
new file mode 100644
index 0000000..6d90d0f
--- /dev/null
+++ b/t/read_unknown_date.t
@@ -0,0 +1,29 @@
+use strict;
+use warnings;
+
+use Test::More tests => 19;
+
+use_ok( 'CPAN::Changes' );
+
+my $changes = CPAN::Changes->load( 't/corpus/unknown_date.changes' );
+
+isa_ok( $changes, 'CPAN::Changes' );
+is( $changes->preamble, '', 'no preamble' );
+
+my @releases = $changes->releases;
+
+is( scalar @releases, 5, 'has 5 releases' );
+
+my @expected = (
+    { version => '0.01', date => 'Unknown' },
+    { version => '0.02', date => 'Not Released' },
+    { version => '0.03', date => 'Unknown Release Date' },
+    { version => '0.04', date => 'Development Release' },
+    { version => '0.05', date => 'Developer Release' },
+);
+
+for ( 0.. at expected - 1 ) {
+    isa_ok( $releases[ $_ ], 'CPAN::Changes::Release' );
+    is( $releases[ $_ ]->version, $expected[ $_ ]->{ version }, 'version' );
+    is( $releases[ $_ ]->date, $expected[ $_ ]->{ date }, 'date' );
+}
diff --git a/t/self.t b/t/self.t
index 3c9e662..d7f37aa 100644
--- a/t/self.t
+++ b/t/self.t
@@ -1,7 +1,7 @@
 use strict;
 use warnings;
 
-use Test::More tests => 22;
+use Test::More tests => 25;
 
 use_ok( 'CPAN::Changes' );
 
diff --git a/t/serialize.t b/t/serialize.t
index 3b8df81..fb97526 100644
--- a/t/serialize.t
+++ b/t/serialize.t
@@ -1,7 +1,7 @@
 use strict;
 use warnings;
 
-use Test::More tests => 6;
+use Test::More tests => 8;
 
 use_ok( 'CPAN::Changes' );
 
@@ -101,3 +101,51 @@ EOCHANGES
 
     is( $changes->serialize, $expected, 'serialize with line-wrap' );
 }
+
+{
+    $changes->releases(
+        {   version => '0.01',
+            date    => '2010-06-16',
+            note    => 'Note',
+            changes => {
+                '' => [
+                    'Test'
+                ]
+            },
+        }
+    );
+
+    my $expected = <<EOCHANGES;
+Revision history for perl module Foo::Bar
+
+0.01 2010-06-16 Note
+ - Test
+
+EOCHANGES
+
+    is( $changes->serialize, $expected, 'serialize with note' );
+}
+
+{
+    $changes->releases(
+        {   version => '0.01',
+            date    => 'Unknown',
+            note    => '(Oops)',
+            changes => {
+                '' => [
+                    'Test'
+                ]
+            },
+        }
+    );
+
+    my $expected = <<EOCHANGES;
+Revision history for perl module Foo::Bar
+
+0.01 Unknown (Oops)
+ - Test
+
+EOCHANGES
+
+    is( $changes->serialize, $expected, 'serialize with unknown date and note' );
+}
diff --git a/t/sort_groups.t b/t/sort_groups.t
index b06e72d..e68ca01 100644
--- a/t/sort_groups.t
+++ b/t/sort_groups.t
@@ -6,12 +6,12 @@ use Test::More tests => 6;
 use CPAN::Changes;
 
 my $changes = CPAN::Changes->load_string(<<'END_CHANGES');
-2011-04-17 1.05
+1.05 2011-04-17
     [A]
     - stuff
     [B]
     - mo' stuff
-2011-04-16 1.04
+1.04 2011-04-16
     [C]
     - stuff
     [D]

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-perl/packages/libcpan-changes-perl.git



More information about the Pkg-perl-cvs-commits mailing list