#!/usr/bin/env perl
use strict;
use warnings;
use 5.006;
use Module::Path qw(module_path);
use Getopt::Long qw(GetOptions);
use Pod::Usage qw(pod2usage);

GetOptions(\my %opts, 'help|h|?', 'quiet|q', 'full|f')
  or pod2usage 2;

if ($opts{help}) {
        -verbose => 2,
        -exitval => 0,
elsif (!@ARGV) {
        -message => 'No module specified',
        -verbose => 1,

my $all_found = 1;

for my $module (@ARGV) {
    my $path = module_path($module);
    if (!defined($path)) {
        $all_found = 0;
        print "$module not found\n" unless $opts{quiet};
    else {
        print "$module " if $opts{full};
        print "$path\n";

my $status = $all_found ? 0 : 1;
exit $status;

=head1 NAME

mpath - display the full path to a perl module (installed locally)

=head1 USAGE


=head1 EXAMPLE

  % mpath Module::Path

  % mpath --full Module::Path
  Module::Path /usr/local/lib/perl5/site_perl/5.16.0/Module/Path.pm

  % mpath Moose Moo


mpath displays the full path to a perl module on the local system.
It uses the C<module_path()> function from L<Module::Path> to get the path.

If one of the module wasn't found, mpath will exit with the exit code 1 and
print the following message (you can silence it with the option B<--quiet>):

  % mpath Foo::Bar
  Foo::Bar not found


  % mpath Moose Foo::Bar
  Foo::Bar not found

=head1 OPTIONS


=item B<-h>, B<-?>, B<--help>

Print this help message and exit.

=item B<-f>, B<--full>

Print module name.

=item B<-q>, B<--quiet>

Don't print any error when one of the module requested could not be found.


=head1 SEE ALSO


=head1 AUTHOR

Neil Bowers E<lt>neilb@cpan.orgE<gt>


This software is copyright (c) 2012 by Neil Bowers E<lt>neilb@cpan.orgE<gt>.

This is free software; you can redistribute it and/or modify it under
the same terms as the Perl 5 programming language system itself.