Permalink
Browse files

Moved pkg-details to the examples/ directory.

  • Loading branch information...
1 parent 0bd1b01 commit d165df319f3aafee384e37ee307cd6608cf3270c Jeffrey Ryan Thalhammer committed Nov 21, 2011
Showing with 61 additions and 2 deletions.
  1. +47 −0 examples/pkg-locate
  2. +14 −2 lib/Package/Locator.pm
View
47 examples/pkg-locate
@@ -0,0 +1,47 @@
+#!/usr/bin/perl
+
+# ABSTRACT: Find URL to distribution that contains a given package
+# PODNAME: pkg-locate
+
+use strict;
+use warnings;
+
+use Getopt::Long;
+use Pod::Usage;
+use Package::Locator;
+
+my @opts_spec = qw(cache_dir|cache=s);
+GetOptions(\my %opts, @opts_spec) || pod2usage();
+my @wanted = @ARGV ? @ARGV : pod2usage();
+
+my $locator = Package::Locator->new(%opts);
+my %found = map { my $p = $_; $p => $locator->locate($p) || '' } @wanted;
+my $longest = (sort { $b <=> $a } map { length } keys %found)[0];
+printf "%-${longest}s => %s\n", $_, $found{$_} for sort keys %found;
+
+exit;
+
+#-----------------------------------------------------------------------------
+
+=head1 SYNOPSIS
+
+ pkg-locate [ --cache=/some/dir ] PACKAGE_NAME_OR_DIST_PATH ...
+
+=head1 DESCRIPTION
+
+L<pkg-locate> is a simple command line tool demonstrating the use
+of L<Package::Locator>. For each package, L<pkg-locate> will report
+the URL of a distribution that will provide that package.
+
+=head1 ARGUMENTS
+
+The arguments are the names of packages (e.g. 'FOO::Bar') or paths to
+distributions as they would appear in a CPAN-like index file
+(e.g. 'F/FO/FOO/Bar-1.2.tar.gz').
+
+=head1 OPTIONS
+
+=head2 --cache = /some/path
+
+A directory that will be used to cache index files for future
+lookups. If this directory does not exist it will be created for you.
View
16 lib/Package/Locator.pm
@@ -313,10 +313,22 @@ All the attributes listed below can be passed to the constructor, and
retrieved via accessor methods with the same name. All attributes are
read-only, and cannot be changed once the object is constructed.
+=head1 MOTIVATION
+
+The L<CPAN> module also provides a mechanism for locating packages or
+distributions, much like L<Package::Locator> does. However, L<CPAN>
+assumes that all repositories are CPAN mirrors, so it only searches
+the first repository that it can contact.
+
+My secret ambition is to fill the world with lots of DarkPAN
+repositories -- each with its own set of distributions. For that
+scenario, I need to search multiple repositories at the same time.
+
=head1 SEE ALSO
-If you need to find a precise version of a package/distribution rather
-than just a version that is "new enough", then look at some of these:
+If you need to locate a distribution that contains a precise version
+of a file rather than just a version that is "new enough", then look
+at some of these:
L<Dist::Surveyor>
L<BackPAN::Index>

0 comments on commit d165df3

Please sign in to comment.