Integrate against change 9670 aka perl-5.7.1
[p5sagit/p5-mst-13.2.git] / lib / PerlIO.pm
CommitLineData
1141d9f8 1package PerlIO;
2
3# Map layer name to package that defines it
4my %alias = (encoding => 'Encode');
5
6sub import
7{
8 my $class = shift;
9 while (@_)
10 {
11 my $layer = shift;
12 if (exists $alias{$layer})
13 {
14 $layer = $alias{$layer}
15 }
16 else
17 {
18 $layer = "${class}::$layer";
19 }
20 eval "require $layer";
21 warn $@ if $@;
22 }
23}
24
251;
26__END__
b3d30bf7 27
28=head1 NAME
29
7d3b96bb 30PerlIO - On demand loader for PerlIO layers and root of PerlIO::* name space
b3d30bf7 31
32=head1 SYNOPSIS
33
7d3b96bb 34 open($fh,">:crlf","my.txt")
35 open($fh,">:raw","his.jpg")
36
37 Shell:
38 PERLIO=perlio perl ....
b3d30bf7 39
40=head1 DESCRIPTION
41
42When an undefined layer 'foo' is encountered in an C<open> or C<binmode> layer
43specification then C code performs the equivalent of:
44
45 use PerlIO 'foo';
46
47The perl code in PerlIO.pm then attempts to locate a layer by doing
48
49 require PerlIO::foo;
50
51Otherwise the C<PerlIO> package is a place holder for additional PerLIO related
52functions.
53
7d3b96bb 54The following layers are currently defined:
b3d30bf7 55
7d3b96bb 56=over 4
57
58=item unix
59
60Low level layer which calls C<read>, C<write> and C<lseek> etc.
61
62=item stdio
63
64Layer which calls C<fread>, C<fwrite> and C<fseek>/C<ftell> etc.
65Note that as this is "real" stdio it will ignore any layers beneath it and
66got straight to the operating system via the C library as usual.
67
68=item perlio
69
70This is a re-implementation of "stdio-like" buffering written as a PerlIO "layer".
71As such it will call whatever layer is below it for its operations.
72
73=item crlf
74
75A layer which does CRLF to "\n" translation distinguishing "text" and "binary"
76files in the manner of MS-DOS and similar operating systems.
77
78=item utf8
79
80Declares that the stream accepts perl's internal encoding of characters.
81(Which really is UTF-8 on ASCII machines, but is UTF-EBCDIC on EBCDIC machines.)
82This allows any character perl can represent to be read from or written to the
83stream. The UTF-X encoding is chosen to render simple text parts (i.e.
84non-accented letters, digits and common punctuation) human readable in the
85encoded file.
86
87=item raw
88
89A pseudo-layer which performs two functions (which is messy, but necessary to
90maintain compatibility with non-PerLIO builds of perl and they way things
91have been documented elsewhere).
92
93Firstly it forces the file handle to be considered binary at that point
94in the layer stack,
95
96Secondly in prevents the IO system seaching back before it in the layer specification.
97Thus:
98
99 open($fh,":raw:perlio"),...)
100
101Forces the use of C<perlio> layer even if the platform default, or C<use open> default
102is something else (such as ":encoding(iso-8859-7)" ) which would interfere with
103binary nature of the stream.
b3d30bf7 104
7d3b96bb 105=back
106
107=head2 Defaults and how to override them
108
109If the platform is MS-DOS like and normally does CRLF to "\n" translation
110for text files then the default layers are :
111
112 unix crlf
113
114(The low level "unix" layer may be replaced by a platform specific low level layer.)
115
116Otherwise if C<Configure> found out how to do "fast" IO using system's stdio, then
117the default layers are :
118
119 unix stdio
120
121Otherwise the default layers are
122
123 unix perlio
124
125These defaults may change once perlio has been better tested and tuned.
126
127The default can be overridden by setting the environment variable PERLIO
128to a space separated list of layers (unix or platform low level layer is
129always pushed first).
130This can be used to see the effect of/bugs in the various layers e.g.
131
132 cd .../perl/t
133 PERLIO=stdio ./perl harness
134 PERLIO=perlio ./perl harness
135
136=head1 AUTHOR
137
138Nick Ing-Simmons E<lt>nick@ing-simmons.netE<gt>
139
140=head1 SEE ALSO
141
142L<perlfunc/"binmode">, L<perlfunc/"open">, L<perlunicode>, L<open>
143
144=cut
b3d30bf7 145