Commit | Line | Data |
---|---|---|
a65c06db S |
1 | package ExtUtils::ParseXS::Utilities; |
2 | use strict; | |
3 | use warnings; | |
4 | use Exporter; | |
f3aadd09 | 5 | use File::Spec; |
a65c06db S |
6 | our (@ISA, @EXPORT_OK); |
7 | @ISA = qw(Exporter); | |
8 | @EXPORT_OK = qw( | |
9 | standard_typemap_locations | |
1d40e528 | 10 | trim_whitespace |
a65c06db S |
11 | ); |
12 | ||
f3aadd09 S |
13 | =head1 NAME |
14 | ||
15 | ExtUtils::ParseXS::Utilities - Subroutines used with ExtUtils::ParseXS | |
16 | ||
17 | =head1 SYNOPSIS | |
18 | ||
19 | use ExtUtils::ParseXS::Utilities qw( | |
20 | standard_typemap_locations | |
1d40e528 | 21 | trim_whitespace |
f3aadd09 S |
22 | ); |
23 | ||
24 | =head1 SUBROUTINES | |
25 | ||
26 | The following functions are not considered to be part of the public interface. | |
27 | They are documented here for the benefit of future maintainers of this module. | |
28 | ||
29 | =head2 C<standard_typemap_locations()> | |
30 | ||
31 | =over 4 | |
32 | ||
33 | =item * Purpose | |
34 | ||
35 | Provide a list of filepaths where F<typemap> files may be found. The | |
36 | filepaths -- relative paths to files (not just directory paths) -- appear in this list in lowest-to-highest priority. | |
37 | ||
38 | The highest priority is to look in the current directory. | |
39 | ||
40 | 'typemap' | |
41 | ||
42 | The second and third highest priorities are to look in the parent of the | |
43 | current directory and a directory called F<lib/ExtUtils> underneath the parent | |
44 | directory. | |
45 | ||
46 | '../typemap', | |
47 | '../lib/ExtUtils/typemap', | |
48 | ||
49 | The fourth through ninth highest priorities are to look in the corresponding | |
50 | grandparent, great-grandparent and great-great-grandparent directories. | |
51 | ||
52 | '../../typemap', | |
53 | '../../lib/ExtUtils/typemap', | |
54 | '../../../typemap', | |
55 | '../../../lib/ExtUtils/typemap', | |
56 | '../../../../typemap', | |
57 | '../../../../lib/ExtUtils/typemap', | |
58 | ||
59 | The tenth and subsequent priorities are to look in directories named | |
60 | F<ExtUtils> which are subdirectories of directories found in C<@INC> -- | |
61 | I<provided> a file named F<typemap> actually exists in such a directory. | |
62 | Example: | |
63 | ||
64 | '/usr/local/lib/perl5/5.10.1/ExtUtils/typemap', | |
65 | ||
66 | However, these filepaths appear in the list returned by | |
67 | C<standard_typemap_locations()> in reverse order, I<i.e.>, lowest-to-highest. | |
68 | ||
69 | '/usr/local/lib/perl5/5.10.1/ExtUtils/typemap', | |
70 | '../../../../lib/ExtUtils/typemap', | |
71 | '../../../../typemap', | |
72 | '../../../lib/ExtUtils/typemap', | |
73 | '../../../typemap', | |
74 | '../../lib/ExtUtils/typemap', | |
75 | '../../typemap', | |
76 | '../lib/ExtUtils/typemap', | |
77 | '../typemap', | |
78 | 'typemap' | |
79 | ||
80 | =item * Arguments | |
81 | ||
82 | my @stl = standard_typemap_locations( \@INC ); | |
83 | ||
84 | Reference to C<@INC>. | |
85 | ||
86 | =item * Return Value | |
87 | ||
88 | Array holding list of directories to be searched for F<typemap> files. | |
89 | ||
90 | =back | |
91 | ||
92 | =cut | |
93 | ||
a65c06db S |
94 | sub standard_typemap_locations { |
95 | my $include_ref = shift; | |
a65c06db S |
96 | my @tm = qw(typemap); |
97 | ||
f3aadd09 S |
98 | my $updir = File::Spec->updir(); |
99 | foreach my $dir ( | |
100 | File::Spec->catdir(($updir) x 1), | |
101 | File::Spec->catdir(($updir) x 2), | |
102 | File::Spec->catdir(($updir) x 3), | |
103 | File::Spec->catdir(($updir) x 4), | |
104 | ) { | |
a65c06db S |
105 | unshift @tm, File::Spec->catfile($dir, 'typemap'); |
106 | unshift @tm, File::Spec->catfile($dir, lib => ExtUtils => 'typemap'); | |
107 | } | |
108 | foreach my $dir (@{ $include_ref}) { | |
109 | my $file = File::Spec->catfile($dir, ExtUtils => 'typemap'); | |
110 | unshift @tm, $file if -e $file; | |
111 | } | |
112 | return @tm; | |
113 | } | |
114 | ||
1d40e528 JK |
115 | =head2 C<trim_whitespace()> |
116 | ||
117 | =over 4 | |
118 | ||
119 | =item * Purpose | |
120 | ||
121 | Perform an in-place trimming of leading and trailing whitespace from the | |
122 | first argument provided to the function. | |
123 | ||
124 | =item * Argument | |
125 | ||
126 | trim_whitespace($arg); | |
127 | ||
128 | =item * Return Value | |
129 | ||
130 | None. Remember: this is an I<in-place> modification of the argument. | |
131 | ||
132 | =back | |
133 | ||
134 | =cut | |
135 | ||
136 | sub trim_whitespace { | |
137 | $_[0] =~ s/^\s+|\s+$//go; | |
138 | } | |
139 | ||
a65c06db | 140 | 1; |