=back
-=head1 INTERNAL SUBROUTINES
-
-The following functions are not considered to be part of the public interface.
-They are documented here for the benefit of future maintainers of this module.
-
-=head2 C<standard_typemap_locations()>
-
-=over 4
-
-=item * Purpose
-
-Provide a list of directories in which to search for F<typemap> files. The
-directories appear in this list in lowest-to-highest priority. The lowest
-priority directories are directories named F<ExtUtils> which are
-subdirectories of directories found in C<@INC> -- provided a file named
-F<typemap> actually exists in such a directory. The highest priority
-directory is the current directory. The second highest priority directory is
-the parent of the current directory. The third highest priority directory is
-a directory called F<lib/ExtUtils> underneath the parent directory. And so
-forth for three more upward levels. This results in a list like this:
-
- '/usr/local/lib/perl5/5.10.1/ExtUtils/typemap',
- '../../../../lib/ExtUtils/typemap',
- '../../../../typemap',
- '../../../lib/ExtUtils/typemap',
- '../../../typemap',
- '../../lib/ExtUtils/typemap',
- '../../typemap',
- '../lib/ExtUtils/typemap',
- '../typemap',
- 'typemap'
-
-=item * Arguments
-
- my @stl = standard_typemap_locations( \@INC );
-
-Reference to C<@INC>.
-
-=item * Return Value
-
-Array holding list of directories to be searched for F<typemap> files.
-
-=back
-
=head1 AUTHOR
Based on xsubpp code, written by Larry Wall.
use strict;
use warnings;
use Exporter;
+use File::Spec;
our (@ISA, @EXPORT_OK);
@ISA = qw(Exporter);
@EXPORT_OK = qw(
standard_typemap_locations
);
+=head1 NAME
+
+ExtUtils::ParseXS::Utilities - Subroutines used with ExtUtils::ParseXS
+
+=head1 SYNOPSIS
+
+ use ExtUtils::ParseXS::Utilities qw(
+ standard_typemap_locations
+ );
+
+=head1 SUBROUTINES
+
+The following functions are not considered to be part of the public interface.
+They are documented here for the benefit of future maintainers of this module.
+
+=head2 C<standard_typemap_locations()>
+
+=over 4
+
+=item * Purpose
+
+Provide a list of filepaths where F<typemap> files may be found. The
+filepaths -- relative paths to files (not just directory paths) -- appear in this list in lowest-to-highest priority.
+
+The highest priority is to look in the current directory.
+
+ 'typemap'
+
+The second and third highest priorities are to look in the parent of the
+current directory and a directory called F<lib/ExtUtils> underneath the parent
+directory.
+
+ '../typemap',
+ '../lib/ExtUtils/typemap',
+
+The fourth through ninth highest priorities are to look in the corresponding
+grandparent, great-grandparent and great-great-grandparent directories.
+
+ '../../typemap',
+ '../../lib/ExtUtils/typemap',
+ '../../../typemap',
+ '../../../lib/ExtUtils/typemap',
+ '../../../../typemap',
+ '../../../../lib/ExtUtils/typemap',
+
+The tenth and subsequent priorities are to look in directories named
+F<ExtUtils> which are subdirectories of directories found in C<@INC> --
+I<provided> a file named F<typemap> actually exists in such a directory.
+Example:
+
+ '/usr/local/lib/perl5/5.10.1/ExtUtils/typemap',
+
+However, these filepaths appear in the list returned by
+C<standard_typemap_locations()> in reverse order, I<i.e.>, lowest-to-highest.
+
+ '/usr/local/lib/perl5/5.10.1/ExtUtils/typemap',
+ '../../../../lib/ExtUtils/typemap',
+ '../../../../typemap',
+ '../../../lib/ExtUtils/typemap',
+ '../../../typemap',
+ '../../lib/ExtUtils/typemap',
+ '../../typemap',
+ '../lib/ExtUtils/typemap',
+ '../typemap',
+ 'typemap'
+
+=item * Arguments
+
+ my @stl = standard_typemap_locations( \@INC );
+
+Reference to C<@INC>.
+
+=item * Return Value
+
+Array holding list of directories to be searched for F<typemap> files.
+
+=back
+
+=cut
+
sub standard_typemap_locations {
my $include_ref = shift;
- # Add all the default typemap locations to the search path
my @tm = qw(typemap);
- my $updir = File::Spec->updir;
- foreach my $dir (File::Spec->catdir(($updir) x 1), File::Spec->catdir(($updir) x 2),
- File::Spec->catdir(($updir) x 3), File::Spec->catdir(($updir) x 4)) {
-
+ my $updir = File::Spec->updir();
+ foreach my $dir (
+ File::Spec->catdir(($updir) x 1),
+ File::Spec->catdir(($updir) x 2),
+ File::Spec->catdir(($updir) x 3),
+ File::Spec->catdir(($updir) x 4),
+ ) {
unshift @tm, File::Spec->catfile($dir, 'typemap');
unshift @tm, File::Spec->catfile($dir, lib => ExtUtils => 'typemap');
}
--- /dev/null
+#!/usr/bin/perl
+use strict;
+use warnings;
+use Test::More tests => 3;
+use lib qw( lib );
+use ExtUtils::ParseXS::Utilities qw(
+ standard_typemap_locations
+);
+
+{
+ local @INC = @INC;
+ my @stl = standard_typemap_locations( \@INC );
+ ok( @stl >= 9, "At least 9 entries in typemap locations list" );
+ is( $stl[$#stl], 'typemap',
+ "Last element is typemap in current directory");
+ SKIP: {
+ skip "No lib/ExtUtils/ directories under directories in \@INC",
+ 1
+ unless @stl > 9;
+ ok( -f $stl[-10],
+ "At least one typemap file exists underneath \@INC directories"
+ );
+ }
+}
+