1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147
|
package CPAN::Changes::Group;
use strict;
use warnings;
our $VERSION = '0.500005';
$VERSION =~ tr/_//d;
use Sub::Quote qw(qsub);
use CPAN::Changes::Entry;
use Moo;
has _entry => (
is => 'rw',
handles => {
is_empty => 'has_entries',
add_changes => 'add_entry',
},
lazy => 1,
default => qsub q{ CPAN::Changes::Entry->new(text => '') },
predicate => 1,
);
sub name {
my $self = shift;
my $entry = $self->_entry;
return $entry->can('text') ? $entry->text : '';
}
sub _maybe_entry {
my $self = shift;
if ($self->can('changes') == \&changes) {
return $self->_entry;
}
else {
return CPAN::Changes::Entry->new(
text => $self->name,
entries => $self->changes,
);
}
}
around BUILDARGS => sub {
my ($orig, $self, @args) = @_;
my $args = $self->$orig(@args);
if (!$args->{_entry}) {
$args->{_entry} = CPAN::Changes::Entry->new({
text => $args->{name} || '',
entries => $args->{changes} || [],
});
}
$args;
};
sub changes {
my ($self) = @_;
return []
unless $self->_has_entry;
[ map { $_->text } @{ $self->_entry->entries } ];
}
sub set_changes {
my ($self, @changes) = @_;
$self->clear_changes;
my $entry = $self->_entry;
for my $change (@changes) {
$entry->add_entry($change);
}
return;
}
sub clear_changes {
my ($self) = @_;
my $entry = $self->_entry;
@{$entry->entries} = ();
$self->changes;
}
sub serialize {
my ($self, %args) = @_;
$args{indents} ||= [' ', ' '];
$args{styles} ||= ['[]', '-'];
$self->_maybe_entry->serialize(%args);
}
1;
__END__
=head1 NAME
CPAN::Changes::Group - An entry group in a CPAN Changes file
=head1 SYNOPSIS
my $group = CPAN::Changes::Group->new(
name => 'A change group',
changes => [
'A change entry',
'Another change entry',
],
);
=head1 DESCRIPTION
Represents a group of change entries on a changelog release. This is a legacy
interface for the and its use is discouraged.
Behind the scenes, this works as a proxy for the real L<CPAN::Changes::Entry>
objects.
=head1 ATTRIBUTES
=head2 name
The name of the change group.
=head1 METHODS
=head2 is_empty
=head2 add_changes
=head2 changes
=head2 set_changes
=head2 clear_changes
=head2 serialize
=head1 SEE ALSO
=over 4
=item * L<CPAN::Changes>
=back
=head1 AUTHORS
See L<CPAN::Changes> for authors.
=head1 COPYRIGHT AND LICENSE
See L<CPAN::Changes> for the copyright and license.
=cut
|