| 1 | package OPM::Maker::Command::info; | ||||||||||||
| 2 | 16 | $OPM::Maker::Command::info::VERSION = '1.17'; | |||||||||||
| 3 | |||||||||||||
| 4 | 16 | ▶ | use strict; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 5 | 16 | ▶ | use warnings; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 6 | |||||||||||||
| 7 | # ABSTRACT: show version info about opmbuild commands | ||||||||||||
| 8 | |||||||||||||
| 9 | 16 | ▶ | use Carp qw(croak); | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 10 | 16 | ▶ | use OPM::Maker -command; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 11 | 16 | ▶ | use HTTP::Tiny; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 12 | 16 | ▶ | use JSON::PP; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 13 | |||||||||||||
| 14 | 0 | ▶ | sub abstract { | ||||||||||
|
Subroutine
abstract: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||
| 15 | 0 | return "show version info about opmbuild commands"; | |||||||||||
| 16 | } | ||||||||||||
| 17 | |||||||||||||
| 18 | 0 | ▶ | sub opt_spec { | ||||||||||
|
Subroutine
opt_spec: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||
| 19 | return ( | ||||||||||||
| 20 | 0 | [ 'no-cpan-info', 'Do not get information about the distribution that ships a command' ], | |||||||||||
| 21 | ); | ||||||||||||
| 22 | } | ||||||||||||
| 23 | |||||||||||||
| 24 | |||||||||||||
| 25 | 0 | ▶ | sub usage_desc { | ||||||||||
|
Subroutine
usage_desc: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||
| 26 | 0 | return "opmbuild info [--no-cpan-info]"; | |||||||||||
| 27 | } | ||||||||||||
| 28 | |||||||||||||
| 29 | 0 | ▶ | sub execute { | ||||||||||
|
Subroutine
execute: not called CC=5 SCAR=34.0
Pod
documented
| |||||||||||||
| 30 | 0 | my ($self, $opt, $args) = @_; | |||||||||||
| 31 | |||||||||||||
| 32 | 0 | my $app = $self->app; | |||||||||||
| 33 | 0 | my $ua = HTTP::Tiny->new; | |||||||||||
| 34 | |||||||||||||
| 35 | my %commands = map { | ||||||||||||
| 36 | 0 | my ($short) = (split /::/, $_)[-1]; | |||||||||||
| 37 | 0 | $short => $_; | |||||||||||
| 38 | } grep { | ||||||||||||
| 39 | 0 | $_ =~ m{\AOPM::Maker::Command}; | |||||||||||
| 40 | } $app->command_plugins; | ||||||||||||
| 41 | |||||||||||||
| 42 | CMD: | ||||||||||||
| 43 | 0 | for my $cmd ( sort keys %commands ) { | |||||||||||
| 44 | 0 | my $module = $commands{$cmd}; | |||||||||||
| 45 | |||||||||||||
| 46 | 0 | print sprintf "%s:\n version: %s\n module: %s\n", $cmd, $module->VERSION(), $module; | |||||||||||
| 47 | |||||||||||||
| 48 | 0 | ▶ | if ( !$opt->{no_cpan_info} ) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 49 | 0 | my $json = _json( $module, $module->VERSION() ); | |||||||||||
| 50 | 0 | my $response = $ua->post( | |||||||||||
| 51 | 'https://fastapi.metacpan.org/v1/file/_search', { | ||||||||||||
| 52 | content => $json, | ||||||||||||
| 53 | } | ||||||||||||
| 54 | ); | ||||||||||||
| 55 | |||||||||||||
| 56 | 0 | ▶ | next CMD if !$response->{success}; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 57 | |||||||||||||
| 58 | 0 | my ($dist, $version) = _from_json( $response->{content} ); | |||||||||||
| 59 | |||||||||||||
| 60 | 0 | ▶ | next CMD if !$dist; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 61 | |||||||||||||
| 62 | 0 | print sprintf " dist: %s\n dist-version: %s\n", $dist, $version; | |||||||||||
| 63 | } | ||||||||||||
| 64 | } | ||||||||||||
| 65 | } | ||||||||||||
| 66 | |||||||||||||
| 67 | 0 | ▶ | sub _from_json { | ||||||||||
|
Subroutine
_from_json: not called CC=2 SCAR=17.9
| |||||||||||||
| 68 | 0 | my ($json) = @_; | |||||||||||
| 69 | |||||||||||||
| 70 | 0 | my $data = JSON::PP->new->utf8(1)->decode( $json ); | |||||||||||
| 71 | 0 | ▶ | my $fields = $data->{hits}->{hits}->[0]->{fields} || {}; | ||||||||||
|
Condition0%0/2
$data->{'hits'}{'hits'}[0]{'fields'} || {}
MC/DC0%0/1
$data->{'hits'}{'hits'}[0]{'fields'} || {}
$data->{'hits'}{'hits'}[0]{'fields'}
Truth table0%0/2
A
A= $data->{'hits'}{'hits'}[0]{'fields'}
| |||||||||||||
| 72 | |||||||||||||
| 73 | 0 | return @{ $fields }{qw/distribution version/}; | |||||||||||
| 74 | } | ||||||||||||
| 75 | |||||||||||||
| 76 | 0 | ▶ | sub _json { | ||||||||||
|
Subroutine
_json: not called CC=2 SCAR=17.9
| |||||||||||||
| 77 | 0 | my ($module, $version) = @_; | |||||||||||
| 78 | |||||||||||||
| 79 | 0 | my $dots = $version =~ tr/././; | |||||||||||
| 80 | |||||||||||||
| 81 | 0 | ▶ | $version = 'v' . $version if $dots > 1; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 82 | 0 | return JSON::PP->new->utf8(1)->encode({ | |||||||||||
| 83 | "query" => { | ||||||||||||
| 84 | "filtered" => { | ||||||||||||
| 85 | "query" => { | ||||||||||||
| 86 | "match_all" => {}, | ||||||||||||
| 87 | }, | ||||||||||||
| 88 | "filter" => { | ||||||||||||
| 89 | "and" => [ | ||||||||||||
| 90 | { | ||||||||||||
| 91 | "term" => { | ||||||||||||
| 92 | "module.name" => $module, | ||||||||||||
| 93 | }, | ||||||||||||
| 94 | }, | ||||||||||||
| 95 | { | ||||||||||||
| 96 | "term" => { | ||||||||||||
| 97 | "module.version" => $version, | ||||||||||||
| 98 | }, | ||||||||||||
| 99 | }, | ||||||||||||
| 100 | ], | ||||||||||||
| 101 | }, | ||||||||||||
| 102 | }, | ||||||||||||
| 103 | }, | ||||||||||||
| 104 | "fields" => ["release","distribution","version"], | ||||||||||||
| 105 | }); | ||||||||||||
| 106 | } | ||||||||||||
| 107 | |||||||||||||
| 108 | 16 | 1; | |||||||||||
| 109 | |||||||||||||
| 110 | __END__ | ||||||||||||