| 1 | package CPAN::Namespace::Check::Visibility; | ||||||||||
| 2 | 1 | ▶ | use Exporter 'import'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 3 | 1 | our @EXPORT = qw(is_not_public); # No need to care more than that for pollution | |||||||||
| 4 | |||||||||||
| 5 | 1 | ▶ | use 5.006; | ||||||||
|
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 | |||||||||||
| 9 | 1 | ▶ | use App::cpm::Resolver::02Packages; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 10 | 1 | ▶ | use App::cpm::Resolver::MetaDB; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 11 | 1 | ▶ | use App::cpm::Resolver::MetaCPAN; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 12 | |||||||||||
| 13 | =head1 NAME | ||||||||||
| 14 | |||||||||||
| 15 | CPAN::Namespace::Check::Visibility - Check if a namespace exists on public CPAN | ||||||||||
| 16 | |||||||||||
| 17 | =head1 VERSION | ||||||||||
| 18 | |||||||||||
| 19 | Version 0.03 | ||||||||||
| 20 | |||||||||||
| 21 | =cut | ||||||||||
| 22 | |||||||||||
| 23 | 1 | our $VERSION = '0.03'; | |||||||||
| 24 | |||||||||||
| 25 | |||||||||||
| 26 | =head1 SYNOPSIS | ||||||||||
| 27 | |||||||||||
| 28 | =begin html | ||||||||||
| 29 | |||||||||||
| 30 | <div style="display: flex"> | ||||||||||
| 31 | <div style="margin: 3px; flex: 1 1 50%"> | ||||||||||
| 32 | <img alt="Demo CPAN Namespace Check Visibility" src="https://fastapi.metacpan.org/source/CONTRA/CPAN-Namespace-Check-Visibility-0.03/demo.png" style="max-width: 100%"> | ||||||||||
| 33 | </div> | ||||||||||
| 34 | </div> | ||||||||||
| 35 | |||||||||||
| 36 | =end html | ||||||||||
| 37 | |||||||||||
| 38 | |||||||||||
| 39 | You can use the C<is_not_public> sub with one or several packages: | ||||||||||
| 40 | |||||||||||
| 41 | use CPAN::Namespace::Check::Visibility; | ||||||||||
| 42 | |||||||||||
| 43 | exit is_not_public("Local::Acme"); | ||||||||||
| 44 | |||||||||||
| 45 | Or | ||||||||||
| 46 | |||||||||||
| 47 | use CPAN::Namespace::Check::Visibility; | ||||||||||
| 48 | |||||||||||
| 49 | exit is_not_public(@ARGV); | ||||||||||
| 50 | |||||||||||
| 51 | Or prefer the executable: | ||||||||||
| 52 | |||||||||||
| 53 | cpan-check-visibility Local::Acme | ||||||||||
| 54 | |||||||||||
| 55 | Or from a file: | ||||||||||
| 56 | |||||||||||
| 57 | cpan-check-visibility `cat private-deps.txt` | ||||||||||
| 58 | |||||||||||
| 59 | Please note: it does not accept C<cpanfile> nor C<cpm.yml> format | ||||||||||
| 60 | |||||||||||
| 61 | =head1 SUBROUTINES/METHODS | ||||||||||
| 62 | |||||||||||
| 63 | =head2 is_not_public | ||||||||||
| 64 | |||||||||||
| 65 | Test indexes for package(s) provided as argument(s). | ||||||||||
| 66 | |||||||||||
| 67 | =cut | ||||||||||
| 68 | |||||||||||
| 69 | 0 | ▶ | sub is_not_public { | ||||||||
|
Subroutine
is_not_public: not called CC=8 SCAR=42.8
Pod
documented
| |||||||||||
| 70 | 0 | my @packages = @_; | |||||||||
| 71 | 0 | my $cpan = App::cpm::Resolver::02Packages->new( | |||||||||
| 72 | mirror => "https://cpan.org", | ||||||||||
| 73 | cache => "/tmp", | ||||||||||
| 74 | ); | ||||||||||
| 75 | 0 | my $metadb = App::cpm::Resolver::MetaDB->new(); | |||||||||
| 76 | 0 | my $metacpan = App::cpm::Resolver::MetaCPAN->new(dev => 1); | |||||||||
| 77 | |||||||||||
| 78 | |||||||||||
| 79 | 0 | my $status = 0; | |||||||||
| 80 | 0 | for my $package (@packages) { | |||||||||
| 81 | 0 | chomp $package; | |||||||||
| 82 | 0 | my $fail = 0; | |||||||||
| 83 | #print "🔍 Working on $package...\n"; | ||||||||||
| 84 | 0 | my $task = { package => "$package" }; | |||||||||
| 85 | 0 | my @resolvers = (); | |||||||||
| 86 | 0 | ▶ | if (not defined $cpan->resolve($task)->{error}) { push @resolvers, "CPAN"; $fail = 1; } | ||||||||
|
Branch: 1 branch
| |||||||||||
| 87 | 0 | ▶ | if (not defined $metadb->resolve($task)->{error}) { push @resolvers, "MetaDB"; $fail = 1; } | ||||||||
|
Branch: 1 branch
| |||||||||||
| 88 | 0 | ▶ | if (not defined $metacpan->resolve($task)->{error}) { push @resolvers, "MetaCPAN"; $fail = 1; } | ||||||||
|
Branch: 1 branch
| |||||||||||
| 89 | |||||||||||
| 90 | 0 | ▶ | if ($fail) { print "❌ [$package] resolves in " . join("/", @resolvers) . "\n"; } | ||||||||
|
Branch: 1 branch
| |||||||||||
| 91 | 0 | ▶ | if (not $fail) { print "✅ [$package] does not resolve\n"; } else { $status +=1 } | ||||||||
|
Branch: 1 branch
| |||||||||||
| 92 | } | ||||||||||
| 93 | |||||||||||
| 94 | 0 | ▶ | return -1 if $status; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 95 | 0 | return; | |||||||||
| 96 | } | ||||||||||
| 97 | |||||||||||
| 98 | =head1 AUTHOR | ||||||||||
| 99 | |||||||||||
| 100 | Thibault Duponchelle, C<< <thibault.duponchelle at gmail.com> >> | ||||||||||
| 101 | |||||||||||
| 102 | =head1 ACKNOWLEDGEMENTS | ||||||||||
| 103 | |||||||||||
| 104 | |||||||||||
| 105 | =head1 LICENSE AND COPYRIGHT | ||||||||||
| 106 | |||||||||||
| 107 | This software is Copyright (c) 2024 by Thibault Duponchelle. | ||||||||||
| 108 | |||||||||||
| 109 | This is free software, licensed under: | ||||||||||
| 110 | |||||||||||
| 111 | The Artistic License 2.0 (GPL Compatible) | ||||||||||
| 112 | |||||||||||
| 113 | |||||||||||
| 114 | =cut | ||||||||||
| 115 | |||||||||||
| 116 | 1 | 1; # End of CPAN::Namespace::Check::Visibility | |||||||||