File Coverage

blib/lib/Dist/Zilla/Plugin/SchwartzRatio.pm
Criterion Covered Total %
statement 21 21 100.0
branch n/a
condition n/a
subroutine 7 7 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::SchwartzRatio;
2             our $AUTHORITY = 'cpan:YANICK';
3             # ABSTRACT: display the Schwartz ratio of the distribution upon release
4             $Dist::Zilla::Plugin::SchwartzRatio::VERSION = '0.3.3';
5              
6 1     1   161019 use 5.14.0;
  1         7  
7 1     1   5 use strict;
  1         2  
  1         16  
8 1     1   4 use warnings;
  1         1  
  1         23  
9              
10 1     1   376 use List::UtilsBy qw/ sort_by /;
  1         1535  
  1         54  
11 1     1   359 use MetaCPAN::Client;
  1         275570  
  1         31  
12              
13 1     1   443 use Moose;
  1         401267  
  1         8  
14              
15             with qw/
16             Dist::Zilla::Role::Plugin
17             Dist::Zilla::Role::AfterRelease
18             /;
19              
20             has mcpan => (
21             is => 'ro',
22             lazy => 1,
23             default => sub { MetaCPAN::Client->new },
24             );
25              
26             has total_nbr => (
27             traits => [ 'Counter' ],
28             is => 'rw',
29             default => 0,
30             handles => { inc_releases => 'inc' },
31             );
32              
33             before total_nbr => sub { $_[0]->releases };
34              
35             has releases => (
36             is => 'ro',
37             traits => [ 'Array' ],
38             handles => {
39             all_releases => 'elements',
40             nbr_releases => 'count',
41             },
42             lazy => 1,
43             default => sub {
44             my $self = shift;
45              
46             my $releases = $self->mcpan->release({
47             distribution => $self->zilla->name
48             });
49             my @releases;
50              
51             while( my $r = $releases->next ) {
52             $self->inc_releases;
53             next if $r->status eq 'backpan';
54             my( $version, $date ) = map { $r->$_ } qw/ version date /;
55             $date =~ s/T.*//;
56             push @releases, [ 'v'.$version, $date ];
57             }
58              
59             return [ sort_by { $_->[1] } @releases ];
60             },
61             );
62              
63             sub after_release {
64 1     1 0 196132 my $self = shift;
65              
66 1         23 $self->log( sprintf "Total number of releases: %d", $self->total_nbr );
67              
68 1         307 $self->log( $self->nbr_releases . " old releases are lingering on CPAN" );
69 1         364 $self->log( "\t" . join ', ', @$_ ) for $self->all_releases;
70             }
71              
72             __PACKAGE__->meta->make_immutable;
73              
74             1;
75              
76             __END__
77              
78             =pod
79              
80             =encoding UTF-8
81              
82             =head1 NAME
83              
84             Dist::Zilla::Plugin::SchwartzRatio - display the Schwartz ratio of the distribution upon release
85              
86             =head1 VERSION
87              
88             version 0.3.3
89              
90             =head1 SYNOPSIS
91              
92             In dist.ini:
93              
94             [SchwartzRatio]
95              
96             =head1 DESCRIPTION
97              
98             The Schwartz Ratio of CPAN is the number of number of latest
99             releases over the total number of releases that CPAN has. For
100             a single distribution, it boils down to the less exciting
101             number of previous releases still on CPAN.
102              
103             After a successful release, the plugin displays
104             the releases of the distribution still kicking around on CPAN,
105             just to give an idea to the author that maybe it's time
106             to do some cleanup.
107              
108             =head1 SEE ALSO
109              
110             =over
111              
112             =item L<App-PAUSE-cleanup|https://metacpan.org/release/App-PAUSE-cleanup>
113              
114             CLI utility to list and help you delete easily your distributions on CPAN.
115              
116             =back
117              
118             =head1 AUTHOR
119              
120             Yanick Champoux <yanick@cpan.org>
121              
122             =head1 COPYRIGHT AND LICENSE
123              
124             This software is copyright (c) 2019, 2017, 2012 by Yanick Champoux.
125              
126             This is free software; you can redistribute it and/or modify it under
127             the same terms as the Perl 5 programming language system itself.
128              
129             =cut