@@ -64,94 +64,75 @@ They are documented here for the benefit of future maintainers of this module.
6464
6565=item * Purpose
6666
67- Provide a list of filepaths where F<typemap> files may be found. The
68- filepaths -- relative paths to files (not just directory paths) -- appear in this list in lowest-to-highest priority.
69-
70- The highest priority is to look in the current directory.
71-
72- 'typemap'
73-
74- The second and third highest priorities are to look in the parent of the
75- current directory and a directory called F<lib/ExtUtils> underneath the parent
76- directory.
77-
78- '../typemap',
79- '../lib/ExtUtils/typemap',
80-
81- The fourth through ninth highest priorities are to look in the corresponding
82- grandparent, great-grandparent and great-great-grandparent directories.
83-
84- '../../typemap',
85- '../../lib/ExtUtils/typemap',
86- '../../../typemap',
87- '../../../lib/ExtUtils/typemap',
88- '../../../../typemap',
89- '../../../../lib/ExtUtils/typemap',
90-
91- The tenth and subsequent priorities are to look in directories named
92- F<ExtUtils> which are subdirectories of directories found in C<@INC > --
93- I<provided > a file named F<typemap> actually exists in such a directory.
94- Example:
95-
96- '/usr/local/lib/perl5/5.10.1/ExtUtils/typemap',
97-
98- However, these filepaths appear in the list returned by
99- C<standard_typemap_locations() > in reverse order, I<i.e. > , lowest-to-highest.
100-
101- '/usr/local/lib/perl5/5.10.1/ExtUtils/typemap',
102- '../../../../lib/ExtUtils/typemap',
103- '../../../../typemap',
104- '../../../lib/ExtUtils/typemap',
105- '../../../typemap',
106- '../../lib/ExtUtils/typemap',
107- '../../typemap',
108- '../lib/ExtUtils/typemap',
109- '../typemap',
110- 'typemap'
67+ Returns a standard list of filepaths where F<typemap> files may be found.
68+ This will typically be something like:
69+
70+ map("$_/ExtUtils/typemap", reverse @INC),
71+ qw(
72+ ../../../../lib/ExtUtils/typemap
73+ ../../../../typemap
74+ ../../../lib/ExtUtils/typemap
75+ ../../../typemap
76+ ../../lib/ExtUtils/typemap
77+ ../../typemap
78+ ../lib/ExtUtils/typemap
79+ ../typemap
80+ typemap
81+ )
82+
83+ but the style of the pathnames may vary with OS. Note that the value to
84+ use for C<@INC > is passed as an array reference, and can be something
85+ other than C<@INC > itself.
86+
87+ Pathnames are returned in the order they are expected to be processed;
88+ this means that later files will update or override entries found in
89+ earlier files. So in particular, F<typemap> in the current directory has
90+ highest priority. C<@INC > is searched in reverse order so that earlier
91+ entries in C<@INC > are processed later and so have higher priority.
92+
93+ The values of C<-typemap > switches are not used here; they should be added
94+ by the caller to the list of pathnames returned by this function.
11195
11296=item * Arguments
11397
114- my @stl = standard_typemap_locations( \@INC );
98+ my @stl = standard_typemap_locations(\@INC);
11599
116- Reference to C<@INC > .
100+ A single argument: a reference to an array to use as if it were C<@INC > .
117101
118102=item * Return Value
119103
120- Array holding list of directories to be searched for F<typemap> files .
104+ A list of F<typemap> pathnames .
121105
122106=back
123107
124108=cut
125109
126- SCOPE: {
127- my @tm_template ;
110+ sub standard_typemap_locations {
111+ my $include_ref = shift ;
128112
129- sub standard_typemap_locations {
130- my $include_ref = shift ;
113+ my @tm ;
131114
132- if (not @tm_template ) {
133- @tm_template = qw( typemap) ;
134-
135- my $updir = File::Spec-> updir();
136- foreach my $dir (
137- File::Spec-> catdir(($updir ) x 1 ),
138- File::Spec-> catdir(($updir ) x 2 ),
139- File::Spec-> catdir(($updir ) x 3 ),
140- File::Spec-> catdir(($updir ) x 4 ),
141- ) {
142- unshift @tm_template , File::Spec-> catfile($dir , ' typemap' );
143- unshift @tm_template , File::Spec-> catfile($dir , lib => ExtUtils => ' typemap' );
144- }
145- }
115+ # See function description above for why 'reverse' is used here.
116+ foreach my $dir (reverse @{$include_ref }) {
117+ my $file = File::Spec-> catfile($dir , ExtUtils => ' typemap' );
118+ push @tm , $file ;
119+ }
146120
147- my @tm = @tm_template ;
148- foreach my $dir (@{ $include_ref }) {
149- my $file = File::Spec-> catfile($dir , ExtUtils => ' typemap' );
150- unshift @tm , $file if -e $file ;
151- }
152- return @tm ;
121+ my $updir = File::Spec-> updir();
122+ foreach my $dir (
123+ File::Spec-> catdir(($updir ) x 4 ),
124+ File::Spec-> catdir(($updir ) x 3 ),
125+ File::Spec-> catdir(($updir ) x 2 ),
126+ File::Spec-> catdir(($updir ) x 1 ),
127+ ) {
128+ push @tm , File::Spec-> catfile($dir , lib => ExtUtils => ' typemap' );
129+ push @tm , File::Spec-> catfile($dir , ' typemap' );
153130 }
154- } # end SCOPE
131+
132+ push @tm , ' typemap' ;
133+
134+ return @tm ;
135+ }
155136
156137=head2 C<trim_whitespace() >
157138
@@ -245,18 +226,21 @@ sub valid_proto_string {
245226
246227=item * Purpose
247228
248- Process all typemap files.
229+ Process all typemap files. Reads in any typemap files specified explicitly
230+ with C<-typemap > switches or similar, plus any typemap files found in
231+ standard locations relative to C<@INC > and the current directory.
249232
250233=item * Arguments
251234
252235 my $typemaps_object = process_typemaps( $args{typemap}, $pwd );
253236
254- List of two elements: C<typemap > element from C<%args > ; current working
255- directory.
237+ The first argument is the C<typemap > element from C<%args > ; the second is
238+ the current working directory (which is only needed for error messages) .
256239
257240=item * Return Value
258241
259- Upon success, returns an L<ExtUtils::Typemaps> object.
242+ Upon success, returns an L<ExtUtils::Typemaps> object which contains the
243+ accumulated results of all processed typemap files.
260244
261245=back
262246
@@ -265,13 +249,13 @@ Upon success, returns an L<ExtUtils::Typemaps> object.
265249sub process_typemaps {
266250 my ($tmap , $pwd ) = @_ ;
267251
268- my @tm = ref $tmap ? @{ $tmap } : ( $tmap );
252+ my @tm = standard_typemap_locations( \ @INC );
269253
270- foreach my $typemap (@tm ) {
254+ my @explicit = ref $tmap ? @{$tmap } : ($tmap );
255+ foreach my $typemap (@explicit ) {
271256 die " Can't find $typemap in $pwd \n " unless -r $typemap ;
272257 }
273-
274- push @tm , standard_typemap_locations( \@INC );
258+ push @tm , @explicit ;
275259
276260 require ExtUtils::Typemaps;
277261 my $typemap = ExtUtils::Typemaps-> new;
0 commit comments