| 1 | package App::lcpan::Cmd::changes; | ||||||||||||||||||||
| 2 | |||||||||||||||||||||
| 3 | 1 | ▶ | use 5.010001; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 4 | 1 | ▶ | use strict; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 5 | 1 | ▶ | use warnings; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 6 | |||||||||||||||||||||
| 7 | 1 | ▶ | use Encode qw(decode); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 8 | |||||||||||||||||||||
| 9 | 1 | require App::lcpan; | |||||||||||||||||||
| 10 | |||||||||||||||||||||
| 11 | 1 | our $AUTHORITY = 'cpan:PERLANCAR'; # AUTHORITY | |||||||||||||||||||
| 12 | 1 | our $DATE = '2023-09-26'; # DATE | |||||||||||||||||||
| 13 | 1 | our $DIST = 'App-lcpan'; # DIST | |||||||||||||||||||
| 14 | 1 | our $VERSION = '1.074'; # VERSION | |||||||||||||||||||
| 15 | |||||||||||||||||||||
| 16 | 1 | our %SPEC; | |||||||||||||||||||
| 17 | |||||||||||||||||||||
| 18 | 1 | $SPEC{'handle_cmd'} = { | |||||||||||||||||||
| 19 | v => 1.1, | ||||||||||||||||||||
| 20 | summary => 'Show Changes of distribution/module', | ||||||||||||||||||||
| 21 | description => <<'_', | ||||||||||||||||||||
| 22 | |||||||||||||||||||||
| 23 | This command will find a file named Changes/CHANGES/ChangeLog or other similar | ||||||||||||||||||||
| 24 | name in the top-level directory inside the release tarballs and show it. | ||||||||||||||||||||
| 25 | |||||||||||||||||||||
| 26 | _ | ||||||||||||||||||||
| 27 | args => { | ||||||||||||||||||||
| 28 | %App::lcpan::common_args, | ||||||||||||||||||||
| 29 | %App::lcpan::mod_or_dist_or_script_args, | ||||||||||||||||||||
| 30 | #parse => { | ||||||||||||||||||||
| 31 | # summary => 'Parse with CPAN::Changes', | ||||||||||||||||||||
| 32 | # schema => 'bool', | ||||||||||||||||||||
| 33 | #}. | ||||||||||||||||||||
| 34 | }, | ||||||||||||||||||||
| 35 | examples => [ | ||||||||||||||||||||
| 36 | { | ||||||||||||||||||||
| 37 | summary => 'Use module name', | ||||||||||||||||||||
| 38 | argv => ['Data::CSel::Parser'], | ||||||||||||||||||||
| 39 | test => 0, | ||||||||||||||||||||
| 40 | 'x.doc.show_result' => 0, | ||||||||||||||||||||
| 41 | }, | ||||||||||||||||||||
| 42 | #{ | ||||||||||||||||||||
| 43 | # summary => 'Use dist name, parse', | ||||||||||||||||||||
| 44 | # argv => ['--parse', 'App-PMUtils'], | ||||||||||||||||||||
| 45 | # test => 0, | ||||||||||||||||||||
| 46 | # 'x.doc.show_result' => 0, | ||||||||||||||||||||
| 47 | #}, | ||||||||||||||||||||
| 48 | ], | ||||||||||||||||||||
| 49 | }; | ||||||||||||||||||||
| 50 | 0 | ▶ | sub handle_cmd { | ||||||||||||||||||
|
Subroutine
handle_cmd: not called CC=17 SCAR=57.2
Pod
documented
| |||||||||||||||||||||
| 51 | 0 | my %args = @_; | |||||||||||||||||||
| 52 | |||||||||||||||||||||
| 53 | 0 | my $state = App::lcpan::_init(\%args, 'ro'); | |||||||||||||||||||
| 54 | 0 | my $dbh = $state->{dbh}; | |||||||||||||||||||
| 55 | |||||||||||||||||||||
| 56 | 0 | my $mod_or_dist_or_script = $args{module_or_dist_or_script}; | |||||||||||||||||||
| 57 | 0 | $mod_or_dist_or_script =~ s!/!::!g; # XXX this should be done by coercer | |||||||||||||||||||
| 58 | |||||||||||||||||||||
| 59 | 0 | my @join; | |||||||||||||||||||
| 60 | my @where; | ||||||||||||||||||||
| 61 | 0 | my @bind; | |||||||||||||||||||
| 62 | |||||||||||||||||||||
| 63 | 0 | my @file_ids; | |||||||||||||||||||
| 64 | { | ||||||||||||||||||||
| 65 | # search in module first | ||||||||||||||||||||
| 66 | 0 | ▶ | unless ($mod_or_dist_or_script =~ /-/) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 67 | 0 | my $sth = $dbh->prepare("SELECT file_id FROM module WHERE name=?"); | |||||||||||||||||||
| 68 | 0 | $sth->execute($mod_or_dist_or_script); | |||||||||||||||||||
| 69 | 0 | ▶ | while (my ($e) = $sth->fetchrow_array) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 70 | 0 | push @file_ids, $e; | |||||||||||||||||||
| 71 | } | ||||||||||||||||||||
| 72 | } | ||||||||||||||||||||
| 73 | # search in dist or script | ||||||||||||||||||||
| 74 | 0 | ▶ | unless ($mod_or_dist_or_script =~ /::/) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 75 | 0 | my $dist_found; | |||||||||||||||||||
| 76 | 0 | my $sth = $dbh->prepare("SELECT id FROM file WHERE dist_name=? ORDER BY dist_version_numified DESC LIMIT 1"); | |||||||||||||||||||
| 77 | 0 | $sth->execute($mod_or_dist_or_script); | |||||||||||||||||||
| 78 | 0 | ▶ | while (my ($e) = $sth->fetchrow_array) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 79 | 0 | $dist_found++; | |||||||||||||||||||
| 80 | 0 | push @file_ids, $e; | |||||||||||||||||||
| 81 | } | ||||||||||||||||||||
| 82 | |||||||||||||||||||||
| 83 | 0 | ▶ | unless ($dist_found) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 84 | 0 | my $sth = $dbh->prepare("SELECT file_id FROM script WHERE name=?"); | |||||||||||||||||||
| 85 | 0 | $sth->execute($mod_or_dist_or_script); | |||||||||||||||||||
| 86 | 0 | ▶ | while (my ($e) = $sth->fetchrow_array) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 87 | 0 | push @file_ids, $e; | |||||||||||||||||||
| 88 | } | ||||||||||||||||||||
| 89 | } | ||||||||||||||||||||
| 90 | } | ||||||||||||||||||||
| 91 | |||||||||||||||||||||
| 92 | 0 | ▶ | return [404, "No such module/dist/script"] unless @file_ids; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 93 | 0 | push @where, "file.id IN (".join(",", @file_ids).")"; | |||||||||||||||||||
| 94 | } | ||||||||||||||||||||
| 95 | |||||||||||||||||||||
| 96 | 0 | ▶ | my $sql = "SELECT | ||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||
| 97 | content.path content_path, | ||||||||||||||||||||
| 98 | file.cpanid author, | ||||||||||||||||||||
| 99 | file.name release | ||||||||||||||||||||
| 100 | FROM content | ||||||||||||||||||||
| 101 | LEFT JOIN file ON content.file_id=file.id | ||||||||||||||||||||
| 102 | ".(@join ? join(" ", @join) : "")." | ||||||||||||||||||||
| 103 | ".(@where ? " WHERE ".join(" AND ", @where) : "")." | ||||||||||||||||||||
| 104 | ORDER BY content.path"; | ||||||||||||||||||||
| 105 | 0 | my $sth = $dbh->prepare($sql); | |||||||||||||||||||
| 106 | 0 | $sth->execute(@bind); | |||||||||||||||||||
| 107 | |||||||||||||||||||||
| 108 | 0 | my $first_row; | |||||||||||||||||||
| 109 | 0 | ▶ | while (my $row = $sth->fetchrow_hashref) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 110 | 0 | ▶ | $first_row //= $row; | ||||||||||||||||||
|
Condition0%0/3
$first_row //= $row
MC/DC0%0/2
$first_row //= $row
$first_row
$row
Truth table0%0/3
A //= B
A= $first_rowB= $row
| |||||||||||||||||||||
| 111 | 0 | ▶ | next unless $row->{content_path} =~ m!\A | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 112 | (?:[^/]+/)? | ||||||||||||||||||||
| 113 | (changes|changelog) | ||||||||||||||||||||
| 114 | (?:\.(\w+))?\z!ix; | ||||||||||||||||||||
| 115 | # XXX handle YAML file | ||||||||||||||||||||
| 116 | my $path = App::lcpan::_fullpath( | ||||||||||||||||||||
| 117 | 0 | $row->{release}, $state->{cpan}, $row->{author}); | |||||||||||||||||||
| 118 | |||||||||||||||||||||
| 119 | # XXX needs to be refactored into common code (see also doc subcommand) | ||||||||||||||||||||
| 120 | 0 | my $content; | |||||||||||||||||||
| 121 | 0 | ▶ | if ($path =~ /\.zip$/i) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 122 | 0 | require Archive::Zip; | |||||||||||||||||||
| 123 | 0 | my $zip = Archive::Zip->new; | |||||||||||||||||||
| 124 | 0 | ▶ | $zip->read($path) == Archive::Zip::AZ_OK() | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 125 | or return [500, "Can't read zip file '$path'"]; | ||||||||||||||||||||
| 126 | 0 | $content = $zip->contents($row->{content_path}); | |||||||||||||||||||
| 127 | } else { | ||||||||||||||||||||
| 128 | 0 | require Archive::Tar; | |||||||||||||||||||
| 129 | 0 | my $tar; | |||||||||||||||||||
| 130 | 0 | eval { | |||||||||||||||||||
| 131 | 0 | $tar = Archive::Tar->new; | |||||||||||||||||||
| 132 | 0 | $content = $tar->read($path); # can still die untrapped when out of mem | |||||||||||||||||||
| 133 | }; | ||||||||||||||||||||
| 134 | 0 | ▶ | return [500, "Can't read tar file '$path': $@"] if $@; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 135 | 0 | my ($obj) = $tar->get_files($row->{content_path}); | |||||||||||||||||||
| 136 | 0 | $content = $obj->get_content; | |||||||||||||||||||
| 137 | } | ||||||||||||||||||||
| 138 | |||||||||||||||||||||
| 139 | return [200, "OK", $content, { | ||||||||||||||||||||
| 140 | 'func.content_path' => $row->{content_path}, | ||||||||||||||||||||
| 141 | 0 | 'cmdline.skip_format'=>1, | |||||||||||||||||||
| 142 | "cmdline.page_result"=>1, | ||||||||||||||||||||
| 143 | }]; | ||||||||||||||||||||
| 144 | } | ||||||||||||||||||||
| 145 | |||||||||||||||||||||
| 146 | 0 | ▶ | if ($first_row) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 147 | 0 | return [404, "No Changes file found in $first_row->{release}"]; | |||||||||||||||||||
| 148 | } else { | ||||||||||||||||||||
| 149 | 0 | return [404, "No such module or dist"]; | |||||||||||||||||||
| 150 | } | ||||||||||||||||||||
| 151 | } | ||||||||||||||||||||
| 152 | |||||||||||||||||||||
| 153 | 1 | 1; | |||||||||||||||||||
| 154 | # ABSTRACT: Show Changes of distribution/module | ||||||||||||||||||||
| 155 | |||||||||||||||||||||
| 156 | __END__ | ||||||||||||||||||||