Skip to content

Commit

Permalink
add 'delete_empty_groups' methods
Browse files Browse the repository at this point in the history
Can be useful for sanitization (sp?) of Changelogs. For example,
the work copy of the changelog can contain all the acceptable
groups, and we might want to filter away those that weren't used
for a specific release.
  • Loading branch information
yanick committed Apr 11, 2011
1 parent 597e6f1 commit 869b637
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 0 deletions.
10 changes: 10 additions & 0 deletions lib/CPAN/Changes.pm
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,12 @@ sub release {
return $self->{ releases }->{ $version };
}

sub delete_empty_groups {
my $self = shift;

$_->delete_empty_groups for $self->releases;
}

sub serialize {
my $self = shift;

Expand Down Expand Up @@ -320,6 +326,10 @@ matching release object, undef is returned.
Returns all of the data as a string, suitable for saving as a Changes
file.
=head2 delete_empty_groups( )
Deletes change groups without changes in all releases.
=head1 DEALING WITH "NEXT VERSION" PLACEHOLDERS
In the working copy of a distribution, it's not uncommon
Expand Down
12 changes: 12 additions & 0 deletions lib/CPAN/Changes/Release.pm
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,14 @@ sub delete_group {
delete $self->{ changes }->{ $_ } for @groups;
}

sub delete_empty_groups {
my $self = shift;

$self->delete_group(
grep { ! @{ $self->changes($_) } } $self->groups
);
}

sub serialize {
my $self = shift;

Expand Down Expand Up @@ -197,6 +205,10 @@ Creates an empty group under the names provided.
Deletes the groups of changes specified.
=head2 delete_empty_groups( )
Deletes all groups that don't contain any changes.
=head2 serialize( )
Returns the release data as a string, suitable for inclusion in a Changes
Expand Down
27 changes: 27 additions & 0 deletions t/delete_empty_groups.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
use strict;
use warnings;

use Test::More tests => 2;

use CPAN::Changes;

my $changes = CPAN::Changes->load_string(<<'END_CHANGES');
0.2 2012-02-01
[D]
[E]
- Yadah
0.1 2011-01-01
[A]
- Stuff
[B]
[C]
- Blah
END_CHANGES

$changes->delete_empty_groups;

is_deeply( [ sort( ($changes->releases)[0]->groups ) ], [ qw/ A C / ] );
is_deeply( [ sort( ($changes->releases)[1]->groups ) ], [ 'E' ] );


0 comments on commit 869b637

Please sign in to comment.