| 1 | package OrePAN2::Auditor; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 1 | ▶ | use Moo; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||
| 5 | 1 | ▶ | use feature qw( say state ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | 1 | ▶ | use version; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | 1 | ▶ | use Carp qw( croak ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | 1 | ▶ | use List::Compare (); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | 1 | ▶ | use MooX::Options; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | 1 | ▶ | use Parse::CPAN::Packages::Fast 0.09 (); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | 1 | ▶ | use Path::Tiny (); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 13 | 1 | ▶ | use Type::Params qw( signature ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 14 | 1 | ▶ | use Types::Self qw( Self ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 15 | 1 | ▶ | use Types::Standard qw( ArrayRef Bool Enum InstanceOf Str ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 16 | 1 | ▶ | use Types::URI qw( Uri ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 17 | 1 | ▶ | use LWP::UserAgent (); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | 1 | ▶ | use namespace::clean -except => [qw( _options_data _options_config )]; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | 1 | option cpan => ( | |||||||||||||||||||||||||||
| 22 | is => 'ro', | ||||||||||||||||||||||||||||
| 23 | isa => Uri, | ||||||||||||||||||||||||||||
| 24 | format => 's', | ||||||||||||||||||||||||||||
| 25 | required => 1, | ||||||||||||||||||||||||||||
| 26 | coerce => 1, | ||||||||||||||||||||||||||||
| 27 | doc => 'the path to a CPAN 02packages file', | ||||||||||||||||||||||||||||
| 28 | ); | ||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||
| 30 | 1 | option darkpan => ( | |||||||||||||||||||||||||||
| 31 | is => 'ro', | ||||||||||||||||||||||||||||
| 32 | isa => Uri, | ||||||||||||||||||||||||||||
| 33 | format => 's', | ||||||||||||||||||||||||||||
| 34 | required => 1, | ||||||||||||||||||||||||||||
| 35 | coerce => 1, | ||||||||||||||||||||||||||||
| 36 | doc => 'the path to your DarkPan 02packages file', | ||||||||||||||||||||||||||||
| 37 | ); | ||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||
| 39 | 1 | option show => ( | |||||||||||||||||||||||||||
| 40 | is => 'ro', | ||||||||||||||||||||||||||||
| 41 | isa => | ||||||||||||||||||||||||||||
| 42 | Enum [qw( cpan-only-modules darkpan-only-modules outdated-modules )], | ||||||||||||||||||||||||||||
| 43 | format => 's', | ||||||||||||||||||||||||||||
| 44 | ); | ||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||
| 46 | 1 | option verbose => ( | |||||||||||||||||||||||||||
| 47 | is => 'ro', | ||||||||||||||||||||||||||||
| 48 | isa => Bool, | ||||||||||||||||||||||||||||
| 49 | default => 0, | ||||||||||||||||||||||||||||
| 50 | ); | ||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||
| 52 | has cpan_modules => ( | ||||||||||||||||||||||||||||
| 53 | is => 'ro', | ||||||||||||||||||||||||||||
| 54 | isa => ArrayRef [Str], | ||||||||||||||||||||||||||||
| 55 | lazy => 1, | ||||||||||||||||||||||||||||
| 56 | 1 | ▶ | default => sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 57 | 1 | my $self = shift; | |||||||||||||||||||||||||||
| 58 | 1 | return $self->_modules_from_parser( $self->_cpan_parser ); | |||||||||||||||||||||||||||
| 59 | }, | ||||||||||||||||||||||||||||
| 60 | 1 | ); | |||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||
| 62 | has darkpan_modules => ( | ||||||||||||||||||||||||||||
| 63 | is => 'ro', | ||||||||||||||||||||||||||||
| 64 | isa => ArrayRef [Str], | ||||||||||||||||||||||||||||
| 65 | lazy => 1, | ||||||||||||||||||||||||||||
| 66 | 1 | ▶ | default => sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 67 | 1 | my $self = shift; | |||||||||||||||||||||||||||
| 68 | 1 | return $self->_modules_from_parser( $self->_darkpan_parser ); | |||||||||||||||||||||||||||
| 69 | }, | ||||||||||||||||||||||||||||
| 70 | 1 | ); | |||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||
| 72 | has cpan_only_modules => ( | ||||||||||||||||||||||||||||
| 73 | is => 'ro', | ||||||||||||||||||||||||||||
| 74 | isa => ArrayRef [Str], | ||||||||||||||||||||||||||||
| 75 | lazy => 1, | ||||||||||||||||||||||||||||
| 76 | 1 | ▶ | default => sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 77 | 1 | return [ shift->_list_compare->get_complement ]; | |||||||||||||||||||||||||||
| 78 | }, | ||||||||||||||||||||||||||||
| 79 | 1 | ); | |||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||
| 81 | has darkpan_only_modules => ( | ||||||||||||||||||||||||||||
| 82 | is => 'ro', | ||||||||||||||||||||||||||||
| 83 | isa => ArrayRef [Str], | ||||||||||||||||||||||||||||
| 84 | lazy => 1, | ||||||||||||||||||||||||||||
| 85 | 1 | ▶ | default => sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 86 | 1 | return [ shift->_list_compare->get_unique ]; | |||||||||||||||||||||||||||
| 87 | }, | ||||||||||||||||||||||||||||
| 88 | 1 | ); | |||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||
| 90 | 1 | has outdated_modules => ( | |||||||||||||||||||||||||||
| 91 | is => 'ro', | ||||||||||||||||||||||||||||
| 92 | isa => ArrayRef [Str], | ||||||||||||||||||||||||||||
| 93 | lazy => 1, | ||||||||||||||||||||||||||||
| 94 | builder => '_build_outdated_modules', | ||||||||||||||||||||||||||||
| 95 | ); | ||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||
| 97 | has ua => ( | ||||||||||||||||||||||||||||
| 98 | is => 'ro', | ||||||||||||||||||||||||||||
| 99 | isa => InstanceOf ['LWP::UserAgent'], | ||||||||||||||||||||||||||||
| 100 | 1 | ▶ | default => sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 101 | 1 | return LWP::UserAgent->new(); | |||||||||||||||||||||||||||
| 102 | }, | ||||||||||||||||||||||||||||
| 103 | 1 | ); | |||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||
| 105 | has _cpan_parser => ( | ||||||||||||||||||||||||||||
| 106 | is => 'ro', | ||||||||||||||||||||||||||||
| 107 | isa => InstanceOf ['Parse::CPAN::Packages::Fast'], | ||||||||||||||||||||||||||||
| 108 | lazy => 1, | ||||||||||||||||||||||||||||
| 109 | 1 | ▶ | default => sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 110 | 1 | my $self = shift; | |||||||||||||||||||||||||||
| 111 | 1 | return $self->_parser_for_url( $self->cpan ); | |||||||||||||||||||||||||||
| 112 | }, | ||||||||||||||||||||||||||||
| 113 | 1 | ); | |||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||
| 115 | has _darkpan_parser => ( | ||||||||||||||||||||||||||||
| 116 | is => 'ro', | ||||||||||||||||||||||||||||
| 117 | isa => InstanceOf ['Parse::CPAN::Packages::Fast'], | ||||||||||||||||||||||||||||
| 118 | lazy => 1, | ||||||||||||||||||||||||||||
| 119 | 1 | ▶ | default => sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 120 | 1 | my $self = shift; | |||||||||||||||||||||||||||
| 121 | 1 | return $self->_parser_for_url( $self->darkpan ); | |||||||||||||||||||||||||||
| 122 | }, | ||||||||||||||||||||||||||||
| 123 | 1 | ); | |||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||
| 125 | has _list_compare => ( | ||||||||||||||||||||||||||||
| 126 | is => 'ro', | ||||||||||||||||||||||||||||
| 127 | isa => InstanceOf ['List::Compare'], | ||||||||||||||||||||||||||||
| 128 | lazy => 1, | ||||||||||||||||||||||||||||
| 129 | 1 | ▶ | default => sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 130 | 1 | my $self = shift; | |||||||||||||||||||||||||||
| 131 | 1 | return List::Compare->new( | |||||||||||||||||||||||||||
| 132 | $self->darkpan_modules, | ||||||||||||||||||||||||||||
| 133 | $self->cpan_modules | ||||||||||||||||||||||||||||
| 134 | ); | ||||||||||||||||||||||||||||
| 135 | }, | ||||||||||||||||||||||||||||
| 136 | 1 | ); | |||||||||||||||||||||||||||
| 137 | |||||||||||||||||||||||||||||
| 138 | 0 | ▶ | sub run { | ||||||||||||||||||||||||||
|
Subroutine
run: not called CC=5 SCAR=34.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 139 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||
| 141 | 0 | my $method = $self->show; | |||||||||||||||||||||||||||
| 142 | 0 | $method =~ s{-}{_}g; | |||||||||||||||||||||||||||
| 143 | |||||||||||||||||||||||||||||
| 144 | 0 | my $modules = $self->$method; | |||||||||||||||||||||||||||
| 145 | |||||||||||||||||||||||||||||
| 146 | 0 | ▶ | if ( $method eq 'outdated_modules' && $self->verbose ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$method eq "outdated_modules" and $self->verbose
MC/DC0%0/2
$method eq "outdated_modules" and $self->verbose
$method eq "outdated_modules"
$self->verbose
Truth table0%0/3
A and B
A= $method eq "outdated_modules"B= $self->verbose
| |||||||||||||||||||||||||||||
| 147 | 0 | foreach my $module ( @{$modules} ) { | |||||||||||||||||||||||||||
| 148 | 0 | my @row = ( | |||||||||||||||||||||||||||
| 149 | $module, | ||||||||||||||||||||||||||||
| 150 | $self->darkpan_module($module)->distribution->distvname, | ||||||||||||||||||||||||||||
| 151 | $self->cpan_module($module)->distribution->distvname, | ||||||||||||||||||||||||||||
| 152 | |||||||||||||||||||||||||||||
| 153 | sprintf( | ||||||||||||||||||||||||||||
| 154 | 'https://metacpan.org/changes/distribution/%s', | ||||||||||||||||||||||||||||
| 155 | $self->cpan_module($module)->distribution->dist | ||||||||||||||||||||||||||||
| 156 | ), | ||||||||||||||||||||||||||||
| 157 | ); | ||||||||||||||||||||||||||||
| 158 | 0 | say join "\t", @row; | |||||||||||||||||||||||||||
| 159 | } | ||||||||||||||||||||||||||||
| 160 | 0 | return; | |||||||||||||||||||||||||||
| 161 | } | ||||||||||||||||||||||||||||
| 162 | |||||||||||||||||||||||||||||
| 163 | 0 | say $_ for @{$modules}; | |||||||||||||||||||||||||||
| 164 | } | ||||||||||||||||||||||||||||
| 165 | |||||||||||||||||||||||||||||
| 166 | 1 | ▶ | sub cpan_module { | ||||||||||||||||||||||||||
|
Subroutine
cpan_module: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 167 | 1 | state $signature = signature( method => Self, positional => [Str] ); | |||||||||||||||||||||||||||
| 168 | 1 | my ( $self, $module ) = $signature->(@_); | |||||||||||||||||||||||||||
| 169 | |||||||||||||||||||||||||||||
| 170 | 1 | return $self->_cpan_parser->package($module); | |||||||||||||||||||||||||||
| 171 | } | ||||||||||||||||||||||||||||
| 172 | |||||||||||||||||||||||||||||
| 173 | 1 | ▶ | sub darkpan_module { | ||||||||||||||||||||||||||
|
Subroutine
darkpan_module: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 174 | 1 | state $signature = signature( method => Self, positional => [Str] ); | |||||||||||||||||||||||||||
| 175 | 1 | my ( $self, $module ) = $signature->(@_); | |||||||||||||||||||||||||||
| 176 | |||||||||||||||||||||||||||||
| 177 | 1 | return $self->_darkpan_parser->package($module); | |||||||||||||||||||||||||||
| 178 | } | ||||||||||||||||||||||||||||
| 179 | |||||||||||||||||||||||||||||
| 180 | 1 | ▶ | sub _build_outdated_modules { | ||||||||||||||||||||||||||
|
Subroutine
_build_outdated_modules: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||
| 181 | 1 | my $self = shift; | |||||||||||||||||||||||||||
| 182 | |||||||||||||||||||||||||||||
| 183 | 1 | my $darkpan = $self->_darkpan_parser; | |||||||||||||||||||||||||||
| 184 | 1 | my $cpan = $self->_cpan_parser; | |||||||||||||||||||||||||||
| 185 | |||||||||||||||||||||||||||||
| 186 | 1 | my @outdated; | |||||||||||||||||||||||||||
| 187 | 1 | for my $module ( $self->_list_compare->get_intersection ) { | |||||||||||||||||||||||||||
| 188 | 1 | ▶ | if ( version->parse( $darkpan->package($module)->version ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 189 | < version->parse( $cpan->package($module)->version ) ) { | ||||||||||||||||||||||||||||
| 190 | 1 | push @outdated, $module; | |||||||||||||||||||||||||||
| 191 | } | ||||||||||||||||||||||||||||
| 192 | } | ||||||||||||||||||||||||||||
| 193 | 1 | return \@outdated; | |||||||||||||||||||||||||||
| 194 | } | ||||||||||||||||||||||||||||
| 195 | |||||||||||||||||||||||||||||
| 196 | 2 | ▶ | sub _modules_from_parser { | ||||||||||||||||||||||||||
|
Subroutine
_modules_from_parser: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 197 | 2 | my $self = shift; | |||||||||||||||||||||||||||
| 198 | 2 | my $parser = shift; | |||||||||||||||||||||||||||
| 199 | |||||||||||||||||||||||||||||
| 200 | 2 | return [ sort { $a cmp $b } $parser->packages ]; | |||||||||||||||||||||||||||
| 201 | } | ||||||||||||||||||||||||||||
| 202 | |||||||||||||||||||||||||||||
| 203 | 2 | ▶ | sub _parser_for_url { | ||||||||||||||||||||||||||
|
Subroutine
_parser_for_url: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||
| 204 | 2 | my $self = shift; | |||||||||||||||||||||||||||
| 205 | 2 | my $url = shift; | |||||||||||||||||||||||||||
| 206 | |||||||||||||||||||||||||||||
| 207 | 2 | ▶ | $url->scheme('file') if !$url->scheme; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 208 | |||||||||||||||||||||||||||||
| 209 | 2 | my $res = $self->ua->get($url); | |||||||||||||||||||||||||||
| 210 | 2 | ▶ | croak "could not fetch $url" if !$res->is_success; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 211 | |||||||||||||||||||||||||||||
| 212 | # dumb hack to avoid having to uncompress this ourselves | ||||||||||||||||||||||||||||
| 213 | 2 | my @path_segments = $url->path_segments; | |||||||||||||||||||||||||||
| 214 | |||||||||||||||||||||||||||||
| 215 | 2 | my $err = <<"EOF"; | |||||||||||||||||||||||||||
| 216 | Path invalid for $url Please provide full path to 02packages file. | ||||||||||||||||||||||||||||
| 217 | EOF | ||||||||||||||||||||||||||||
| 218 | 2 | ▶ | croak $err if !@path_segments; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 219 | |||||||||||||||||||||||||||||
| 220 | 2 | my $tempdir = Path::Tiny->tempdir; | |||||||||||||||||||||||||||
| 221 | 2 | my $child = $tempdir->child( pop @path_segments ); | |||||||||||||||||||||||||||
| 222 | 2 | $child->spew_raw( $res->content ); | |||||||||||||||||||||||||||
| 223 | |||||||||||||||||||||||||||||
| 224 | 2 | return Parse::CPAN::Packages::Fast->new( $child->stringify ); | |||||||||||||||||||||||||||
| 225 | } | ||||||||||||||||||||||||||||
| 226 | |||||||||||||||||||||||||||||
| 227 | 1 | 1; | |||||||||||||||||||||||||||
| 228 | |||||||||||||||||||||||||||||
| 229 | __END__ | ||||||||||||||||||||||||||||