NAME

Unix::Whereis - locate programs in standard binary directories and/or specified directories

VERSION

This document describes Unix::Whereis version 0.1

SYNOPSIS

    use Unix::Whereis;

    my $ffmpeg = whereis('ffmpeg');
    if ($ffmpeg) {
        system($ffmpeg, …) && die …;
    }
    else {
        die "Install ffmpeg into your PATH please.";
    }

DESCRIPTION

Same idea as the Unix whereis program but in perl function form. Should work on non-Unix systems that have a concept of PATH.

A few handy uses:

Use a modified lookup PATH without affecting your actual environment (i.e. then the shell can then skip the lookup it’d have done).
Verify you have a binary installed to avoid unnecessary work and handle it gracefully if you don’t.

Also, this will help when you’re not shelling out immediately, for example:

Look up a value for a configuration option.
Look it up and do some checks on it/with it before you execute it.
Look it up once and execute it several times without making the shell do the same lookup each time.

I find it handy, if you do to, cool!

INTERFACE

There are 3 functions:

whereis()

Exported via import().

Given a program name it looks for it in the environment’s PATH. Returns the first path found or nothing (i.e. false) if it is not found.

You can modify it by passing in an optional hashref with the following keys:

'fallback'

Boolean, when true will cause whereis() to return the program name (instead of nothing) if no specific path is found.

'mypath'

PATH string to use instead of $ENV{PATH}

'prepend'

PATH string to prepend to the base path.

'append'

PATH string to append to the base path.

'cache'

Boolean, default false.

When true it caches the results for the program name for subsequent calls that also have 'cache' set.

Caveat: The cache is not based on what is in the optional hash.

You can clear the current cached value first by giving it a value of 'clear'.

whereis_everyone()

Exported on request:

    use Unix::Whereis 'whereis_everyone';

Given a program name it looks for it in the environment’s PATH. Returns a list of every one of the paths it finds.

It can take the same optional hashref that whereis() does, except 'fallback' is a no-op.

    print Dumper( [ Unix::Whereis::whereis_everyone('perl') ] );

pathsep()

Not exportable.

    my $sep = Unix::Whereis::pathsep();

Mainly internal but handy for introspection perhaps …

Returns the $PATH separator it will use.

If the separator has not yet been set it will set it to $Config::Config{'path_sep'} if you have loaded Config.pm, : otherwise.

You can pass it a value to set the separator to whatever you like (seems odd but hey its your code).

Passing undef() will make it redo the $Config::Config{'path_sep'} or : logic.

DIAGNOSTICS

Throws no warnings or errors of its own.

DEPENDENCIES

File::Spec

INCOMPATIBILITIES

None reported.

BUGS AND LIMITATIONS

No bugs have been reported.

Please report any bugs or feature requests to bug-Unix-whereis@rt.cpan.org, or through the web interface at http://rt.cpan.org.

AUTHOR

Daniel Muey <http://drmuey.com/cpan_contact.pl>

LICENCE AND COPYRIGHT

Copyright (c) 2013, Daniel Muey <http://drmuey.com/cpan_contact.pl>. All rights reserved.

This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself. See perlartistic.

DISCLAIMER OF WARRANTY

BECAUSE THIS SOFTWARE IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE SOFTWARE, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE SOFTWARE "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE SOFTWARE IS WITH YOU. SHOULD THE SOFTWARE PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR, OR CORRECTION.

IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE SOFTWARE AS PERMITTED BY THE ABOVE LICENCE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE SOFTWARE (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE SOFTWARE TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.