NAME

File::Where - find the absolute file for a program module; absolute dir for a repository

SYNOPSIS

#######
# Subroutine interface
#  
use File::PM2File qw(pm2require where where_dir where_file where_pm where_repository);

$file                            = pm2require($pm);

$abs_file                        = where($relative_file);
($abs_file, $inc_path, $rel_fle) = where($relative_file)
$abs_file                        = where($relative_file, \@path);
($abs_file, $inc_path, $rel_fle) = where($relative_file, \@path)
$abs_dir                         = where($relative_dir, '', 'nofile'); 
($abs_dir, $inc_path, $rel_dir)  = where($relative_dir, '', 'nofile');
$abs_dir                         = where($relative_dir, \@path, 'nofile'); 
($abs_dir, $inc_path, $rel_dir)  = where($relative_dir, \@path, 'nofile');

$abs_dir                         = where_dir($relative_dir); 
($abs_dir, $inc_path, $rel_dir)  = where_dir($relative_dir);
$abs_dir                         = where_dir($relative_dir, \@path; 
($abs_dir, $inc_path, $rel_dir)  = where_dir($relative_dir, \@path);
$abs_dir                         = where_dir($relative_dir, @path; 
($abs_dir, $inc_path, $rel_dir)  = where_dir($relative_dir, @path);

$abs_file                        = where_file($relative_file);
($abs_file, $inc_path, $rel_fle) = where_file($relative_file)
$abs_file                        = where_file($relative_file, \@path);
($abs_file, $inc_path, $rel_fle) = where_file($relative_file, \@path)
$abs_file                        = where_file($relative_file, @path);
($abs_file, $inc_path, $rel_fle) = where_file($relative_file, @path)

$abs_file                        = where_pm($pm); 
($abs_file, $inc_path, $require) = where_pm($pm);
$abs_file                        = where_pm($pm, \@path);
($abs_file, $inc_path, $require) = where_pm($pm, \@path);
$abs_file                        = where_pm($pm, @path);
($abs_file, $inc_path, $require) = where_pm($pm, @path);

$abs_dir                         = where_repository($repository);
($abs_dir,  $inc_path, $rel_dir) = where_repository($repository);
$abs_dir                         = where_repository($repository, \@path);
($abs_dir,  $inc_path, $rel_dir) = where_repository($repository, \@path);
$abs_dir                         = where_repository($repository, @path);
($abs_dir,  $inc_path, $rel_dir) = where_repository($repository, @path);

#######
# Class interface
#
$file                            = File::PM2File->pm2require($pm);

$abs_file                        = File::PM2File->where($relative_file);
($abs_file, $inc_path, $require) = File::PM2File->where($relative_file)
$abs_file                        = File::PM2File->where($relative_file, \@path);
($abs_file, $inc_path, $require) = File::PM2File->where($relative_file, \@path)
$abs_dir                         = File::PM2File->where($relative_dir, '', 'nofile'); 
($abs_dir, $inc_path, $rel_dir)  = File::PM2File->where($relative_dir, '', 'nofile');
$abs_dir                         = File::PM2File->where($relative_dir, \@path, 'nofile'); 
($abs_dir, $inc_path, $rel_dir)  = File::PM2File->where($relative_dir, \@path, 'nofile');

$abs_dir                         = File::PM2File->where_dir($relative_dir); 
($abs_dir, $inc_path, $rel_dir)  = File::PM2File->where_dir($relative_dir);
$abs_dir                         = File::PM2File->where_dir($relative_dir, \@path; 
($abs_dir, $inc_path, $rel_dir)  = File::PM2File->where_dir($relative_dir, \@path);
$abs_dir                         = File::PM2File->where_dir($relative_dir, @path; 
($abs_dir, $inc_path, $rel_dir)  = File::PM2File->where_dir($relative_dir, @path);

$abs_file                        = File::PM2File->where_file($relative_file);
($abs_file, $inc_path, $require) = File::PM2File->where_file($relative_file)
$abs_file                        = File::PM2File->where_file($relative_file, \@path);
($abs_file, $inc_path, $require) = File::PM2File->where_file($relative_file, \@path)
$abs_file                        = File::PM2File->where_file($relative_file, @path);
($abs_file, $inc_path, $require) = File::PM2File->where_file($relative_file, @path)

$abs_file                        = File::PM2File->where_pm($pm); 
($abs_file, $inc_path, $require) = File::PM2File->where_pm($pm);
$abs_file                        = File::PM2File->where_pm($pm, \@path);
($abs_file, $inc_path, $require) = File::PM2File->where_pm($pm, \@path);
$abs_file                        = File::PM2File->where_pm($pm, @path);
($abs_file, $inc_path, $require) = File::PM2File->where_pm($pm, @path);

$abs_dir                         = File::PM2File->where_repository($repository);
($abs_dir,  $inc_path, $rel_dir) = File::PM2File->where_repository($repository);
$abs_dir                         = File::PM2File->where_repository($repository, \@path);
($abs_dir,  $inc_path, $rel_dir) = File::PM2File->where_repository($repository, \@path);
$abs_dir                         = File::PM2File->where_repository($repository, @path);
($abs_dir,  $inc_path, $rel_dir) = File::PM2File->where_repository($repository, @path);

DESCRIPTION

From time to time, an program needs to know the abolute file for a program module that has not been loaded. The File::PM2File module provides methods to find this information. For loaded files, using the hash %INC may perform better than using the methods in this module.

METHODS/SUBROUTINES

pm2require subroutine

$file = pm2require($pm_file)

The pm2require method/subroutine returns the file suitable for use in a Perl require for the $pm program module.

where subroutine

The where subroutine is the core subroutine call by where_file, where_dir, where_pm and where_repository.

When $no_file is absent, 0 or '', the where subroutine performs as established for the where_file subroutine; otherwise the where subroutine performs as established for the where_dir subroutine.

The differences is that the where syntax only accepts a reference to an array path while the where_dir and where_file accept both a reference to an array path and an array path.

where_dir subroutine

When $nofile exists and is non-zero, the find_in_include method/subroutine looks for the $relative_dir under one of the directories in the @path (@INC path if @path is '' or 0) in the order listed in @path or @INC. When find_in_include finds the directory, it returns the absolute file $absolute_dir and the directory $path where it found $relative_dir when the usage calls for an array return; otherwise, the absolute directory $absolute_dir.

When the @path list of directores exists and is not '' or 0, the where_dir subroutine/method searches the @path list of directories instead of the @INC list of directories.

where_file subroutine

When $nofile is '', 0 or absent, the find_in_include method/subroutine looks for the $relative_file in one of the directories in the @path (@INC path if @path is absent, '' or 0) in the order listed in @path or @INC. When find_in_include finds the file, it returns the absolute file $file_absolute and the directory $path where it found $file_relative when the usage calls for an array return; otherwise, the absolute file $file_absolute.

When the @path list of directores exists and is not '' or 0, the where_file subroutine/method searches the @path list of directories instead of the @INC list of directories.

where_pm subroutine

In an array context, the where_pm subroutine/method returns the $absolute_file, the directory $inc_path in @INC, and the relative $require_file for the first directory in @INC list of directories where it found the program module $pm; otherwise, it returns just the $absolute_file.

When the @path list of directores exists and is not '' or 0, the where_pm subroutine/method searches the @path list of directories instead of the @INC list of directories.

where_repository subroutine

An repository specifies the location of a number of program modules. For example, the repository for this program module, File::Where, is File::.

In an array context, the where_repository subroutine/method returns the $absolute_directory, the directory $inc_path in @INC for the first directory in @INC list of directories, and the relative directory of the repository where it found the $repository; otherwise, it returns just the $absolute_file.\ When where_repository cannot find a directory containing the $repository relative directory, where_repository pops the last directory off the $repository relative directory and trys again. If where_repository finds that $repository is empty, it returns emptys.

for the $repository; otherwise, it returns just the $absolute_directory.

When the @path list of directores exists and is not '' or 0, the where_repository subroutine/method searches the @path list of directories instead of the @INC list of directories.

REQUIREMENTS

DEMONSTRATION

~~~~~~ Demonstration overview ~~~~~

Perl code begins with the prompt

=>

The selected results from executing the Perl Code follow on the next lines. For example,

=> 2 + 2
4

~~~~~~ The demonstration follows ~~~~~

=>     use File::Spec;
=>     use File::Copy;
=>     use File::Path;
=>     use File::Package;
=>     my $fp = 'File::Package';

=>     my $uut = 'File::Where';
=>     my $loaded = '';
=>     # Use the test file as an example since know its absolute path
=>     #
=>     my $test_script_dir = cwd();
=>     chdir File::Spec->updir();
=>     chdir File::Spec->updir();
=>     my $include_dir = cwd();
=>     chdir $test_script_dir;
=>     my $OS = $^O;  # need to escape ^
=>     unless ($OS) {   # on some perls $^O is not defined
=>         require Config;
=> 	$OS = $Config::Config{'osname'};
=>     } 
=>     $include_dir =~ s=/=\\=g if( $OS eq 'MSWin32');
=>     $test_script_dir =~ s=/=\\=g if( $OS eq 'MSWin32');

=>     # Put base directory as the first in the @INC path
=>     #
=>     my @restore_inc = @INC;
=>     unshift @INC, $include_dir;    

=>     my $relative_file = File::Spec->catfile('t', 'File', 'Where.pm'); 
=>     my $relative_dir1 = File::Spec->catdir('t', 'File');
=>     my $relative_dir2 = File::Spec->catdir('t', 'Jolly_Green_Giant');

=>     my $absolute_file1 = File::Spec->catfile($include_dir, 't', 'File', 'Where.pm');
=>     my $absolute_dir1A = File::Spec->catdir($include_dir, 't', 'File');
=>     my $absolute_dir1B = File::Spec->catdir($include_dir, 't');

=>     mkpath (File::Spec->catdir($test_script_dir, 't','File'));
=>     my $absolute_file2 = File::Spec->catfile($test_script_dir, 't', 'File', 'Where.pm');
=>     my $absolute_dir2A = File::Spec->catdir($include_dir, 't', 'File', 't', 'File');
=>     my $absolute_dir2B = File::Spec->catdir($include_dir, 't', 'File', 't');

=>     my @inc2 = ($test_script_dir, @INC);  # another way to do unshift
=>     
=>     copy $absolute_file1,$absolute_file2;

=>     my (@actual,$actual); # use for array and scalar context
=> my $errors = $fp->load_package( 'File::Where' )
=> $errors
''

=> $actual = $uut->pm2require( "$uut")
'File\Where.pm'

=> [@actual = $uut->where($relative_file)]
[
          'E:\User\SoftwareDiamonds\installation\t\File\Where.pm',
          'E:\User\SoftwareDiamonds\installation',
          't\File\Where.pm'
        ]

=> $actual = $uut->where($relative_file)
'E:\User\SoftwareDiamonds\installation\t\File\Where.pm'

=> [@actual = $uut->where($relative_file, [$test_script_dir, $include_dir])]
[
          'E:\User\SoftwareDiamonds\installation\t\File\t\File\Where.pm',
          'E:\User\SoftwareDiamonds\installation\t\File',
          't\File\Where.pm'
        ]

=> [@actual = $uut->where($relative_dir1, '', 'nofile')]
[
          'E:\User\SoftwareDiamonds\installation\t\File',
          'E:\User\SoftwareDiamonds\installation',
          't\File'
        ]

=> $actual = $uut->where($relative_file, '', 'nofile')
'E:\User\SoftwareDiamonds\installation\t\File'

=> [@actual = $uut->where($relative_dir2, \@inc2, 'nofile')]
[
          'E:\User\SoftwareDiamonds\installation\t\File\t',
          'E:\User\SoftwareDiamonds\installation\t\File',
          't'
        ]

=> $actual = $uut->where('t', [$test_script_dir,@INC], 'nofile')
'E:\User\SoftwareDiamonds\installation\t\File\t'

=> [@actual = $uut->where_file($relative_file)]
[
          'E:\User\SoftwareDiamonds\installation\t\File\Where.pm',
          'E:\User\SoftwareDiamonds\installation',
          't\File\Where.pm'
        ]

=> $actual = $uut->where_file($relative_file, $test_script_dir, $include_dir)
'E:\User\SoftwareDiamonds\installation\t\File\t\File\Where.pm'

=> [@actual = $uut->where_dir($relative_dir1, \@inc2)]
[
          'E:\User\SoftwareDiamonds\installation\t\File\t\File',
          'E:\User\SoftwareDiamonds\installation\t\File',
          't\File'
        ]

=> [@actual = $uut->where_dir($relative_dir2, $test_script_dir)]
[
          'E:\User\SoftwareDiamonds\installation\t\File\t',
          'E:\User\SoftwareDiamonds\installation\t\File',
          't'
        ]

=> $actual = $uut->where_dir($relative_file)
'E:\User\SoftwareDiamonds\installation\t\File'

=> [@actual= $uut->where_pm( 't::File::Where' )]
[
          'E:\User\SoftwareDiamonds\installation\t\File\Where.pm',
          'E:\User\SoftwareDiamonds\installation',
          't\File\Where.pm'
        ]

=> $actual = $uut->where_pm( 't::File::Where', @inc2)
'E:\User\SoftwareDiamonds\installation\t\File\t\File\Where.pm'

=> [@actual= $uut->where_pm( 't::File::Where', [$test_script_dir])]
[
          'E:\User\SoftwareDiamonds\installation\t\File\t\File\Where.pm',
          'E:\User\SoftwareDiamonds\installation\t\File',
          't\File\Where.pm'
        ]

=> [@actual= $uut->where_repository( 't::File' )]
[
          'E:\User\SoftwareDiamonds\installation\t\File',
          'E:\User\SoftwareDiamonds\installation',
          't\File'
        ]

=> $actual = $uut->where_repository( 't::File', @inc2)
'E:\User\SoftwareDiamonds\installation\t\File\t\File'

=> [@actual= $uut->where_repository( 't::Jolly_Green_Giant', [$test_script_dir])]
[
          'E:\User\SoftwareDiamonds\installation\t\File\t',
          'E:\User\SoftwareDiamonds\installation\t\File',
          't'
        ]

=>    @INC = @restore_inc; #restore @INC;
=>    rmtree 't';

QUALITY ASSURANCE

Running the test script 'PM2File.t' found in the "File-PM2File-$VERSION.tar.gz" distribution file verifies the requirements for this module.

All testing software and documentation stems from the Software Test Description (STD) program module 't::File::PM2File', found in the distribution file "File-PM2File-$VERSION.tar.gz".

The 't::File::PM2File' STD POD contains a tracebility matix between the requirements established above for this module, and the test steps identified by a 'ok' number from running the 'PM2File.t' test script.

The t::File::PM2File' STD program module '__DATA__' section contains the data to perform the following:

  • to generate the test script 'PM2File.t'

  • generate the tailored STD POD in the 't::File::PM2File' module,

  • generate the 'PM2File.d' demo script,

  • replace the POD demonstration section herein with the demo script 'PM2File.d' output, and

  • run the test script using Test::Harness with or without the verbose option,

To perform all the above, prepare and run the automation software as follows:

  • Install "Test_STDmaker-$VERSION.tar.gz" from one of the respositories only if it has not been installed:

    • http://www.softwarediamonds/packages/

    • http://www.perl.com/CPAN-local/authors/id/S/SO/SOFTDIA/

  • manually place the script tmake.pl in "Test_STDmaker-$VERSION.tar.gz' in the site operating system executable path only if it is not in the executable path

  • place the 't::File::PM2File' at the same level in the directory struture as the directory holding the 'File::PM2File' module

  • execute the following in any directory:

    tmake -test_verbose -replace -run -pm=t::File::PM2File

NOTES

FILES

The installation of the "File-PM2File-$VERSION.tar.gz" distribution file installs the 'Docs::Site_SVD::File_PM2File' SVD program module.

The __DATA__ data section of the 'Docs::Site_SVD::File_PM2File' contains all the necessary data to generate the POD section of 'Docs::Site_SVD::File_PM2File' and the "File-PM2File-$VERSION.tar.gz" distribution file.

To make use of the 'Docs::Site_SVD::File_PM2File' SVD program module, perform the following:

  • install "ExtUtils-SVDmaker-$VERSION.tar.gz" from one of the respositories only if it has not been installed:

    • http://www.softwarediamonds/packages/

    • http://www.perl.com/CPAN-local/authors/id/S/SO/SOFTDIA/

  • manually place the script vmake.pl in "ExtUtils-SVDmaker-$VERSION.tar.gz' in the site operating system executable path only if it is not in the executable path

  • Make any appropriate changes to the __DATA__ section of the 'Docs::Site_SVD::File_PM2File' module. For example, any changes to 'File::PM2File' will impact the at least 'Changes' field.

  • Execute the following:

    vmake readme_html all -pm=Docs::Site_SVD::File_PM2File

AUTHOR

The holder of the copyright and maintainer is

<support@SoftwareDiamonds.com>

Copyrighted (c) 2002 Software Diamonds

All Rights Reserved

BINDING REQUIREMENTS NOTICE

Binding requirements are indexed with the pharse 'shall[dd]' where dd is an unique number for each header section. This conforms to standard federal government practices, 490A ("3.2.3.6" in STD490A). In accordance with the License, Software Diamonds is not liable for any requirement, binding or otherwise.

LICENSE

Software Diamonds permits the redistribution and use in source and binary forms, with or without modification, provided that the following conditions are met:

  1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.

  2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.

SOFTWARE DIAMONDS, http::www.softwarediamonds.com, PROVIDES THIS SOFTWARE 'AS IS' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SOFTWARE DIAMONDS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING USE OF THIS SOFTWARE, EVEN IF ADVISED OF NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE POSSIBILITY OF SUCH DAMAGE.