File Coverage

blib/lib/CPAN/Namespace/Check/Visibility.pm
Criterion Covered Total %
statement 20 46 43.4
branch 0 12 0.0
condition n/a
subroutine 7 8 87.5
pod 1 1 100.0
total 28 67 41.7


line stmt bran cond sub pod time code
1             package CPAN::Namespace::Check::Visibility;
2 1     1   125718 use Exporter 'import';
  1         5  
  1         66  
3             our @EXPORT = qw(is_not_public); # No need to care more than that for pollution
4              
5 1     1   20 use 5.006;
  1         4  
6 1     1   7 use strict;
  1         2  
  1         27  
7 1     1   5 use warnings;
  1         2  
  1         118  
8              
9 1     1   759 use App::cpm::Resolver::02Packages;
  1         87775  
  1         49  
10 1     1   637 use App::cpm::Resolver::MetaDB;
  1         12295  
  1         52  
11 1     1   658 use App::cpm::Resolver::MetaCPAN;
  1         27251  
  1         506  
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             our $VERSION = '0.03';
24              
25              
26             =head1 SYNOPSIS
27              
28             =begin html
29              
30            
31            
32             Demo CPAN Namespace Check Visibility
33            
34            
35              
36             =end html
37              
38              
39             You can use the C 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 nor C 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             sub is_not_public {
70 0     0 1   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 0         if (not defined $cpan->resolve($task)->{error}) { push @resolvers, "CPAN"; $fail = 1; }
  0            
  0            
87 0 0         if (not defined $metadb->resolve($task)->{error}) { push @resolvers, "MetaDB"; $fail = 1; }
  0            
  0            
88 0 0         if (not defined $metacpan->resolve($task)->{error}) { push @resolvers, "MetaCPAN"; $fail = 1; }
  0            
  0            
89            
90 0 0         if ($fail) { print "❌ [$package] resolves in " . join("/", @resolvers) . "\n"; }
  0            
91 0 0         if (not $fail) { print "✅ [$package] does not resolve\n"; } else { $status +=1 }
  0            
  0            
92             }
93              
94 0 0         return -1 if $status;
95 0           return;
96             }
97              
98             =head1 AUTHOR
99              
100             Thibault Duponchelle, C<< >>
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; # End of CPAN::Namespace::Check::Visibility