Debian Codegraph @

examples/pkg-locate

raw
1 #!/usr/bin/perl
2
3 # ABSTRACT: Find URL to distribution that contains a given package
4 # PODNAME: pkg-locate
5
6 use strict;
7 use warnings;
8
9 use Getopt::Long;
10 use Pod::Usage;
11 use Package::Locator;
12
13 my @opts_spec = qw(cache_dir|cache=s);
14 GetOptions(\my %opts, @opts_spec) || pod2usage();
15 my @wanted = @ARGV ? @ARGV : pod2usage();
16
17 my $locator = Package::Locator->new(%opts);
18 my %found = map { my $p = $_; $p => $locator->locate($p) || '' } @wanted;
19 my $longest = (sort { $b <=> $a } map { length } keys %found)[0];
20 printf "%-${longest}s => %s\n", $_, $found{$_} for sort keys %found;
21
22 exit;
23
24 #-----------------------------------------------------------------------------
25
26 =head1 SYNOPSIS
27
28 pkg-locate [ --cache=/some/dir ] PACKAGE_NAME_OR_DIST_PATH ...
29
30 =head1 DESCRIPTION
31
32 L<pkg-locate> is a simple command line tool demonstrating the use
33 of L<Package::Locator>. For each package, L<pkg-locate> will report
34 the URL of a distribution that will provide that package.
35
36 =head1 ARGUMENTS
37
38 The arguments are the names of packages (e.g. 'FOO::Bar') or paths to
39 distributions as they would appear in a CPAN-like index file
40 (e.g. 'F/FO/FOO/Bar-1.2.tar.gz').
41
42 =head1 OPTIONS
43
44 =head2 --cache = /some/path
45
46 A directory that will be used to cache index files for future
47 lookups. If this directory does not exist it will be created for you.