File Coverage

blib/lib/Dist/Zilla/Plugin/PreviousVersion/Changelog.pm
Criterion Covered Total %
statement 20 20 100.0
branch n/a
condition n/a
subroutine 8 8 100.0
pod 0 1 0.0
total 28 29 96.5


line stmt bran cond sub pod time code
1             package Dist::Zilla::Plugin::PreviousVersion::Changelog;
2             BEGIN {
3 1     1   997647 $Dist::Zilla::Plugin::PreviousVersion::Changelog::AUTHORITY = 'cpan:YANICK';
4             }
5             # ABSTRACT: extract previous version from changelog
6             $Dist::Zilla::Plugin::PreviousVersion::Changelog::VERSION = '0.2.4';
7              
8 1     1   11 use strict;
  1         3  
  1         48  
9 1     1   7 use warnings;
  1         2  
  1         42  
10              
11 1     1   723 use CPAN::Changes;
  1         10759  
  1         63  
12 1     1   15 use List::Util qw/ first /;
  1         2  
  1         127  
13              
14 1     1   8 use Moose;
  1         2  
  1         11  
15              
16             with qw/
17             Dist::Zilla::Role::Plugin
18             Dist::Zilla::Role::YANICK::PreviousVersionProvider
19             /;
20              
21             has filename => ( is => 'ro', isa=>'Str', default => 'Changes' );
22              
23             has changelog => (
24             is => 'ro',
25             isa => 'CPAN::Changes',
26             lazy => 1,
27             default => sub {
28             my $self = shift;
29             my $changes_file = first { $_->name eq $self->filename }
30             @{ $self->zilla->files }
31             or $self->log_fatal(
32             "changelog '@{[ $self->filename ]}' not found" );
33              
34             CPAN::Changes->load_string(
35             $changes_file->content,
36             next_token => qr/{{\$NEXT}}/
37             );
38             },
39             );
40              
41             sub provide_previous_version {
42 6     6 0 15 my $self = shift;
43              
44             # TODO {{$NEXT}} not generic enough
45 12     12   60 return first { $_ ne '{{$NEXT}}' }
46 6         302 map { $_->version }
  12         235  
47             reverse $self->changelog->releases;
48             }
49              
50             __PACKAGE__->meta->make_immutable;
51              
52             1;
53              
54             __END__
55              
56             =pod
57              
58             =encoding UTF-8
59              
60             =head1 NAME
61              
62             Dist::Zilla::Plugin::PreviousVersion::Changelog - extract previous version from changelog
63              
64             =head1 VERSION
65              
66             version 0.2.4
67              
68             =head1 DESCRIPTION
69              
70             Plugin implementing the L<Dist::Zilla::Role::PreviousVersionProvider> role.
71             It provides the previous released version by peeking at the C<Changelog> file
72             and returning its latest release, skipping over C<{{$NEXT}}> if its there
73             (see L<Dist::Zilla::Plugin::NextRelease>).
74              
75             Note that this module uses L<CPAN::Changes> to parse the change log. If the
76             file is not well-formed according to its specs, strange things might happen.
77              
78             =head1 CONFIGURATION
79              
80             =head2 filename
81              
82             Changelog filename. Defaults to 'Changes'.
83              
84             =head1 AUTHOR
85              
86             Yanick Champoux <yanick@cpan.org>
87              
88             =head1 COPYRIGHT AND LICENSE
89              
90             This software is copyright (c) 2012 by Yanick Champoux.
91              
92             This is free software; you can redistribute it and/or modify it under
93             the same terms as the Perl 5 programming language system itself.
94              
95             =cut