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