1
1
package ModulesPerl6::DbBuilder::Dist::Source ;
2
2
3
+ use FindBin; FindBin-> again;
3
4
use File::Spec::Functions qw/ catfile/ ;
4
5
use JSON::Meth qw/ $json/ ;
6
+ use Mojo::JSON qw/ from_json/ ;
5
7
use Mojo::UserAgent;
6
- use Mojo::Util qw/ spurt decode/ ;
8
+ use Mojo::Util qw/ slurp spurt decode/ ;
7
9
use Try::Tiny;
8
10
9
11
use ModulesPerl6::DbBuilder::Log;
@@ -22,6 +24,24 @@ has _ua => InstanceOf['Mojo::UserAgent'], (
22
24
is => ' lazy' ,
23
25
default => sub { Mojo::UserAgent-> new( max_redirects => 10 ) },
24
26
);
27
+ has _tag_aliases => Maybe[Ref[' HASH' ]], (
28
+ is => ' lazy' ,
29
+ default => sub {
30
+ my $raw_tags = eval {
31
+ from_json slurp $ENV {MODULESPERL6_TAG_ALIASES_FILE }
32
+ // catfile $FindBin::Bin , qw/ .. tag-aliases.json/ ;
33
+ } || do { warn " \n\n Failed to load tag-aliases.json: $@ \n\n " ; exit ; };
34
+
35
+ my %tags ;
36
+ for my $key (keys %{ $raw_tags -> {replacements } || {}}) {
37
+ for (@{$raw_tags -> {replacements }{$key }}) {
38
+ $tags {+uc } = uc $key ;
39
+ }
40
+ }
41
+ my %no_index = map +((uc ) => 1), @{ $raw_tags -> {do_not_index } || [] };
42
+ { no_index => \%no_index , replacements => \%tags }
43
+ }
44
+ );
25
45
26
46
sub _download_meta {
27
47
my $self = shift ;
@@ -57,10 +77,16 @@ sub _parse_meta {
57
77
// $json -> {' repo-url' }
58
78
// $json -> {support }{source };
59
79
80
+ my ($no_index , $tags ) = @{ $self -> _tag_aliases }{qw/ no_index replacements/ };
81
+
60
82
$json -> {tags } = [] unless ref ($json -> {tags }) eq ' ARRAY' ;
61
- @{ $json -> {tags } } = map uc , map {
62
- length > 20 ? substr ($_ , 0, 17) . ' ...' : $_
63
- } grep {length and not ref } @{ $json -> {tags } };
83
+ @{ $json -> {tags } } = map {
84
+ length > 20 ? substr ($_ , 0, 17) . ' ...' : $_
85
+ } map {
86
+ $tags -> {$_ } || $_ # perform substitution to common form
87
+ } grep {
88
+ length and not ref and not $no_index -> {$_ }
89
+ } map uc , @{ $json -> {tags } };
64
90
return $self -> _fill_missing( {%$json } );
65
91
}
66
92
@@ -435,4 +461,3 @@ Original version of this module was written by Zoffix Znet
435
461
=head1 LICENSE
436
462
437
463
You can use and distribute this module under the same terms as Perl itself.
438
-
0 commit comments