| 1 | package Pod::Readme::Plugin::changes; | ||||||||||
| 2 | |||||||||||
| 3 | 1 | ▶ | use Moo::Role; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | |||||||||||
| 5 | 1 | our $VERSION = 'v1.2.3'; | |||||||||
| 6 | |||||||||||
| 7 | 1 | ▶ | use CPAN::Changes 0.30; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 8 | 1 | ▶ | use Path::Tiny; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 9 | 1 | ▶ | use Types::Standard qw/ Bool Str /; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 10 | |||||||||||
| 11 | 1 | ▶ | use Pod::Readme::Types qw/ File HeadingLevel /; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 12 | |||||||||||
| 13 | =head1 NAME | ||||||||||
| 14 | |||||||||||
| 15 | Pod::Readme::Plugin::changes - Include latest Changes in README | ||||||||||
| 16 | |||||||||||
| 17 | =head1 SYNOPSIS | ||||||||||
| 18 | |||||||||||
| 19 | =for readme plugin changes | ||||||||||
| 20 | |||||||||||
| 21 | =head1 DESCRIPTION | ||||||||||
| 22 | |||||||||||
| 23 | This is a plugin for L<Pod::Readme> that includes the latest release | ||||||||||
| 24 | of a F<Changes> file that conforms to the L<CPAN::Changes::Spec>. | ||||||||||
| 25 | |||||||||||
| 26 | =head1 ARGUMENTS | ||||||||||
| 27 | |||||||||||
| 28 | Defaults can be overridden with optional arguments. | ||||||||||
| 29 | |||||||||||
| 30 | Note that changing arguments may change later calls to this plugin. | ||||||||||
| 31 | |||||||||||
| 32 | =head2 C<file> | ||||||||||
| 33 | |||||||||||
| 34 | =for readme plugin changes file='Changes' | ||||||||||
| 35 | |||||||||||
| 36 | If the F<Changes> file has a non-standard name or location in the | ||||||||||
| 37 | distribution, you can specify an alternative name. But note that it | ||||||||||
| 38 | I<must> conform the the L<CPAN::Changes::Spec>. | ||||||||||
| 39 | |||||||||||
| 40 | =head2 C<heading-level> | ||||||||||
| 41 | |||||||||||
| 42 | =for readme plugin changes heading-level=1 | ||||||||||
| 43 | |||||||||||
| 44 | This changes the heading level. (The default is 1.) | ||||||||||
| 45 | |||||||||||
| 46 | =head2 C<title> | ||||||||||
| 47 | |||||||||||
| 48 | =for readme plugin changes title='RECENT CHANGES' | ||||||||||
| 49 | |||||||||||
| 50 | This option allows you to change the title of the heading. | ||||||||||
| 51 | |||||||||||
| 52 | =head2 C<verbatim> | ||||||||||
| 53 | |||||||||||
| 54 | =for readme plugin changes verbatim | ||||||||||
| 55 | |||||||||||
| 56 | If you prefer, you can display a verbatim section of the F<Changes> | ||||||||||
| 57 | file. | ||||||||||
| 58 | |||||||||||
| 59 | By default, the F<Changes> file will be parsed and reformatted as POD | ||||||||||
| 60 | (equivalent to the C<no-verbatim> option). | ||||||||||
| 61 | |||||||||||
| 62 | =cut | ||||||||||
| 63 | |||||||||||
| 64 | 1 | requires 'parse_cmd_args'; | |||||||||
| 65 | |||||||||||
| 66 | has 'changes_file' => ( | ||||||||||
| 67 | is => 'rw', | ||||||||||
| 68 | isa => File, | ||||||||||
| 69 | 1 | ▶ | coerce => sub { File->coerce(@_) }, | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 70 | 1 | default => 'Changes', | |||||||||
| 71 | lazy => 1, | ||||||||||
| 72 | ); | ||||||||||
| 73 | |||||||||||
| 74 | 1 | has 'changes_title' => ( | |||||||||
| 75 | is => 'rw', | ||||||||||
| 76 | isa => Str, | ||||||||||
| 77 | default => 'RECENT CHANGES', | ||||||||||
| 78 | lazy => 1, | ||||||||||
| 79 | ); | ||||||||||
| 80 | |||||||||||
| 81 | 1 | has 'changes_verbatim' => ( | |||||||||
| 82 | is => 'rw', | ||||||||||
| 83 | isa => Bool, | ||||||||||
| 84 | default => 0, | ||||||||||
| 85 | lazy => 1, | ||||||||||
| 86 | ); | ||||||||||
| 87 | |||||||||||
| 88 | 1 | has 'changes_heading_level' => ( | |||||||||
| 89 | is => 'rw', | ||||||||||
| 90 | isa => HeadingLevel, | ||||||||||
| 91 | default => 1, | ||||||||||
| 92 | lazy => 1, | ||||||||||
| 93 | ); | ||||||||||
| 94 | |||||||||||
| 95 | 1 | has 'changes_run' => ( | |||||||||
| 96 | is => 'rw', | ||||||||||
| 97 | isa => Bool, | ||||||||||
| 98 | default => 0, | ||||||||||
| 99 | lazy => 1, | ||||||||||
| 100 | ); | ||||||||||
| 101 | |||||||||||
| 102 | 2 | ▶ | around 'depends_on' => sub { | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 103 | 2 | my ($orig, $self) = @_; | |||||||||
| 104 | 2 | return ($self->changes_file, $self->$orig); | |||||||||
| 105 | 1 | }; | |||||||||
| 106 | |||||||||||
| 107 | 1 | ▶ | sub cmd_changes { | ||||||||
|
Subroutine
cmd_changes: called CC=11 SCAR=26.8
Pod
undocumented
| |||||||||||
| 108 | 1 | my ( $self, @args ) = @_; | |||||||||
| 109 | |||||||||||
| 110 | 1 | ▶ | die "The changes plugin can only be used once" if $self->changes_run; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 111 | |||||||||||
| 112 | 1 | my $res = $self->parse_cmd_args( | |||||||||
| 113 | [qw/ file title verbatim no-verbatim heading-level /], @args ); | ||||||||||
| 114 | 1 | foreach my $key ( keys %{$res} ) { | |||||||||
| 115 | 0 | ( my $name = "changes_${key}" ) =~ s/-/_/g; | |||||||||
| 116 | 0 | ▶ | if ( my $method = $self->can($name) ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 117 | 0 | $self->$method( $res->{$key} ); | |||||||||
| 118 | } | ||||||||||
| 119 | else { | ||||||||||
| 120 | 0 | die "Invalid key: '${key}'"; | |||||||||
| 121 | } | ||||||||||
| 122 | } | ||||||||||
| 123 | |||||||||||
| 124 | 1 | my $file = path( $self->base_dir, $self->changes_file ); | |||||||||
| 125 | |||||||||||
| 126 | 1 | my %opts; | |||||||||
| 127 | 1 | ▶ | if ($self->zilla) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 128 | 0 | $opts{next_token} = qr/\{\{\$NEXT}}/; | |||||||||
| 129 | } | ||||||||||
| 130 | |||||||||||
| 131 | 1 | my $changes = CPAN::Changes->load($file, %opts); | |||||||||
| 132 | 1 | my $latest = ( $changes->releases )[-1]; | |||||||||
| 133 | |||||||||||
| 134 | 1 | ▶ | my $heading = $self->can( "write_head" . $self->changes_heading_level ) | ||||||||
|
Branch: 1 branch
| |||||||||||
| 135 | or die "Invalid heading level: " . $self->changes_heading_level; | ||||||||||
| 136 | |||||||||||
| 137 | 1 | $self->$heading( $self->changes_title ); | |||||||||
| 138 | |||||||||||
| 139 | 1 | ▶ | if ( $self->changes_verbatim ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 140 | |||||||||||
| 141 | 0 | $self->write_verbatim( $latest->serialize ); | |||||||||
| 142 | |||||||||||
| 143 | } | ||||||||||
| 144 | else { | ||||||||||
| 145 | |||||||||||
| 146 | 1 | foreach my $group ( $latest->groups ) { | |||||||||
| 147 | |||||||||||
| 148 | 1 | ▶ | $self->write_head2($group) | ||||||||
|
Branch: 1 branch
| |||||||||||
| 149 | if ( $group ne '' ); | ||||||||||
| 150 | |||||||||||
| 151 | 1 | $self->write_over(4); | |||||||||
| 152 | 1 | foreach my $items ( $latest->get_group($group)->changes ) { | |||||||||
| 153 | 1 | foreach my $item ( @{$items} ) { | |||||||||
| 154 | 1 | $self->write_item('* '); | |||||||||
| 155 | 1 | $self->write_para($item); | |||||||||
| 156 | } | ||||||||||
| 157 | } | ||||||||||
| 158 | 1 | $self->write_back(); | |||||||||
| 159 | |||||||||||
| 160 | } | ||||||||||
| 161 | |||||||||||
| 162 | } | ||||||||||
| 163 | |||||||||||
| 164 | 1 | $self->write_para( | |||||||||
| 165 | sprintf( 'See the F<%s> file for a longer revision history.', | ||||||||||
| 166 | $file->basename ) | ||||||||||
| 167 | ); | ||||||||||
| 168 | |||||||||||
| 169 | 1 | $self->changes_run(1); | |||||||||
| 170 | } | ||||||||||
| 171 | |||||||||||
| 172 | 1 | ▶ | use namespace::autoclean; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 173 | |||||||||||
| 174 | 1 | 1; | |||||||||