Make the Class::Struct import() wiser.
[p5sagit/p5-mst-13.2.git] / lib / English.pm
CommitLineData
8990e307 1package English;
2
3require Exporter;
4@ISA = (Exporter);
5
f06db76b 6=head1 NAME
7
8English - use nice English (or awk) names for ugly punctuation variables
9
10=head1 SYNOPSIS
11
60ed1d8c 12 use English qw( -no_match_vars ) ; # Avoids regex performance penalty
f06db76b 13 use English;
14 ...
15 if ($ERRNO =~ /denied/) { ... }
16
17=head1 DESCRIPTION
18
19This module provides aliases for the built-in variables whose
20names no one seems to like to read. Variables with side-effects
21which get triggered just by accessing them (like $0) will still
22be affected.
23
24For those variables that have an B<awk> version, both long
25and short English alternatives are provided. For example,
26the C<$/> variable can be referred to either $RS or
27$INPUT_RECORD_SEPARATOR if you are using the English module.
28
29See L<perlvar> for a complete list of these.
30
60ed1d8c 31=head1 PERFORMANCE
f2545c07 32
60ed1d8c 33This module can provoke sizeable inefficiencies for regular expressions,
34due to unfortunate implementation details. If performance matters in
35your application and you don't need $PREMATCH, $MATCH, or $POSTMATCH,
36try doing
37
38 use English qw( -no_match_vars ) ;
39
40. B<It is especially important to do this in modules to avoid penalizing
41all applications which use them.>
f2545c07 42
f06db76b 43=cut
44
db376a24 45no warnings;
748a9306 46
60ed1d8c 47my $globbed_match ;
48
748a9306 49# Grandfather $NAME import
50sub import {
51 my $this = shift;
60ed1d8c 52 my @list = grep { ! /^-no_match_vars$/ } @_ ;
748a9306 53 local $Exporter::ExportLevel = 1;
60ed1d8c 54 if ( @_ == @list ) {
55 *EXPORT = \@COMPLETE_EXPORT ;
56 $globbed_match ||= (
57 eval q{
58 *MATCH = *& ;
59 *PREMATCH = *` ;
60 *POSTMATCH = *' ;
61 1 ;
62 }
63 || do {
64 require Carp ;
65 Carp::croak "Can't create English for match leftovers: $@" ;
66 }
67 ) ;
68 }
69 else {
70 *EXPORT = \@MINIMAL_EXPORT ;
71 }
748a9306 72 Exporter::import($this,grep {s/^\$/*/} @list);
73}
a0d0e21e 74
60ed1d8c 75@MINIMAL_EXPORT = qw(
8990e307 76 *ARG
748a9306 77 *LAST_PAREN_MATCH
78 *INPUT_LINE_NUMBER
79 *NR
80 *INPUT_RECORD_SEPARATOR
81 *RS
82 *OUTPUT_AUTOFLUSH
83 *OUTPUT_FIELD_SEPARATOR
84 *OFS
85 *OUTPUT_RECORD_SEPARATOR
86 *ORS
87 *LIST_SEPARATOR
88 *SUBSCRIPT_SEPARATOR
89 *SUBSEP
90 *FORMAT_PAGE_NUMBER
91 *FORMAT_LINES_PER_PAGE
92 *FORMAT_LINES_LEFT
93 *FORMAT_NAME
94 *FORMAT_TOP_NAME
95 *FORMAT_LINE_BREAK_CHARACTERS
96 *FORMAT_FORMFEED
97 *CHILD_ERROR
98 *OS_ERROR
99 *ERRNO
d57fa8b6 100 *EXTENDED_OS_ERROR
748a9306 101 *EVAL_ERROR
102 *PROCESS_ID
103 *PID
104 *REAL_USER_ID
105 *UID
106 *EFFECTIVE_USER_ID
107 *EUID
108 *REAL_GROUP_ID
109 *GID
110 *EFFECTIVE_GROUP_ID
111 *EGID
112 *PROGRAM_NAME
113 *PERL_VERSION
114 *ACCUMULATOR
115 *DEBUGGING
116 *SYSTEM_FD_MAX
117 *INPLACE_EDIT
118 *PERLDB
119 *BASETIME
120 *WARNING
121 *EXECUTABLE_NAME
d57fa8b6 122 *OSNAME
66558a10 123 *LAST_REGEXP_CODE_RESULT
124 *EXCEPTIONS_BEING_CAUGHT
fe307981 125 @LAST_MATCH_START
126 @LAST_MATCH_END
8990e307 127);
128
60ed1d8c 129
130@MATCH_EXPORT = qw(
131 *MATCH
132 *PREMATCH
133 *POSTMATCH
134);
135
136@COMPLETE_EXPORT = ( @MINIMAL_EXPORT, @MATCH_EXPORT ) ;
137
fb73857a 138# The ground of all being. @ARG is deprecated (5.005 makes @_ lexical)
8990e307 139
8990e307 140 *ARG = *_ ;
141
142# Matching.
143
748a9306 144 *LAST_PAREN_MATCH = *+ ;
fe307981 145 *LAST_MATCH_START = *-{ARRAY} ;
146 *LAST_MATCH_END = *+{ARRAY} ;
8990e307 147
148# Input.
149
748a9306 150 *INPUT_LINE_NUMBER = *. ;
151 *NR = *. ;
152 *INPUT_RECORD_SEPARATOR = */ ;
153 *RS = */ ;
8990e307 154
155# Output.
156
748a9306 157 *OUTPUT_AUTOFLUSH = *| ;
158 *OUTPUT_FIELD_SEPARATOR = *, ;
159 *OFS = *, ;
160 *OUTPUT_RECORD_SEPARATOR = *\ ;
161 *ORS = *\ ;
8990e307 162
163# Interpolation "constants".
164
748a9306 165 *LIST_SEPARATOR = *" ;
166 *SUBSCRIPT_SEPARATOR = *; ;
167 *SUBSEP = *; ;
8990e307 168
169# Formats
170
748a9306 171 *FORMAT_PAGE_NUMBER = *% ;
172 *FORMAT_LINES_PER_PAGE = *= ;
173 *FORMAT_LINES_LEFT = *- ;
174 *FORMAT_NAME = *~ ;
175 *FORMAT_TOP_NAME = *^ ;
176 *FORMAT_LINE_BREAK_CHARACTERS = *: ;
177 *FORMAT_FORMFEED = *^L ;
8990e307 178
179# Error status.
180
748a9306 181 *CHILD_ERROR = *? ;
4318d5a0 182 *OS_ERROR = *! ;
183 *ERRNO = *! ;
f86702cc 184 *EXTENDED_OS_ERROR = *^E ;
748a9306 185 *EVAL_ERROR = *@ ;
8990e307 186
187# Process info.
188
748a9306 189 *PROCESS_ID = *$ ;
190 *PID = *$ ;
191 *REAL_USER_ID = *< ;
192 *UID = *< ;
193 *EFFECTIVE_USER_ID = *> ;
194 *EUID = *> ;
195 *REAL_GROUP_ID = *( ;
196 *GID = *( ;
197 *EFFECTIVE_GROUP_ID = *) ;
198 *EGID = *) ;
199 *PROGRAM_NAME = *0 ;
8990e307 200
201# Internals.
202
44dcb63b 203 *PERL_VERSION = *^V ;
748a9306 204 *ACCUMULATOR = *^A ;
305aace0 205 *COMPILING = *^C ;
748a9306 206 *DEBUGGING = *^D ;
207 *SYSTEM_FD_MAX = *^F ;
208 *INPLACE_EDIT = *^I ;
209 *PERLDB = *^P ;
66558a10 210 *LAST_REGEXP_CODE_RESULT = *^R ;
211 *EXCEPTIONS_BEING_CAUGHT = *^S ;
748a9306 212 *BASETIME = *^T ;
213 *WARNING = *^W ;
214 *EXECUTABLE_NAME = *^X ;
d57fa8b6 215 *OSNAME = *^O ;
8990e307 216
217# Deprecated.
218
748a9306 219# *ARRAY_BASE = *[ ;
220# *OFMT = *# ;
221# *MULTILINE_MATCHING = ** ;
44dcb63b 222# *OLD_PERL_VERSION = *] ;
8990e307 223
2241;