| 1 | package App::swcat; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 1 | our $AUTHORITY = 'cpan:PERLANCAR'; # AUTHORITY | |||||||||||||||||||||||||||
| 4 | 1 | our $DATE = '2021-04-04'; # DATE | |||||||||||||||||||||||||||
| 5 | 1 | our $DIST = 'App-swcat'; # DIST | |||||||||||||||||||||||||||
| 6 | 1 | our $VERSION = '0.015'; # VERSION | |||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | 1 | ▶ | use 5.010001; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | 1 | ▶ | use strict 'subs', 'vars'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | 1 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | 1 | ▶ | use Log::ger; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | 1 | ▶ | use Perinci::Object; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 14 | 1 | ▶ | use PerlX::Maybe; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||
| 16 | 1 | ▶ | use vars '%Config'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 17 | 1 | our %SPEC; | |||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | 1 | our $db_schema_spec = { | |||||||||||||||||||||||||||
| 20 | latest_v => 2, | ||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||
| 22 | install => [ | ||||||||||||||||||||||||||||
| 23 | 'CREATE TABLE sw_cache ( | ||||||||||||||||||||||||||||
| 24 | software VARCHAR(128) NOT NULL, | ||||||||||||||||||||||||||||
| 25 | name VARCHAR(64) NOT NULL, | ||||||||||||||||||||||||||||
| 26 | value TEXT NOT NULL, | ||||||||||||||||||||||||||||
| 27 | mtime INT NOT NULL | ||||||||||||||||||||||||||||
| 28 | )', | ||||||||||||||||||||||||||||
| 29 | 'CREATE UNIQUE INDEX ix_sw_cache__software_name ON sw_cache(software,name)', | ||||||||||||||||||||||||||||
| 30 | ], # install | ||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||
| 32 | upgrade_to_v2 => [ | ||||||||||||||||||||||||||||
| 33 | 'DROP TABLE sw_cache', # remove all cache | ||||||||||||||||||||||||||||
| 34 | 'CREATE TABLE sw_cache ( | ||||||||||||||||||||||||||||
| 35 | software VARCHAR(128) NOT NULL, | ||||||||||||||||||||||||||||
| 36 | name VARCHAR(64) NOT NULL, | ||||||||||||||||||||||||||||
| 37 | value TEXT NOT NULL, | ||||||||||||||||||||||||||||
| 38 | mtime INT NOT NULL | ||||||||||||||||||||||||||||
| 39 | )', | ||||||||||||||||||||||||||||
| 40 | 'CREATE UNIQUE INDEX ix_sw_cache__software_name ON sw_cache(software,name)', | ||||||||||||||||||||||||||||
| 41 | ], | ||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||
| 43 | install_v1 => [ | ||||||||||||||||||||||||||||
| 44 | 'CREATE TABLE sw_cache ( | ||||||||||||||||||||||||||||
| 45 | software VARCHAR(128) NOT NULL PRIMARY KEY, | ||||||||||||||||||||||||||||
| 46 | latest_version VARCHAR(32), | ||||||||||||||||||||||||||||
| 47 | check_latest_version_mtime INT | ||||||||||||||||||||||||||||
| 48 | )', | ||||||||||||||||||||||||||||
| 49 | ], # install | ||||||||||||||||||||||||||||
| 50 | }; # db_schema_spec | ||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||
| 52 | 1 | our $re_software = qr/\A[A-Za-z0-9_]+(?:-[A-Za-z0-9_]+)*\z/; | |||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||
| 54 | our %args_common0 = ( | ||||||||||||||||||||||||||||
| 55 | db_path => { | ||||||||||||||||||||||||||||
| 56 | summary => 'Location of SQLite database (for caching), '. | ||||||||||||||||||||||||||||
| 57 | 'defaults to ~/.cache/swcat.db', | ||||||||||||||||||||||||||||
| 58 | schema => 'filename*', | ||||||||||||||||||||||||||||
| 59 | tags => ['common'], | ||||||||||||||||||||||||||||
| 60 | }, | ||||||||||||||||||||||||||||
| 61 | cache_period => { | ||||||||||||||||||||||||||||
| 62 | schema => 'int*', | ||||||||||||||||||||||||||||
| 63 | tags => ['common'], | ||||||||||||||||||||||||||||
| 64 | cmdline_aliases => { | ||||||||||||||||||||||||||||
| 65 | 0 | ▶ | no_cache => {summary => 'Alias for --cache-period=-1', is_flag=>1, code=>sub { $_[0]{cache_period} = -1 }}, | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 66 | }, | ||||||||||||||||||||||||||||
| 67 | }, | ||||||||||||||||||||||||||||
| 68 | 1 | ); | |||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||
| 70 | 1 | our %args_common = ( | |||||||||||||||||||||||||||
| 71 | %args_common0, | ||||||||||||||||||||||||||||
| 72 | arch => { | ||||||||||||||||||||||||||||
| 73 | schema => 'software::arch*', | ||||||||||||||||||||||||||||
| 74 | tags => ['common'], | ||||||||||||||||||||||||||||
| 75 | }, | ||||||||||||||||||||||||||||
| 76 | ); | ||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||
| 78 | our %arg0_software = ( | ||||||||||||||||||||||||||||
| 79 | software => { | ||||||||||||||||||||||||||||
| 80 | schema => ['str*', match=>$re_software], | ||||||||||||||||||||||||||||
| 81 | req => 1, | ||||||||||||||||||||||||||||
| 82 | pos => 0, | ||||||||||||||||||||||||||||
| 83 | 0 | ▶ | completion => sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 84 | 0 | require Complete::Module; | |||||||||||||||||||||||||||
| 85 | 0 | my %args = @_; | |||||||||||||||||||||||||||
| 86 | Complete::Module::complete_module( | ||||||||||||||||||||||||||||
| 87 | word => $args{word}, | ||||||||||||||||||||||||||||
| 88 | 0 | ns_prefix => 'Software::Catalog::SW', | |||||||||||||||||||||||||||
| 89 | path_sep => '-', | ||||||||||||||||||||||||||||
| 90 | ); | ||||||||||||||||||||||||||||
| 91 | }, | ||||||||||||||||||||||||||||
| 92 | }, | ||||||||||||||||||||||||||||
| 93 | 1 | ); | |||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||
| 95 | 1 | our %argopt1_version = ( | |||||||||||||||||||||||||||
| 96 | version => { | ||||||||||||||||||||||||||||
| 97 | schema => ['str*'], | ||||||||||||||||||||||||||||
| 98 | pos => 1, | ||||||||||||||||||||||||||||
| 99 | }, | ||||||||||||||||||||||||||||
| 100 | ); | ||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||
| 102 | our %argopt0_softwares_or_patterns = ( | ||||||||||||||||||||||||||||
| 103 | softwares_or_patterns => { | ||||||||||||||||||||||||||||
| 104 | 'x.name.is_plural' => 1, | ||||||||||||||||||||||||||||
| 105 | 'x.name.singular' => 'software_or_pattern', | ||||||||||||||||||||||||||||
| 106 | schema => ['array*', of=>['str*', min_len=>1], min_len=>1], | ||||||||||||||||||||||||||||
| 107 | pos => 0, | ||||||||||||||||||||||||||||
| 108 | greedy => 1, | ||||||||||||||||||||||||||||
| 109 | 0 | ▶ | element_completion => sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 110 | 0 | require Complete::Module; | |||||||||||||||||||||||||||
| 111 | 0 | my %args = @_; | |||||||||||||||||||||||||||
| 112 | Complete::Module::complete_module( | ||||||||||||||||||||||||||||
| 113 | word => $args{word}, | ||||||||||||||||||||||||||||
| 114 | 0 | ns_prefix => 'Software::Catalog::SW', | |||||||||||||||||||||||||||
| 115 | path_sep => '-', | ||||||||||||||||||||||||||||
| 116 | ); | ||||||||||||||||||||||||||||
| 117 | }, | ||||||||||||||||||||||||||||
| 118 | }, | ||||||||||||||||||||||||||||
| 119 | 1 | ); | |||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||
| 121 | 1 | our %arg0_softwares_or_patterns; | |||||||||||||||||||||||||||
| 122 | $arg0_softwares_or_patterns{softwares_or_patterns} = { | ||||||||||||||||||||||||||||
| 123 | 1 | %{$argopt0_softwares_or_patterns{softwares_or_patterns}}, | |||||||||||||||||||||||||||
| 124 | req => 1, | ||||||||||||||||||||||||||||
| 125 | }; | ||||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||
| 127 | 1 | our %argopt_arch = ( | |||||||||||||||||||||||||||
| 128 | arch => { | ||||||||||||||||||||||||||||
| 129 | schema => ['software::arch*'], | ||||||||||||||||||||||||||||
| 130 | }, | ||||||||||||||||||||||||||||
| 131 | ); | ||||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||
| 133 | 0 | ▶ | sub _load_swcat_mod { | ||||||||||||||||||||||||||
|
Subroutine
_load_swcat_mod: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 134 | 0 | my $name = shift; | |||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||
| 136 | 0 | (my $mod = "Software::Catalog::SW::$name") =~ s/-/::/g; | |||||||||||||||||||||||||||
| 137 | 0 | (my $modpm = "$mod.pm") =~ s!::!/!g; | |||||||||||||||||||||||||||
| 138 | 0 | require $modpm; | |||||||||||||||||||||||||||
| 139 | 0 | $mod; | |||||||||||||||||||||||||||
| 140 | } | ||||||||||||||||||||||||||||
| 141 | |||||||||||||||||||||||||||||
| 142 | 0 | ▶ | sub _create_schema { | ||||||||||||||||||||||||||
|
Subroutine
_create_schema: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||
| 143 | 0 | require SQL::Schema::Versioned; | |||||||||||||||||||||||||||
| 144 | |||||||||||||||||||||||||||||
| 145 | 0 | my $dbh = shift; | |||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||
| 147 | 0 | my $res = SQL::Schema::Versioned::create_or_update_db_schema( | |||||||||||||||||||||||||||
| 148 | dbh => $dbh, spec => $db_schema_spec); | ||||||||||||||||||||||||||||
| 149 | 0 | ▶ | die "Can't create/update schema: $res->[0] - $res->[1]\n" | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 150 | unless $res->[0] == 200; | ||||||||||||||||||||||||||||
| 151 | } | ||||||||||||||||||||||||||||
| 152 | |||||||||||||||||||||||||||||
| 153 | 0 | ▶ | sub _connect_db { | ||||||||||||||||||||||||||
|
Subroutine
_connect_db: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||
| 154 | 0 | require DBI; | |||||||||||||||||||||||||||
| 155 | |||||||||||||||||||||||||||||
| 156 | 0 | my ($mode, $path) = @_; | |||||||||||||||||||||||||||
| 157 | |||||||||||||||||||||||||||||
| 158 | 0 | log_trace("Connecting to SQLite database at %s ...", $path); | |||||||||||||||||||||||||||
| 159 | 0 | ▶ | if ($mode eq 'ro') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 160 | # avoid creating the index file automatically if we are only in | ||||||||||||||||||||||||||||
| 161 | # read-only mode | ||||||||||||||||||||||||||||
| 162 | 0 | ▶ | die "Can't find index '$path'\n" unless -f $path; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 163 | } | ||||||||||||||||||||||||||||
| 164 | 0 | my $dbh = DBI->connect("dbi:SQLite:dbname=$path", undef, undef, | |||||||||||||||||||||||||||
| 165 | {RaiseError=>1}); | ||||||||||||||||||||||||||||
| 166 | #$dbh->do("PRAGMA cache_size = 400000"); # 400M | ||||||||||||||||||||||||||||
| 167 | 0 | _create_schema($dbh); | |||||||||||||||||||||||||||
| 168 | 0 | $dbh; | |||||||||||||||||||||||||||
| 169 | } | ||||||||||||||||||||||||||||
| 170 | |||||||||||||||||||||||||||||
| 171 | 0 | ▶ | sub _set_args_default { | ||||||||||||||||||||||||||
|
Subroutine
_set_args_default: not called CC=4 SCAR=30.0
| |||||||||||||||||||||||||||||
| 172 | 0 | my $args = shift; | |||||||||||||||||||||||||||
| 173 | 0 | ▶ | if (!$args->{db_path}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 174 | 0 | require PERLANCAR::File::HomeDir; | |||||||||||||||||||||||||||
| 175 | 0 | $args->{db_path} = PERLANCAR::File::HomeDir::get_my_home_dir() . | |||||||||||||||||||||||||||
| 176 | '/.cache/swcat.db'; | ||||||||||||||||||||||||||||
| 177 | } | ||||||||||||||||||||||||||||
| 178 | 0 | ▶ | if (!$args->{arch}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 179 | 0 | require Software::Catalog::Util; | |||||||||||||||||||||||||||
| 180 | 0 | $args->{arch} = Software::Catalog::Util::detect_arch(); | |||||||||||||||||||||||||||
| 181 | } | ||||||||||||||||||||||||||||
| 182 | 0 | ▶ | if (!defined $args->{cache_period}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 183 | 0 | $args->{cache_period} = 86400; | |||||||||||||||||||||||||||
| 184 | } | ||||||||||||||||||||||||||||
| 185 | } | ||||||||||||||||||||||||||||
| 186 | |||||||||||||||||||||||||||||
| 187 | 0 | ▶ | sub _init { | ||||||||||||||||||||||||||
|
Subroutine
_init: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||
| 188 | 0 | my ($args, $mode) = @_; | |||||||||||||||||||||||||||
| 189 | |||||||||||||||||||||||||||||
| 190 | 0 | _set_args_default($args); | |||||||||||||||||||||||||||
| 191 | 0 | ▶ | unless ($App::swcat::state) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 192 | my $state = { | ||||||||||||||||||||||||||||
| 193 | dbh => _connect_db($mode, $args->{db_path}), | ||||||||||||||||||||||||||||
| 194 | db_path => $args->{db_path}, | ||||||||||||||||||||||||||||
| 195 | 0 | }; | |||||||||||||||||||||||||||
| 196 | 0 | $App::swcat::state = $state; | |||||||||||||||||||||||||||
| 197 | } | ||||||||||||||||||||||||||||
| 198 | 0 | $App::swcat::state; | |||||||||||||||||||||||||||
| 199 | } | ||||||||||||||||||||||||||||
| 200 | |||||||||||||||||||||||||||||
| 201 | 0 | ▶ | sub _cache_result { | ||||||||||||||||||||||||||
|
Subroutine
_cache_result: not called CC=6 SCAR=37.4
| |||||||||||||||||||||||||||||
| 202 | 0 | my %args = @_; | |||||||||||||||||||||||||||
| 203 | |||||||||||||||||||||||||||||
| 204 | 0 | my $now = time(); | |||||||||||||||||||||||||||
| 205 | |||||||||||||||||||||||||||||
| 206 | 0 | my $res; | |||||||||||||||||||||||||||
| 207 | RETRIEVE: { | ||||||||||||||||||||||||||||
| 208 | 0 | my $cache_exists; | |||||||||||||||||||||||||||
| 209 | 0 | log_trace "Getting value from cache (table=%s, column=%s, pk=%s) ...", $args{table}, $args{column}, $args{pk}; | |||||||||||||||||||||||||||
| 210 | |||||||||||||||||||||||||||||
| 211 | 0 | my $sqlwhere; | |||||||||||||||||||||||||||
| 212 | my $sqlcolumns; | ||||||||||||||||||||||||||||
| 213 | 0 | my $sqlbinds; | |||||||||||||||||||||||||||
| 214 | 0 | my @bind; | |||||||||||||||||||||||||||
| 215 | 0 | ▶ | if (ref $args{pk_column} eq 'ARRAY') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 216 | 0 | $sqlwhere = join(" AND ", map {"$_=?"} @{ $args{pk_column} }); | |||||||||||||||||||||||||||
| 217 | 0 | $sqlcolumns = join(",", @{ $args{pk_column} }); | |||||||||||||||||||||||||||
| 218 | 0 | $sqlbinds = join(",", map {"?"} @{ $args{pk_column} }); | |||||||||||||||||||||||||||
| 219 | 0 | push @bind, @{ $args{pk} }; | |||||||||||||||||||||||||||
| 220 | } else { | ||||||||||||||||||||||||||||
| 221 | 0 | $sqlwhere = "$args{pk_column}=?"; | |||||||||||||||||||||||||||
| 222 | 0 | $sqlcolumns = $args{pk_column}; | |||||||||||||||||||||||||||
| 223 | 0 | $sqlbinds = "?"; | |||||||||||||||||||||||||||
| 224 | 0 | push @bind, $args{pk}; | |||||||||||||||||||||||||||
| 225 | } | ||||||||||||||||||||||||||||
| 226 | |||||||||||||||||||||||||||||
| 227 | 0 | my @row = $args{dbh}->selectrow_array("SELECT $args{column}, $args{mtime_column} FROM $args{table} WHERE $sqlwhere", {}, @bind); | |||||||||||||||||||||||||||
| 228 | #log_trace "row=%s, now=%s, cache_period=%s", \@row, $now, $args{cache_period}; | ||||||||||||||||||||||||||||
| 229 | 0 | ▶ | if (!@row) { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 230 | 0 | log_trace "Cache doesn't exist yet"; | |||||||||||||||||||||||||||
| 231 | } elsif ($row[1] < $now - $args{cache_period}) { | ||||||||||||||||||||||||||||
| 232 | 0 | $cache_exists++; | |||||||||||||||||||||||||||
| 233 | 0 | log_trace "Cache is too old, retrieving from source again"; | |||||||||||||||||||||||||||
| 234 | } else { | ||||||||||||||||||||||||||||
| 235 | 0 | log_trace "Cache hit ($row[0])"; | |||||||||||||||||||||||||||
| 236 | 0 | $res = [200, "OK (cached)", $row[0]]; | |||||||||||||||||||||||||||
| 237 | 0 | last; | |||||||||||||||||||||||||||
| 238 | } | ||||||||||||||||||||||||||||
| 239 | 0 | $res = $args{code}->(); | |||||||||||||||||||||||||||
| 240 | 0 | ▶ | if ($res->[0] == 200) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 241 | 0 | log_trace "Updating cache ..."; | |||||||||||||||||||||||||||
| 242 | 0 | ▶ | if ($cache_exists) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 243 | 0 | $args{dbh}->do("UPDATE $args{table} SET $args{column}=?, $args{mtime_column}=? WHERE $sqlwhere", {}, $res->[2], $now, @bind); | |||||||||||||||||||||||||||
| 244 | } else { | ||||||||||||||||||||||||||||
| 245 | 0 | $args{dbh}->do("INSERT INTO $args{table} ($sqlcolumns, $args{column}, $args{mtime_column}) VALUES ($sqlbinds, ?,?)", {}, @bind, $res->[2], $now); | |||||||||||||||||||||||||||
| 246 | } | ||||||||||||||||||||||||||||
| 247 | } | ||||||||||||||||||||||||||||
| 248 | } | ||||||||||||||||||||||||||||
| 249 | 0 | $res; | |||||||||||||||||||||||||||
| 250 | } | ||||||||||||||||||||||||||||
| 251 | |||||||||||||||||||||||||||||
| 252 | $SPEC{list_installed} = { | ||||||||||||||||||||||||||||
| 253 | 1 | v => 1.1, | |||||||||||||||||||||||||||
| 254 | summary => 'List known software in the catalog '. | ||||||||||||||||||||||||||||
| 255 | '(from installed Software::Catalog::SW::* modules)', | ||||||||||||||||||||||||||||
| 256 | args => { | ||||||||||||||||||||||||||||
| 257 | %args_common, | ||||||||||||||||||||||||||||
| 258 | detail => { | ||||||||||||||||||||||||||||
| 259 | schema => ['bool*', is=>1], | ||||||||||||||||||||||||||||
| 260 | cmdline_aliases => {l=>{}}, | ||||||||||||||||||||||||||||
| 261 | }, | ||||||||||||||||||||||||||||
| 262 | }, | ||||||||||||||||||||||||||||
| 263 | }; | ||||||||||||||||||||||||||||
| 264 | 0 | ▶ | sub list_installed { | ||||||||||||||||||||||||||
|
Subroutine
list_installed: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||
| 265 | 0 | require PERLANCAR::Module::List; | |||||||||||||||||||||||||||
| 266 | |||||||||||||||||||||||||||||
| 267 | 0 | my %args = @_; | |||||||||||||||||||||||||||
| 268 | |||||||||||||||||||||||||||||
| 269 | 0 | my $mods = PERLANCAR::Module::List::list_modules( | |||||||||||||||||||||||||||
| 270 | 'Software::Catalog::SW::', {list_modules => 1, recurse=>1}, | ||||||||||||||||||||||||||||
| 271 | ); | ||||||||||||||||||||||||||||
| 272 | 0 | my @rows; | |||||||||||||||||||||||||||
| 273 | 0 | for my $mod (sort keys %$mods) { | |||||||||||||||||||||||||||
| 274 | 0 | (my $name = $mod) =~ s/\ASoftware::Catalog::SW:://; | |||||||||||||||||||||||||||
| 275 | 0 | $name =~ s/::/-/g; | |||||||||||||||||||||||||||
| 276 | 0 | my $row; | |||||||||||||||||||||||||||
| 277 | 0 | ▶ | if ($args{detail}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 278 | 0 | my $mod = _load_swcat_mod($name); | |||||||||||||||||||||||||||
| 279 | 0 | $row = { | |||||||||||||||||||||||||||
| 280 | software => $name, | ||||||||||||||||||||||||||||
| 281 | module => $mod, | ||||||||||||||||||||||||||||
| 282 | }; | ||||||||||||||||||||||||||||
| 283 | } else { | ||||||||||||||||||||||||||||
| 284 | 0 | $row = $name; | |||||||||||||||||||||||||||
| 285 | } | ||||||||||||||||||||||||||||
| 286 | 0 | push @rows, $row; | |||||||||||||||||||||||||||
| 287 | } | ||||||||||||||||||||||||||||
| 288 | |||||||||||||||||||||||||||||
| 289 | 0 | [200, "OK", \@rows]; | |||||||||||||||||||||||||||
| 290 | } | ||||||||||||||||||||||||||||
| 291 | |||||||||||||||||||||||||||||
| 292 | # for backward compatibility | ||||||||||||||||||||||||||||
| 293 | 1 | $SPEC{list} = $SPEC{list_installed}; | |||||||||||||||||||||||||||
| 294 | 1 | *list = \&list_installed; | |||||||||||||||||||||||||||
| 295 | |||||||||||||||||||||||||||||
| 296 | $SPEC{list_cpan} = { | ||||||||||||||||||||||||||||
| 297 | 1 | v => 1.1, | |||||||||||||||||||||||||||
| 298 | summary => 'List available known software in the catalog '. | ||||||||||||||||||||||||||||
| 299 | '(from Software::Catalog::SW::* modules on CPAN)', | ||||||||||||||||||||||||||||
| 300 | args => { | ||||||||||||||||||||||||||||
| 301 | %args_common, | ||||||||||||||||||||||||||||
| 302 | detail => { | ||||||||||||||||||||||||||||
| 303 | schema => ['bool*', is=>1], | ||||||||||||||||||||||||||||
| 304 | cmdline_aliases => {l=>{}}, | ||||||||||||||||||||||||||||
| 305 | }, | ||||||||||||||||||||||||||||
| 306 | lcpan => { | ||||||||||||||||||||||||||||
| 307 | schema => 'bool*', | ||||||||||||||||||||||||||||
| 308 | }, | ||||||||||||||||||||||||||||
| 309 | }, | ||||||||||||||||||||||||||||
| 310 | }; | ||||||||||||||||||||||||||||
| 311 | 0 | ▶ | sub list_cpan { | ||||||||||||||||||||||||||
|
Subroutine
list_cpan: not called CC=12 SCAR=50.5
Pod
documented
| |||||||||||||||||||||||||||||
| 312 | 0 | my %args = @_; | |||||||||||||||||||||||||||
| 313 | |||||||||||||||||||||||||||||
| 314 | my @methods = $args{lcpan} ? | ||||||||||||||||||||||||||||
| 315 | 0 | ▶ | ('lcpan', 'metacpan') : ('metacpan', 'lcpan'); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 316 | |||||||||||||||||||||||||||||
| 317 | METHOD: | ||||||||||||||||||||||||||||
| 318 | 0 | for my $method (@methods) { | |||||||||||||||||||||||||||
| 319 | 0 | ▶ | if ($method eq 'lcpan') { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 320 | 0 | ▶ | unless (eval { require App::lcpan::Call; 1 }) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 321 | 0 | warn "App::lcpan::Call is not installed, skipped listing ". | |||||||||||||||||||||||||||
| 322 | "modules from local CPAN mirror\n"; | ||||||||||||||||||||||||||||
| 323 | 0 | next METHOD; | |||||||||||||||||||||||||||
| 324 | } | ||||||||||||||||||||||||||||
| 325 | 0 | my $res = App::lcpan::Call::call_lcpan_script( | |||||||||||||||||||||||||||
| 326 | argv => [qw/mods --namespace Software::Catalog::SW/], | ||||||||||||||||||||||||||||
| 327 | ); | ||||||||||||||||||||||||||||
| 328 | 0 | ▶ | return $res if $res->[0] != 200; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 329 | return [200, "OK", | ||||||||||||||||||||||||||||
| 330 | 0 | [map {my $w = $_; $w =~ s/\ASoftware::Catalog::SW:://; $w } | |||||||||||||||||||||||||||
| 331 | 0 | grep {/Software::Catalog::SW::/} sort @{$res->[2]}]]; | |||||||||||||||||||||||||||
| 332 | } elsif ($method eq 'metacpan') { | ||||||||||||||||||||||||||||
| 333 | 0 | ▶ | unless (eval { require MetaCPAN::Client; 1 }) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 334 | 0 | warn "MetaCPAN::Client is not installed, skipped listing ". | |||||||||||||||||||||||||||
| 335 | "modules from MetaCPAN\n"; | ||||||||||||||||||||||||||||
| 336 | 0 | next METHOD; | |||||||||||||||||||||||||||
| 337 | } | ||||||||||||||||||||||||||||
| 338 | 0 | my $mcpan = MetaCPAN::Client->new; | |||||||||||||||||||||||||||
| 339 | 0 | my $rs = $mcpan->module({ | |||||||||||||||||||||||||||
| 340 | 'module.name'=>'Software::Catalog::SW::*', | ||||||||||||||||||||||||||||
| 341 | }); | ||||||||||||||||||||||||||||
| 342 | 0 | my @res; | |||||||||||||||||||||||||||
| 343 | 0 | ▶ | while (my $row = $rs->next) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 344 | 0 | my $mod = $row->module->[0]{name}; | |||||||||||||||||||||||||||
| 345 | 0 | ▶ | say "D: mod=$mod" if $ENV{DEBUG}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 346 | 0 | $mod =~ s/\ASoftware::Catalog::SW:://; | |||||||||||||||||||||||||||
| 347 | 0 | ▶ | push @res, $mod unless grep {$mod eq $_} @res; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 348 | } | ||||||||||||||||||||||||||||
| 349 | 0 | ▶ | warn "Empty result from MetaCPAN\n" unless @res; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 350 | 0 | return [200, "OK", [sort(@res)]]; | |||||||||||||||||||||||||||
| 351 | } | ||||||||||||||||||||||||||||
| 352 | } | ||||||||||||||||||||||||||||
| 353 | 0 | return [412, "Can't find a way to list CPAN mirrors"]; | |||||||||||||||||||||||||||
| 354 | } | ||||||||||||||||||||||||||||
| 355 | |||||||||||||||||||||||||||||
| 356 | 0 | ▶ | sub _get_arg_softwares_or_patterns { | ||||||||||||||||||||||||||
|
Subroutine
_get_arg_softwares_or_patterns: not called CC=13 SCAR=52.0
| |||||||||||||||||||||||||||||
| 357 | 0 | my $args = shift; | |||||||||||||||||||||||||||
| 358 | |||||||||||||||||||||||||||||
| 359 | 0 | ▶ | my $sws = $args->{softwares_or_patterns} // []; | ||||||||||||||||||||||||||
|
Condition0%0/2
$args->{"softwares_or_patterns"} // []
MC/DC0%0/1
$args->{"softwares_or_patterns"} // []
$args->{"softwares_or_patterns"}
Truth table0%0/2
A
A= $args->{"softwares_or_patterns"}
| |||||||||||||||||||||||||||||
| 360 | 0 | my $is_single_software; | |||||||||||||||||||||||||||
| 361 | RESOLVE_PATTERN: | ||||||||||||||||||||||||||||
| 362 | { | ||||||||||||||||||||||||||||
| 363 | 0 | ▶ | if (@$sws && !(grep {$_ !~ $re_software} @$sws)) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
@$sws and not grep({not $_ =~ /$App::swcat::re_software/;} @$sws)
MC/DC0%0/2
@$sws and not grep({not $_ =~ /$App::swcat::re_software/;} @$sws)
@$sws
not grep({not $_ =~ /$App::swcat::re_software/;} @$sws)
Truth table0%0/3
A and not(B)
A= @$swsB= not grep({not $_ =~ /$App::swcat::re_software/;} @$sws)
| |||||||||||||||||||||||||||||
| 364 | # user specifies all software, no patterns. so we need not match | ||||||||||||||||||||||||||||
| 365 | # against list of known software | ||||||||||||||||||||||||||||
| 366 | 0 | ▶ | $is_single_software = 1 if @$sws == 1; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 367 | 0 | last; | |||||||||||||||||||||||||||
| 368 | } | ||||||||||||||||||||||||||||
| 369 | 0 | my $res = list(); | |||||||||||||||||||||||||||
| 370 | 0 | ▶ | die "Can't list known software: $res->[0] - $res->[1]" | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 371 | unless $res->[0] == 200; | ||||||||||||||||||||||||||||
| 372 | 0 | my $known = $res->[2]; | |||||||||||||||||||||||||||
| 373 | 0 | ▶ | if (!@$sws) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 374 | 0 | $sws = $known; | |||||||||||||||||||||||||||
| 375 | 0 | last; | |||||||||||||||||||||||||||
| 376 | } | ||||||||||||||||||||||||||||
| 377 | 0 | my $sws_pat_resolved = []; | |||||||||||||||||||||||||||
| 378 | 0 | for my $e (@$sws) { | |||||||||||||||||||||||||||
| 379 | 0 | ▶ | if ($e =~ $re_software) { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 380 | 0 | push @$sws_pat_resolved, $e; | |||||||||||||||||||||||||||
| 381 | } elsif ($e =~ m!\A/(.*)/\z!) { | ||||||||||||||||||||||||||||
| 382 | 0 | my $re = qr/$1/; | |||||||||||||||||||||||||||
| 383 | 0 | for my $sw (@$known) { | |||||||||||||||||||||||||||
| 384 | push @$sws_pat_resolved, $sw | ||||||||||||||||||||||||||||
| 385 | 0 | ▶ | if $sw =~ $re && !(grep {$sw eq $_} @$sws_pat_resolved); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$sw =~ /$re/ and not grep({$sw eq $_;} @$sws_pat_resolved)
MC/DC0%0/2
$sw =~ /$re/ and not grep({$sw eq $_;} @$sws_pat_resolved)
$sw =~ /$re/
not grep({$sw eq $_;} @$sws_pat_resolved)
Truth table0%0/3
A and not(B)
A= $sw =~ /$re/B= not grep({$sw eq $_;} @$sws_pat_resolved)
| |||||||||||||||||||||||||||||
| 386 | } | ||||||||||||||||||||||||||||
| 387 | } else { | ||||||||||||||||||||||||||||
| 388 | 0 | die "Invalid software name/pattern '$e'"; | |||||||||||||||||||||||||||
| 389 | } | ||||||||||||||||||||||||||||
| 390 | } | ||||||||||||||||||||||||||||
| 391 | 0 | $sws = $sws_pat_resolved; | |||||||||||||||||||||||||||
| 392 | } # RESOLVE_PATTERN | ||||||||||||||||||||||||||||
| 393 | 0 | ($sws, $is_single_software); | |||||||||||||||||||||||||||
| 394 | } | ||||||||||||||||||||||||||||
| 395 | |||||||||||||||||||||||||||||
| 396 | $SPEC{latest_version} = { | ||||||||||||||||||||||||||||
| 397 | 1 | v => 1.1, | |||||||||||||||||||||||||||
| 398 | summary => 'Get latest version of one or more software', | ||||||||||||||||||||||||||||
| 399 | description => <<'_', | ||||||||||||||||||||||||||||
| 400 | |||||||||||||||||||||||||||||
| 401 | Will return the version number in the payload if given a single software name. | ||||||||||||||||||||||||||||
| 402 | Will return an array of {software=>..., version=>...} in the payload if given | ||||||||||||||||||||||||||||
| 403 | multiple software names or one or more patterns. | ||||||||||||||||||||||||||||
| 404 | |||||||||||||||||||||||||||||
| 405 | _ | ||||||||||||||||||||||||||||
| 406 | args => { | ||||||||||||||||||||||||||||
| 407 | %args_common, | ||||||||||||||||||||||||||||
| 408 | %argopt0_softwares_or_patterns, | ||||||||||||||||||||||||||||
| 409 | }, | ||||||||||||||||||||||||||||
| 410 | }; | ||||||||||||||||||||||||||||
| 411 | 0 | ▶ | sub latest_version { | ||||||||||||||||||||||||||
|
Subroutine
latest_version: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||||||||||||||||
| 412 | 0 | my %args = @_; | |||||||||||||||||||||||||||
| 413 | 0 | my $state = _init(\%args, 'rw'); | |||||||||||||||||||||||||||
| 414 | |||||||||||||||||||||||||||||
| 415 | 0 | my ($sws, $is_single_software) = _get_arg_softwares_or_patterns(\%args); | |||||||||||||||||||||||||||
| 416 | #log_trace "sws=%s", $sws; | ||||||||||||||||||||||||||||
| 417 | |||||||||||||||||||||||||||||
| 418 | 0 | my $envres = envresmulti(); | |||||||||||||||||||||||||||
| 419 | 0 | my @rows; | |||||||||||||||||||||||||||
| 420 | 0 | for my $sw (@$sws) { | |||||||||||||||||||||||||||
| 421 | 0 | my $mod = _load_swcat_mod($sw); | |||||||||||||||||||||||||||
| 422 | my $res = _cache_result( | ||||||||||||||||||||||||||||
| 423 | 0 | ▶ | code => sub { $mod->latest_version(arch => $args{arch}) }, | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 424 | dbh => $state->{dbh}, | ||||||||||||||||||||||||||||
| 425 | cache_period => $args{cache_period}, | ||||||||||||||||||||||||||||
| 426 | 0 | table => 'sw_cache', | |||||||||||||||||||||||||||
| 427 | pk_column => ['software', 'name'], | ||||||||||||||||||||||||||||
| 428 | pk => [$sw, "latest_version.$args{arch}"], | ||||||||||||||||||||||||||||
| 429 | column => 'value', | ||||||||||||||||||||||||||||
| 430 | mtime_column => 'mtime', | ||||||||||||||||||||||||||||
| 431 | ); | ||||||||||||||||||||||||||||
| 432 | 0 | $envres->add_result($res->[0], $res->[1], {item_id=>$sw}); | |||||||||||||||||||||||||||
| 433 | 0 | ▶ | push @rows, { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 434 | software=>$sw, | ||||||||||||||||||||||||||||
| 435 | version=>$res->[0] == 200 ? $res->[2] : undef, | ||||||||||||||||||||||||||||
| 436 | }; | ||||||||||||||||||||||||||||
| 437 | } | ||||||||||||||||||||||||||||
| 438 | 0 | my $res = $envres->as_struct; | |||||||||||||||||||||||||||
| 439 | 0 | ▶ | if ($is_single_software) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 440 | 0 | $res->[2] = $rows[0]{version}; | |||||||||||||||||||||||||||
| 441 | } else { | ||||||||||||||||||||||||||||
| 442 | 0 | $res->[2] = \@rows; | |||||||||||||||||||||||||||
| 443 | } | ||||||||||||||||||||||||||||
| 444 | 0 | $res; | |||||||||||||||||||||||||||
| 445 | } | ||||||||||||||||||||||||||||
| 446 | |||||||||||||||||||||||||||||
| 447 | $SPEC{available_versions} = { | ||||||||||||||||||||||||||||
| 448 | 1 | v => 1.1, | |||||||||||||||||||||||||||
| 449 | summary => 'Get list of available versions of a software', | ||||||||||||||||||||||||||||
| 450 | description => <<'_', | ||||||||||||||||||||||||||||
| 451 | |||||||||||||||||||||||||||||
| 452 | |||||||||||||||||||||||||||||
| 453 | _ | ||||||||||||||||||||||||||||
| 454 | args => { | ||||||||||||||||||||||||||||
| 455 | %args_common, | ||||||||||||||||||||||||||||
| 456 | %arg0_software, | ||||||||||||||||||||||||||||
| 457 | }, | ||||||||||||||||||||||||||||
| 458 | }; | ||||||||||||||||||||||||||||
| 459 | 0 | ▶ | sub available_versions { | ||||||||||||||||||||||||||
|
Subroutine
available_versions: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 460 | 0 | my %args = @_; | |||||||||||||||||||||||||||
| 461 | 0 | my $state = _init(\%args, 'rw'); | |||||||||||||||||||||||||||
| 462 | |||||||||||||||||||||||||||||
| 463 | 0 | my $sw = $args{software}; | |||||||||||||||||||||||||||
| 464 | |||||||||||||||||||||||||||||
| 465 | 0 | my $mod = _load_swcat_mod($sw); | |||||||||||||||||||||||||||
| 466 | 0 | ▶ | return [501, "Not implemented"] unless $mod->can("available_versions"); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 467 | 0 | $mod->available_versions(arch => $args{arch}); | |||||||||||||||||||||||||||
| 468 | } | ||||||||||||||||||||||||||||
| 469 | |||||||||||||||||||||||||||||
| 470 | $SPEC{available_archs} = { | ||||||||||||||||||||||||||||
| 471 | 1 | v => 1.1, | |||||||||||||||||||||||||||
| 472 | summary => 'Get list of available architectures of a software', | ||||||||||||||||||||||||||||
| 473 | description => <<'_', | ||||||||||||||||||||||||||||
| 474 | |||||||||||||||||||||||||||||
| 475 | |||||||||||||||||||||||||||||
| 476 | _ | ||||||||||||||||||||||||||||
| 477 | args => { | ||||||||||||||||||||||||||||
| 478 | %args_common0, | ||||||||||||||||||||||||||||
| 479 | %arg0_software, | ||||||||||||||||||||||||||||
| 480 | }, | ||||||||||||||||||||||||||||
| 481 | }; | ||||||||||||||||||||||||||||
| 482 | 0 | ▶ | sub available_archs { | ||||||||||||||||||||||||||
|
Subroutine
available_archs: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 483 | 0 | my %args = @_; | |||||||||||||||||||||||||||
| 484 | 0 | my $state = _init(\%args, 'rw'); | |||||||||||||||||||||||||||
| 485 | |||||||||||||||||||||||||||||
| 486 | 0 | my $sw = $args{software}; | |||||||||||||||||||||||||||
| 487 | |||||||||||||||||||||||||||||
| 488 | 0 | my $mod = _load_swcat_mod($sw); | |||||||||||||||||||||||||||
| 489 | 0 | [200, "OK", [$mod->available_archs]]; | |||||||||||||||||||||||||||
| 490 | } | ||||||||||||||||||||||||||||
| 491 | |||||||||||||||||||||||||||||
| 492 | $SPEC{release_note} = { | ||||||||||||||||||||||||||||
| 493 | 1 | v => 1.1, | |||||||||||||||||||||||||||
| 494 | summary => 'Get release note of (a version of) a software', | ||||||||||||||||||||||||||||
| 495 | description => <<'_', | ||||||||||||||||||||||||||||
| 496 | |||||||||||||||||||||||||||||
| 497 | |||||||||||||||||||||||||||||
| 498 | _ | ||||||||||||||||||||||||||||
| 499 | args => { | ||||||||||||||||||||||||||||
| 500 | %args_common, | ||||||||||||||||||||||||||||
| 501 | %arg0_software, | ||||||||||||||||||||||||||||
| 502 | %argopt_arch, | ||||||||||||||||||||||||||||
| 503 | %argopt1_version, | ||||||||||||||||||||||||||||
| 504 | }, | ||||||||||||||||||||||||||||
| 505 | }; | ||||||||||||||||||||||||||||
| 506 | 0 | ▶ | sub release_note { | ||||||||||||||||||||||||||
|
Subroutine
release_note: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 507 | 0 | my %args = @_; | |||||||||||||||||||||||||||
| 508 | 0 | my $state = _init(\%args, 'ro'); | |||||||||||||||||||||||||||
| 509 | |||||||||||||||||||||||||||||
| 510 | 0 | my $sw = delete $args{software}; | |||||||||||||||||||||||||||
| 511 | 0 | my $mod = _load_swcat_mod($sw); | |||||||||||||||||||||||||||
| 512 | 0 | $mod->release_note(%args); | |||||||||||||||||||||||||||
| 513 | } | ||||||||||||||||||||||||||||
| 514 | |||||||||||||||||||||||||||||
| 515 | $SPEC{archive_info} = { | ||||||||||||||||||||||||||||
| 516 | 1 | v => 1.1, | |||||||||||||||||||||||||||
| 517 | summary => 'Get info of a software archive', | ||||||||||||||||||||||||||||
| 518 | args => { | ||||||||||||||||||||||||||||
| 519 | %args_common, | ||||||||||||||||||||||||||||
| 520 | %arg0_software, | ||||||||||||||||||||||||||||
| 521 | #%arg_version, | ||||||||||||||||||||||||||||
| 522 | %argopt_arch, | ||||||||||||||||||||||||||||
| 523 | }, | ||||||||||||||||||||||||||||
| 524 | }; | ||||||||||||||||||||||||||||
| 525 | 0 | ▶ | sub archive_info { | ||||||||||||||||||||||||||
|
Subroutine
archive_info: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 526 | 0 | my %args = @_; | |||||||||||||||||||||||||||
| 527 | 0 | my $state = _init(\%args, 'ro'); | |||||||||||||||||||||||||||
| 528 | |||||||||||||||||||||||||||||
| 529 | 0 | my $sw = $args{software}; | |||||||||||||||||||||||||||
| 530 | |||||||||||||||||||||||||||||
| 531 | 0 | my $mod = _load_swcat_mod($sw); | |||||||||||||||||||||||||||
| 532 | my $res = $mod->archive_info( | ||||||||||||||||||||||||||||
| 533 | maybe arch => $args{arch}, | ||||||||||||||||||||||||||||
| 534 | 0 | ); | |||||||||||||||||||||||||||
| 535 | 0 | $res; | |||||||||||||||||||||||||||
| 536 | } | ||||||||||||||||||||||||||||
| 537 | |||||||||||||||||||||||||||||
| 538 | $SPEC{download_url} = { | ||||||||||||||||||||||||||||
| 539 | 1 | v => 1.1, | |||||||||||||||||||||||||||
| 540 | summary => 'Get download URL(s) of a software', | ||||||||||||||||||||||||||||
| 541 | description => <<'_', | ||||||||||||||||||||||||||||
| 542 | |||||||||||||||||||||||||||||
| 543 | Will return the version number in the payload if given a single software name. | ||||||||||||||||||||||||||||
| 544 | Will return an array of {software=>..., version=>...} in the payload if given | ||||||||||||||||||||||||||||
| 545 | multiple software names or one or more patterns. | ||||||||||||||||||||||||||||
| 546 | |||||||||||||||||||||||||||||
| 547 | _ | ||||||||||||||||||||||||||||
| 548 | args => { | ||||||||||||||||||||||||||||
| 549 | %args_common, | ||||||||||||||||||||||||||||
| 550 | %argopt0_softwares_or_patterns, | ||||||||||||||||||||||||||||
| 551 | #%arg_version, | ||||||||||||||||||||||||||||
| 552 | %argopt_arch, | ||||||||||||||||||||||||||||
| 553 | }, | ||||||||||||||||||||||||||||
| 554 | }; | ||||||||||||||||||||||||||||
| 555 | 0 | ▶ | sub download_url { | ||||||||||||||||||||||||||
|
Subroutine
download_url: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||
| 556 | 0 | my %args = @_; | |||||||||||||||||||||||||||
| 557 | 0 | my $state = _init(\%args, 'ro'); | |||||||||||||||||||||||||||
| 558 | |||||||||||||||||||||||||||||
| 559 | 0 | my ($sws, $is_single_software) = _get_arg_softwares_or_patterns(\%args); | |||||||||||||||||||||||||||
| 560 | |||||||||||||||||||||||||||||
| 561 | 0 | my $envres = envresmulti(); | |||||||||||||||||||||||||||
| 562 | 0 | my @rows; | |||||||||||||||||||||||||||
| 563 | 0 | for my $sw (@$sws) { | |||||||||||||||||||||||||||
| 564 | 0 | my $mod = _load_swcat_mod($sw); | |||||||||||||||||||||||||||
| 565 | my $res = $mod->download_url( | ||||||||||||||||||||||||||||
| 566 | maybe arch => $args{arch}, | ||||||||||||||||||||||||||||
| 567 | 0 | ); | |||||||||||||||||||||||||||
| 568 | 0 | $envres->add_result($res->[0], $res->[1], {item_id=>$sw}); | |||||||||||||||||||||||||||
| 569 | 0 | push @rows, { | |||||||||||||||||||||||||||
| 570 | software => $sw, | ||||||||||||||||||||||||||||
| 571 | url => $res->[2], | ||||||||||||||||||||||||||||
| 572 | }; | ||||||||||||||||||||||||||||
| 573 | } | ||||||||||||||||||||||||||||
| 574 | 0 | my $res = $envres->as_struct; | |||||||||||||||||||||||||||
| 575 | 0 | ▶ | if ($is_single_software) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 576 | 0 | $res->[2] = $rows[0]{url}; | |||||||||||||||||||||||||||
| 577 | } else { | ||||||||||||||||||||||||||||
| 578 | 0 | $res->[2] = \@rows; | |||||||||||||||||||||||||||
| 579 | } | ||||||||||||||||||||||||||||
| 580 | 0 | $res; | |||||||||||||||||||||||||||
| 581 | } | ||||||||||||||||||||||||||||
| 582 | |||||||||||||||||||||||||||||
| 583 | 1 | 1; | |||||||||||||||||||||||||||
| 584 | # ABSTRACT: Software catalog | ||||||||||||||||||||||||||||
| 585 | |||||||||||||||||||||||||||||
| 586 | __END__ | ||||||||||||||||||||||||||||