This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Change TrimWhitespace() to trim_whitespace()
[perl5.git] / dist / ExtUtils-ParseXS / lib / ExtUtils / ParseXS / Utilities.pm
CommitLineData
a65c06db
S
1package ExtUtils::ParseXS::Utilities;
2use strict;
3use warnings;
4use Exporter;
f3aadd09 5use File::Spec;
a65c06db
S
6our (@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
15ExtUtils::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
26The following functions are not considered to be part of the public interface.
27They 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
35Provide a list of filepaths where F<typemap> files may be found. The
36filepaths -- relative paths to files (not just directory paths) -- appear in this list in lowest-to-highest priority.
37
38The highest priority is to look in the current directory.
39
40 'typemap'
41
42The second and third highest priorities are to look in the parent of the
43current directory and a directory called F<lib/ExtUtils> underneath the parent
44directory.
45
46 '../typemap',
47 '../lib/ExtUtils/typemap',
48
49The fourth through ninth highest priorities are to look in the corresponding
50grandparent, 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
59The tenth and subsequent priorities are to look in directories named
60F<ExtUtils> which are subdirectories of directories found in C<@INC> --
61I<provided> a file named F<typemap> actually exists in such a directory.
62Example:
63
64 '/usr/local/lib/perl5/5.10.1/ExtUtils/typemap',
65
66However, these filepaths appear in the list returned by
67C<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
84Reference to C<@INC>.
85
86=item * Return Value
87
88Array holding list of directories to be searched for F<typemap> files.
89
90=back
91
92=cut
93
a65c06db
S
94sub 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
121Perform an in-place trimming of leading and trailing whitespace from the
122first argument provided to the function.
123
124=item * Argument
125
126 trim_whitespace($arg);
127
128=item * Return Value
129
130None. Remember: this is an I<in-place> modification of the argument.
131
132=back
133
134=cut
135
136sub trim_whitespace {
137 $_[0] =~ s/^\s+|\s+$//go;
138}
139
a65c06db 1401;