App-Info
view release on metacpan or search on metacpan
lib/App/Info/Util.pm view on Meta::CPAN
=cut
sub first_path {
return unless $path_dem;
shift->first_dir(split /$path_dem/, shift)
}
##############################################################################
=head2 first_file
my $file = $util->first_file(@filelist);
Examines each of the files in @filelist and returns the first one that exists
on the file system. The file must be a regular file -- directories will be
ignored.
=cut
sub first_file {
shift;
foreach (@_) { return $_ if -f }
return;
}
##############################################################################
=head2 first_exe
my $exe = $util->first_exe(@exelist);
Examines each of the files in @exelist and returns the first one that exists
on the file system as an executable file. Directories will be ignored.
=cut
sub first_exe {
shift;
foreach (@_) { return $_ if -f && -x }
return;
}
##############################################################################
=head2 first_cat_path
my $file = $util->first_cat_path('ick.txt', @paths);
$file = $util->first_cat_path(['this.txt', 'that.txt'], @paths);
The first argument to this method may be either a file or directory base name
(that is, a file or directory name without a full path specification), or a
reference to an array of file or directory base names. The remaining arguments
constitute a list of directory paths. C<first_cat_path()> processes each of
these directory paths, concatenates (by the method native to the local
operating system) each of the file or directory base names, and returns the
first one that exists on the file system.
For example, let us say that we were looking for a file called either F<httpd>
or F<apache>, and it could be in any of the following paths:
F</usr/local/bin>, F</usr/bin/>, F</bin>. The method call looks like this:
my $httpd = $util->first_cat_path(['httpd', 'apache'], '/usr/local/bin',
'/usr/bin/', '/bin');
If the OS is a Unix variant, C<first_cat_path()> will then look for the first
file that exists in this order:
=over 4
=item /usr/local/bin/httpd
=item /usr/local/bin/apache
=item /usr/bin/httpd
=item /usr/bin/apache
=item /bin/httpd
=item /bin/apache
=back
The first of these complete paths to be found will be returned. If none are
found, then undef will be returned.
=cut
sub first_cat_path {
my $self = shift;
my $files = ref $_[0] ? shift() : [shift()];
foreach my $p (@_) {
foreach my $f (@$files) {
my $path = $self->catfile($p, $f);
return $path if -e $path;
}
}
return;
}
##############################################################################
=head2 first_cat_dir
my $dir = $util->first_cat_dir('ick.txt', @paths);
$dir = $util->first_cat_dir(['this.txt', 'that.txt'], @paths);
Functionally identical to C<first_cat_path()>, except that it returns the
directory path in which the first file was found, rather than the full
concatenated path. Thus, in the above example, if the file found was
F</usr/bin/httpd>, while C<first_cat_path()> would return that value,
C<first_cat_dir()> would return F</usr/bin> instead.
=cut
sub first_cat_dir {
my $self = shift;
my $files = ref $_[0] ? shift() : [shift()];
foreach my $p (@_) {
foreach my $f (@$files) {
( run in 2.806 seconds using v1.01-cache-2.11-cpan-39bf76dae61 )