| 1 | package Module::CheckDep::Version; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 2 | ▶ | use 5.006; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 2 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 2 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | 2 | ▶ | use version; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | 2 | our $VERSION = '0.09'; | |||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | 2 | require Exporter; | |||||||||||||||||||||||||||
| 11 | 2 | our @ISA = qw(Exporter); | |||||||||||||||||||||||||||
| 12 | 2 | our @EXPORT_OK = qw(check_deps); | |||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | 2 | ▶ | use MetaCPAN::Client; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||
| 16 | 2 | my $mc = MetaCPAN::Client->new(debug => 1); | |||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | 9 | ▶ | sub check_deps { | ||||||||||||||||||||||||||
|
Subroutine
check_deps: called CC=18 SCAR=28.9
Pod
documented
| |||||||||||||||||||||||||||||
| 19 | 9 | my ($author, %args) = @_; | |||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | 9 | ▶ | die "check_deps() requires an \"AUTHOR\" param\n" if ! $author; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | 8 | my $module = $args{module}; | |||||||||||||||||||||||||||
| 24 | 8 | my $all = $args{all}; | |||||||||||||||||||||||||||
| 25 | 8 | my $custom_handler = $args{handler}; | |||||||||||||||||||||||||||
| 26 | 8 | my $return = $args{return}; | |||||||||||||||||||||||||||
| 27 | 8 | ▶ | my $ignore_any = defined $args{ignore_any} ? $args{ignore_any} : 1; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||
| 29 | 8 | my $author_modules = _author_modules($author); | |||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||
| 31 | 8 | my %needs_attention; | |||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||
| 33 | 8 | for my $dist (keys %{ $author_modules }){ | |||||||||||||||||||||||||||
| 34 | 496 | ▶ | next if $module && ($module ne $dist); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$module and $module ne $dist
MC/DC100%2/2
$module and $module ne $dist
$module
$module ne $dist
Truth table100%3/3
A and B
A= $moduleB= $module ne $dist
| |||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||
| 36 | 252 | $dist =~ s/::/-/g; | |||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||
| 38 | 252 | my $release = $mc->release($dist); | |||||||||||||||||||||||||||
| 39 | 252 | my $deps = $release->{data}{dependency}; | |||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||
| 41 | 252 | for my $dep (@$deps){ | |||||||||||||||||||||||||||
| 42 | 1644 | my $dep_mod = $dep->{module}; | |||||||||||||||||||||||||||
| 43 | 1644 | my $dep_ver = $dep->{version}; | |||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||
| 45 | 1644 | ▶ | next if $dep_mod eq 'perl'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||
| 47 | 1420 | ▶ | if ($ignore_any && $dep_ver == 0){ | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$ignore_any and $dep_ver == 0
MC/DC100%2/2
$ignore_any and $dep_ver == 0
$ignore_any
$dep_ver == 0
Truth table100%3/3
A and B
A= $ignore_anyB= $dep_ver == 0
| |||||||||||||||||||||||||||||
| 48 | 1001 | next; | |||||||||||||||||||||||||||
| 49 | } | ||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||
| 51 | 419 | ▶ | $dep_ver .= '.00' if $dep_ver !~ /\./; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||
| 53 | 419 | ▶ | next if ! $all && ! $author_modules->{$dep_mod}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$all or $author_modules->{$dep_mod}
MC/DC100%2/2
$all or $author_modules->{$dep_mod}
$all
$author_modules->{$dep_mod}
Truth table100%3/3
A or B
A= $allB= $author_modules->{$dep_mod}
| |||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||
| 55 | 335 | my $cur_ver; | |||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||
| 57 | 335 | ▶ | if ($author_modules->{$dep_mod}){ | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 58 | 292 | $cur_ver = $author_modules->{$dep_mod}; | |||||||||||||||||||||||||||
| 59 | } | ||||||||||||||||||||||||||||
| 60 | else { | ||||||||||||||||||||||||||||
| 61 | 43 | my $dep_mod_normalized = $dep_mod; | |||||||||||||||||||||||||||
| 62 | 43 | $dep_mod_normalized =~ s/::/-/g; | |||||||||||||||||||||||||||
| 63 | 43 | my $dep_dist; | |||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||
| 65 | 43 | my $dist_found_ok = eval { | |||||||||||||||||||||||||||
| 66 | 43 | $dep_dist = $mc->release($dep_mod_normalized); | |||||||||||||||||||||||||||
| 67 | 37 | 1; | |||||||||||||||||||||||||||
| 68 | }; | ||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||
| 70 | 43 | ▶ | next if ! $dist_found_ok; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 71 | 37 | $cur_ver = $dep_dist->{data}{version}; | |||||||||||||||||||||||||||
| 72 | } | ||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||
| 74 | 329 | $dep_ver = version->parse($dep_ver); | |||||||||||||||||||||||||||
| 75 | 329 | $cur_ver = version->parse($cur_ver); | |||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||
| 77 | 329 | ▶ | if ($dep_ver != $cur_ver){ | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 78 | 220 | $needs_attention{$dist}{$dep_mod}{cur_ver} = $cur_ver; | |||||||||||||||||||||||||||
| 79 | 220 | $needs_attention{$dist}{$dep_mod}{dep_ver} = $dep_ver; | |||||||||||||||||||||||||||
| 80 | } | ||||||||||||||||||||||||||||
| 81 | } | ||||||||||||||||||||||||||||
| 82 | } | ||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||
| 84 | 8 | ▶ | if (defined $custom_handler){ | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 85 | 1 | $custom_handler->(\%needs_attention); | |||||||||||||||||||||||||||
| 86 | } | ||||||||||||||||||||||||||||
| 87 | else { | ||||||||||||||||||||||||||||
| 88 | 7 | ▶ | _display(\%needs_attention) if ! $return; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 89 | } | ||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||
| 91 | 8 | return \%needs_attention; | |||||||||||||||||||||||||||
| 92 | } | ||||||||||||||||||||||||||||
| 93 | 8 | ▶ | sub _author_modules { | ||||||||||||||||||||||||||
|
Subroutine
_author_modules: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||
| 94 | 8 | my ($author) = @_; | |||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||
| 96 | 8 | my $query = { | |||||||||||||||||||||||||||
| 97 | all => [ | ||||||||||||||||||||||||||||
| 98 | { author => $author }, | ||||||||||||||||||||||||||||
| 99 | { status => 'latest' }, | ||||||||||||||||||||||||||||
| 100 | ], | ||||||||||||||||||||||||||||
| 101 | }; | ||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||
| 103 | 8 | my $limit = { | |||||||||||||||||||||||||||
| 104 | '_source' => [ | ||||||||||||||||||||||||||||
| 105 | qw(distribution version) | ||||||||||||||||||||||||||||
| 106 | ] | ||||||||||||||||||||||||||||
| 107 | }; | ||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||
| 109 | 8 | my $releases = $mc->release($query, $limit); | |||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||
| 111 | 8 | my %rel_info; | |||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||
| 113 | 8 | ▶ | while (my $rel = $releases->next){ | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 114 | 496 | my $dist = $rel->distribution; | |||||||||||||||||||||||||||
| 115 | 496 | $dist =~ s/-/::/g; | |||||||||||||||||||||||||||
| 116 | 496 | $rel_info{$dist} = $rel->version; | |||||||||||||||||||||||||||
| 117 | } | ||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||
| 119 | 8 | return \%rel_info; | |||||||||||||||||||||||||||
| 120 | } | ||||||||||||||||||||||||||||
| 121 | 1 | ▶ | sub _display { | ||||||||||||||||||||||||||
|
Subroutine
_display: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||
| 122 | 1 | my $dists = shift; | |||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||
| 124 | 1 | for my $dist (keys %$dists){ | |||||||||||||||||||||||||||
| 125 | 1 | print "$dist:\n"; | |||||||||||||||||||||||||||
| 126 | 1 | for (keys %{ $dists->{$dist} }){ | |||||||||||||||||||||||||||
| 127 | 1 | print "\t$_:\n" . | |||||||||||||||||||||||||||
| 128 | "\t\t$dists->{$dist}{$_}{dep_ver} -> " . | ||||||||||||||||||||||||||||
| 129 | "$dists->{$dist}{$_}{cur_ver}\n"; | ||||||||||||||||||||||||||||
| 130 | } | ||||||||||||||||||||||||||||
| 131 | 1 | print "\n"; | |||||||||||||||||||||||||||
| 132 | } | ||||||||||||||||||||||||||||
| 133 | } | ||||||||||||||||||||||||||||
| 134 | 0 | ▶ | sub __placeholder {} # vim folds | ||||||||||||||||||||||||||
|
Subroutine
__placeholder: not called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||
| 136 | 2 | 1; | |||||||||||||||||||||||||||
| 137 | __END__ | ||||||||||||||||||||||||||||