/
pm_changelog
executable file
·73 lines (53 loc) · 1.51 KB
/
pm_changelog
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
#!/usr/bin/env perl
use 5.10.0;
use strict;
use warnings;
use version;
use MetaCPAN::API;
use CPAN::Changes;
use Getopt::Long;
my %opt;
GetOptions( \%opt, 'all!' );
my $mcpan = MetaCPAN::API->new;
my $module = shift;
(my $distro = $module) =~ s/::/-/g;
my $dist = eval { $mcpan->release( distribution => $distro ); }
or die "couldn't find release '$distro'";
my $source;
for ( qw/ Changes CHANGES Changelog / ) {
$source = eval {
$mcpan->source(
author => $dist->{author},
release => $dist->{name},
path => $_,
)
} and last;
}
$source or die "no changelog found\n";
my $changes = CPAN::Changes->load_string( $source );
if ( my @releases = $changes->releases ) {
# only print the newer stuff
# will get us 0 if the module is not locally installed
my $installed_version = version->parse(
eval "use $module; $module->VERSION"
);
if ( $installed_version >= version->parse(0) ) {
say "installed version: ", $installed_version;
}
say "latest version: ", $releases[-1]->{version};
if ( !($opt{all}) and $installed_version == version->parse( $releases[-1]->{version} ) ) {
say "we are on the bleeding edge!";
exit;
}
unless ( $opt{all} ) {
@releases = grep {
my $v = eval {
version->parse( $_->{version} ) > $installed_version };
defined $v ? $v : 1
} @releases;
}
say $_->serialize for @releases;
}
else {
print $source;
}