| 1 | ## no critic: ControlStructures::ProhibitUnreachableCode | ||||||||||
| 2 | |||||||||||
| 3 | package App::lcpan::Cmd::whatsnew; | ||||||||||
| 4 | |||||||||||
| 5 | 1 | ▶ | use 5.010001; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | 1 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | 1 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 8 | 1 | ▶ | use Log::ger; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 9 | |||||||||||
| 10 | 1 | require App::lcpan; | |||||||||
| 11 | 1 | ▶ | use Hash::Subset 'hash_subset'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 12 | |||||||||||
| 13 | 1 | our $AUTHORITY = 'cpan:PERLANCAR'; # AUTHORITY | |||||||||
| 14 | 1 | our $DATE = '2023-09-26'; # DATE | |||||||||
| 15 | 1 | our $DIST = 'App-lcpan'; # DIST | |||||||||
| 16 | 1 | our $VERSION = '1.074'; # VERSION | |||||||||
| 17 | |||||||||||
| 18 | 1 | our %SPEC; | |||||||||
| 19 | |||||||||||
| 20 | 1 | $SPEC{'handle_cmd'} = { | |||||||||
| 21 | v => 1.1, | ||||||||||
| 22 | summary => "Show what's added/updated recently", | ||||||||||
| 23 | args => { | ||||||||||
| 24 | %App::lcpan::common_args, | ||||||||||
| 25 | %App::lcpan::fctime_or_mtime_args, | ||||||||||
| 26 | my_author => { | ||||||||||
| 27 | summary => 'My author ID', | ||||||||||
| 28 | description => <<'_', | ||||||||||
| 29 | |||||||||||
| 30 | If specified, will show additional added/updated items for this author ID | ||||||||||
| 31 | ("you"), e.g. what distributions recently added dependency to one of your | ||||||||||
| 32 | modules. | ||||||||||
| 33 | |||||||||||
| 34 | _ | ||||||||||
| 35 | schema => 'str*', | ||||||||||
| 36 | cmdline_aliases => {a=>{}}, | ||||||||||
| 37 | completion => \&App::lcpan::_complete_cpanid, | ||||||||||
| 38 | }, | ||||||||||
| 39 | }, | ||||||||||
| 40 | }; | ||||||||||
| 41 | 0 | ▶ | sub handle_cmd { | ||||||||
|
Subroutine
handle_cmd: not called CC=12 SCAR=50.5
Pod
documented
| |||||||||||
| 42 | 0 | require Perinci::Result::Format::Lite; | |||||||||
| 43 | 0 | require Text::Table::Org; # just to let scan-prereqs know | |||||||||
| 44 | |||||||||||
| 45 | 0 | my %args = @_; | |||||||||
| 46 | 0 | my $my_author = $args{my_author}; | |||||||||
| 47 | |||||||||||
| 48 | 0 | my $state = App::lcpan::_init(\%args, 'ro'); | |||||||||
| 49 | 0 | my $dbh = $state->{dbh}; | |||||||||
| 50 | |||||||||||
| 51 | 0 | ▶ | $args{added_or_updated_since_last_index_update} = 1 if !(grep {exists $App::lcpan::fctime_or_mtime_args{$_}} keys %args); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 52 | 0 | App::lcpan::_set_since(\%args, $dbh); | |||||||||
| 53 | |||||||||||
| 54 | 0 | my $time = delete($args{added_or_updated_since}); | |||||||||
| 55 | 0 | my $ftime = scalar(gmtime $time) . " UTC"; | |||||||||
| 56 | |||||||||||
| 57 | 0 | my $org = ''; | |||||||||
| 58 | |||||||||||
| 59 | 0 | local $ENV{FORMAT_PRETTY_TABLE_BACKEND} = 'Text::Table::Org'; | |||||||||
| 60 | |||||||||||
| 61 | #$org .= "#+INFOJS_OPT: view:info toc:nil\n"; | ||||||||||
| 62 | 0 | $org .= "WHAT'S NEW SINCE $ftime\n\n"; | |||||||||
| 63 | |||||||||||
| 64 | NEW_MODULES: { | ||||||||||
| 65 | 0 | my ($res, $fres); | |||||||||
| 66 | 0 | $res = App::lcpan::modules(added_since=>$time, detail=>1); | |||||||||
| 67 | 0 | ▶ | unless ($res->[0] == 200) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 68 | 0 | $org .= "Can't list new modules: $res->[0] - $res->[1]\n\n"; | |||||||||
| 69 | 0 | last; | |||||||||
| 70 | } | ||||||||||
| 71 | 0 | my $num = @{ $res->[2] }; | |||||||||
| 72 | 0 | $org .= "* New modules ($num)\n"; | |||||||||
| 73 | 0 | $fres = Perinci::Result::Format::Lite::format( | |||||||||
| 74 | $res, 'text-pretty', 0, 0); | ||||||||||
| 75 | 0 | $org .= $fres; | |||||||||
| 76 | 0 | $org .= "\n"; | |||||||||
| 77 | } | ||||||||||
| 78 | |||||||||||
| 79 | UPDATED_MODULES: { | ||||||||||
| 80 | 0 | my ($res, $fres); | |||||||||
| 81 | 0 | $res = App::lcpan::modules(updated_since=>$time, detail=>1); | |||||||||
| 82 | 0 | ▶ | unless ($res->[0] == 200) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 83 | 0 | $org .= "Can't list updated modules: $res->[0] - $res->[1]\n\n"; | |||||||||
| 84 | 0 | last; | |||||||||
| 85 | } | ||||||||||
| 86 | 0 | my $num = @{ $res->[2] }; | |||||||||
| 87 | 0 | $org .= "* Updated modules ($num)\n"; | |||||||||
| 88 | 0 | $fres = Perinci::Result::Format::Lite::format( | |||||||||
| 89 | $res, 'text-pretty', 0, 0); | ||||||||||
| 90 | 0 | $org .= $fres; | |||||||||
| 91 | 0 | $org .= "\n"; | |||||||||
| 92 | } | ||||||||||
| 93 | |||||||||||
| 94 | NEW_AUTHORS: { | ||||||||||
| 95 | 0 | my ($res, $fres); | |||||||||
| 96 | 0 | $res = App::lcpan::authors(added_since=>$time, detail=>1); | |||||||||
| 97 | 0 | ▶ | unless ($res->[0] == 200) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 98 | 0 | $org .= "Can't list new authors: $res->[0] - $res->[1]\n\n"; | |||||||||
| 99 | 0 | last; | |||||||||
| 100 | } | ||||||||||
| 101 | 0 | my $num = @{ $res->[2] }; | |||||||||
| 102 | 0 | $org .= "* New authors ($num)\n"; | |||||||||
| 103 | 0 | $fres = Perinci::Result::Format::Lite::format( | |||||||||
| 104 | $res, 'text-pretty', 0, 0); | ||||||||||
| 105 | 0 | $org .= $fres; | |||||||||
| 106 | 0 | $org .= "\n"; | |||||||||
| 107 | } | ||||||||||
| 108 | |||||||||||
| 109 | UPDATED_AUTHORS: { | ||||||||||
| 110 | 0 | my ($res, $fres); | |||||||||
| 111 | 0 | $res = App::lcpan::authors(updated_since=>$time, detail=>1); | |||||||||
| 112 | 0 | ▶ | unless ($res->[0] == 200) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 113 | 0 | $org .= "Can't list updated authors: $res->[0] - $res->[1]\n\n"; | |||||||||
| 114 | 0 | last; | |||||||||
| 115 | } | ||||||||||
| 116 | 0 | my $num = @{ $res->[2] }; | |||||||||
| 117 | 0 | $org .= "* Updated authors ($num)\n"; | |||||||||
| 118 | 0 | $fres = Perinci::Result::Format::Lite::format( | |||||||||
| 119 | $res, 'text-pretty', 0, 0); | ||||||||||
| 120 | 0 | $org .= $fres; | |||||||||
| 121 | 0 | $org .= "\n"; | |||||||||
| 122 | } | ||||||||||
| 123 | |||||||||||
| 124 | NEW_REVERSE_DEPENDENCIES: { | ||||||||||
| 125 | 0 | ▶ | last unless defined $my_author; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 126 | 0 | my ($res, $fres); | |||||||||
| 127 | 0 | require App::lcpan::Cmd::author_rdeps; | |||||||||
| 128 | 0 | $res = App::lcpan::Cmd::author_rdeps::handle_cmd( | |||||||||
| 129 | author=>$my_author, user_authors_arent=>[$my_author], | ||||||||||
| 130 | added_since=>$time, | ||||||||||
| 131 | phase => 'ALL', | ||||||||||
| 132 | rel => 'ALL', | ||||||||||
| 133 | ); | ||||||||||
| 134 | 0 | ▶ | unless ($res->[0] == 200) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 135 | 0 | $org .= "Can't list new reverse dependencies for modules of $my_author: $res->[0] - $res->[1]\n\n"; | |||||||||
| 136 | 0 | last; | |||||||||
| 137 | } | ||||||||||
| 138 | 0 | my $num = @{ $res->[2] }; | |||||||||
| 139 | 0 | $org .= "* Distributions of other authors recently depending on one of $my_author\'s modules ($num)\n"; | |||||||||
| 140 | 0 | $fres = Perinci::Result::Format::Lite::format( | |||||||||
| 141 | $res, 'text-pretty', 0, 0); | ||||||||||
| 142 | 0 | $org .= $fres; | |||||||||
| 143 | 0 | $org .= "\n"; | |||||||||
| 144 | } | ||||||||||
| 145 | |||||||||||
| 146 | UPDATED_REVERSE_DEPENDENCIES: { | ||||||||||
| 147 | # skip for now, usually empty. because dep records are usually not | ||||||||||
| 148 | # updated but recreated. | ||||||||||
| 149 | 0 | last; | |||||||||
| 150 | |||||||||||
| 151 | 0 | ▶ | last unless defined $my_author; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 152 | 0 | my ($res, $fres); | |||||||||
| 153 | 0 | require App::lcpan::Cmd::author_rdeps; | |||||||||
| 154 | 0 | $res = App::lcpan::Cmd::author_rdeps::handle_cmd( | |||||||||
| 155 | author=>$my_author, user_authors_arent=>[$my_author], updated_since=>$time, | ||||||||||
| 156 | phase => 'ALL', | ||||||||||
| 157 | rel => 'ALL', | ||||||||||
| 158 | ); | ||||||||||
| 159 | 0 | ▶ | unless ($res->[0] == 200) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 160 | 0 | $org .= "Can't list updated reverse dependencies for modules of $my_author: $res->[0] - $res->[1]\n\n"; | |||||||||
| 161 | 0 | last; | |||||||||
| 162 | } | ||||||||||
| 163 | 0 | my $num = @{ $res->[2] }; | |||||||||
| 164 | 0 | $org .= "* Distributions of other authors which updated dependencies to one of $my_author\'s modules ($num)\n"; | |||||||||
| 165 | 0 | $fres = Perinci::Result::Format::Lite::format( | |||||||||
| 166 | $res, 'text-pretty', 0, 0); | ||||||||||
| 167 | 0 | $org .= $fres; | |||||||||
| 168 | 0 | $org .= "\n"; | |||||||||
| 169 | } | ||||||||||
| 170 | |||||||||||
| 171 | NEW_MENTIONS: { | ||||||||||
| 172 | 0 | ▶ | last unless defined $my_author; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 173 | 0 | my ($res, $fres); | |||||||||
| 174 | 0 | require App::lcpan::Cmd::mentions; | |||||||||
| 175 | 0 | $res = App::lcpan::Cmd::mentions::handle_cmd( | |||||||||
| 176 | mentioned_authors=>[$my_author], mentioner_authors_arent=>[$my_author], added_since=>$time, | ||||||||||
| 177 | ); | ||||||||||
| 178 | 0 | ▶ | unless ($res->[0] == 200) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 179 | 0 | $org .= "Can't list updated reverse dependencies for modules of $my_author: $res->[0] - $res->[1]\n\n"; | |||||||||
| 180 | 0 | last; | |||||||||
| 181 | } | ||||||||||
| 182 | 0 | my $num = @{ $res->[2] }; | |||||||||
| 183 | 0 | $org .= "* New mentions to one of $my_author\'s modules ($num)\n"; | |||||||||
| 184 | 0 | $fres = Perinci::Result::Format::Lite::format( | |||||||||
| 185 | $res, 'text-pretty', 0, 0); | ||||||||||
| 186 | 0 | $org .= $fres; | |||||||||
| 187 | 0 | $org .= "\n"; | |||||||||
| 188 | } | ||||||||||
| 189 | |||||||||||
| 190 | 0 | [200, "OK", $org, {'content_type' => 'text/x-org'}]; | |||||||||
| 191 | } | ||||||||||
| 192 | |||||||||||
| 193 | 1 | 1; | |||||||||
| 194 | # ABSTRACT: Show what's added/updated recently | ||||||||||
| 195 | |||||||||||
| 196 | __END__ | ||||||||||