File: Entry.pm

package info (click to toggle)
libcpan-changes-perl 0.500005-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,964 kB
  • sloc: perl: 988; makefile: 2
file content (123 lines) | stat: -rw-r--r-- 2,449 bytes parent folder | download
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
package CPAN::Changes::Entry;
use strict;
use warnings;

our $VERSION = '0.500005';
$VERSION =~ tr/_//d;

use Moo;

with 'CPAN::Changes::HasEntries';

has text    => (is => 'ro');
has line    => (is => 'ro');

sub serialize {
  my ($self, %args) = @_;
  my $indents = $args{indents} || [];
  my $styles = $args{styles} || [];
  my $width = $args{width} || 75;

  my $indent = $indents->[0];
  my $style = $styles->[0];
  my $text = $self->text;
  if (length($style) < 2) {
    my $space = ' ' x (2 * length $style);
    $width -= length $space;
    $text =~ s/\G[ \t]*([^\n]{1,$width}|[^ \t\r\n]+)([ \t\r\n]+|$)/$1\n/mg;
    $text =~ s/[ \t]+\n/\n/g;
    $text =~ s/^(.)/$space$1/mg;
    substr $text, 0, length($style), $style;
  }
  # can't wrap this style
  elsif (length($style) % 2 == 0) {
    my $length = length($style) / 2;
    $text = substr($style, 0, $length) . $text . substr($style, $length) . "\n";
  }
  else {
    die "invalid changelog entry style '$style'";
  }
  return $text;
}

1;
__END__

=head1 NAME

CPAN::Changes::Entry - A change entry in a CPAN Changes file

=head1 SYNOPSIS

  my $entry = CPAN::Changes::Entry->new(
    text    => 'A change entry'
    entries => [
      'A sub-entry',
      'Another sub-entry',
    ],
  );

=head1 DESCRIPTION

A changelog is made up of one or more releases. This object provides access to
all of the key data that embodies a release including the version number, date
of release, and all of the changelog information lines.

=head1 ATTRIBUTES

=head2 text

The text of the change entry.

=head2 entries

An array ref of sub-entries under this change entry.

=head2 line

The line number that the change entry starts at.

=head1 METHODS

=head2 serialize

Returns the changes entry in string form.

=head2 clone

Returns a new release object with the same data. Can be given any attributes to
set them differently in the new object.

=head2 has_entries

Returns true if there are sub-entries for this entry.

=head2 find_entry

Accepts a string or a regex, returns a matching sub-entry object.

=head2 add_entry

Adds a changes sub-entry. Accepts a changes sub-entry object or a string.

=head2 remove_entry

Given a string or a changes entry object, removes the entry from the release.

=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