Initial commit of OpenSPARC T2 design and verification files.
[OpenSPARC-T2-DV] / tools / perl-5.8.0 / man / man3 / PerlIO::via.3
CommitLineData
86530b38
AT
1.\" Automatically generated by Pod::Man v1.34, Pod::Parser v1.13
2.\"
3.\" Standard preamble:
4.\" ========================================================================
5.de Sh \" Subsection heading
6.br
7.if t .Sp
8.ne 5
9.PP
10\fB\\$1\fR
11.PP
12..
13.de Sp \" Vertical space (when we can't use .PP)
14.if t .sp .5v
15.if n .sp
16..
17.de Vb \" Begin verbatim text
18.ft CW
19.nf
20.ne \\$1
21..
22.de Ve \" End verbatim text
23.ft R
24.fi
25..
26.\" Set up some character translations and predefined strings. \*(-- will
27.\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left
28.\" double quote, and \*(R" will give a right double quote. | will give a
29.\" real vertical bar. \*(C+ will give a nicer C++. Capital omega is used to
30.\" do unbreakable dashes and therefore won't be available. \*(C` and \*(C'
31.\" expand to `' in nroff, nothing in troff, for use with C<>.
32.tr \(*W-|\(bv\*(Tr
33.ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p'
34.ie n \{\
35. ds -- \(*W-
36. ds PI pi
37. if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch
38. if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch
39. ds L" ""
40. ds R" ""
41. ds C` ""
42. ds C' ""
43'br\}
44.el\{\
45. ds -- \|\(em\|
46. ds PI \(*p
47. ds L" ``
48. ds R" ''
49'br\}
50.\"
51.\" If the F register is turned on, we'll generate index entries on stderr for
52.\" titles (.TH), headers (.SH), subsections (.Sh), items (.Ip), and index
53.\" entries marked with X<> in POD. Of course, you'll have to process the
54.\" output yourself in some meaningful fashion.
55.if \nF \{\
56. de IX
57. tm Index:\\$1\t\\n%\t"\\$2"
58..
59. nr % 0
60. rr F
61.\}
62.\"
63.\" For nroff, turn off justification. Always turn off hyphenation; it makes
64.\" way too many mistakes in technical documents.
65.hy 0
66.if n .na
67.\"
68.\" Accent mark definitions (@(#)ms.acc 1.5 88/02/08 SMI; from UCB 4.2).
69.\" Fear. Run. Save yourself. No user-serviceable parts.
70. \" fudge factors for nroff and troff
71.if n \{\
72. ds #H 0
73. ds #V .8m
74. ds #F .3m
75. ds #[ \f1
76. ds #] \fP
77.\}
78.if t \{\
79. ds #H ((1u-(\\\\n(.fu%2u))*.13m)
80. ds #V .6m
81. ds #F 0
82. ds #[ \&
83. ds #] \&
84.\}
85. \" simple accents for nroff and troff
86.if n \{\
87. ds ' \&
88. ds ` \&
89. ds ^ \&
90. ds , \&
91. ds ~ ~
92. ds /
93.\}
94.if t \{\
95. ds ' \\k:\h'-(\\n(.wu*8/10-\*(#H)'\'\h"|\\n:u"
96. ds ` \\k:\h'-(\\n(.wu*8/10-\*(#H)'\`\h'|\\n:u'
97. ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'^\h'|\\n:u'
98. ds , \\k:\h'-(\\n(.wu*8/10)',\h'|\\n:u'
99. ds ~ \\k:\h'-(\\n(.wu-\*(#H-.1m)'~\h'|\\n:u'
100. ds / \\k:\h'-(\\n(.wu*8/10-\*(#H)'\z\(sl\h'|\\n:u'
101.\}
102. \" troff and (daisy-wheel) nroff accents
103.ds : \\k:\h'-(\\n(.wu*8/10-\*(#H+.1m+\*(#F)'\v'-\*(#V'\z.\h'.2m+\*(#F'.\h'|\\n:u'\v'\*(#V'
104.ds 8 \h'\*(#H'\(*b\h'-\*(#H'
105.ds o \\k:\h'-(\\n(.wu+\w'\(de'u-\*(#H)/2u'\v'-.3n'\*(#[\z\(de\v'.3n'\h'|\\n:u'\*(#]
106.ds d- \h'\*(#H'\(pd\h'-\w'~'u'\v'-.25m'\f2\(hy\fP\v'.25m'\h'-\*(#H'
107.ds D- D\\k:\h'-\w'D'u'\v'-.11m'\z\(hy\v'.11m'\h'|\\n:u'
108.ds th \*(#[\v'.3m'\s+1I\s-1\v'-.3m'\h'-(\w'I'u*2/3)'\s-1o\s+1\*(#]
109.ds Th \*(#[\s+2I\s-2\h'-\w'I'u*3/5'\v'-.3m'o\v'.3m'\*(#]
110.ds ae a\h'-(\w'a'u*4/10)'e
111.ds Ae A\h'-(\w'A'u*4/10)'E
112. \" corrections for vroff
113.if v .ds ~ \\k:\h'-(\\n(.wu*9/10-\*(#H)'\s-2\u~\d\s+2\h'|\\n:u'
114.if v .ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'\v'-.4m'^\v'.4m'\h'|\\n:u'
115. \" for low resolution devices (crt and lpr)
116.if \n(.H>23 .if \n(.V>19 \
117\{\
118. ds : e
119. ds 8 ss
120. ds o a
121. ds d- d\h'-1'\(ga
122. ds D- D\h'-1'\(hy
123. ds th \o'bp'
124. ds Th \o'LP'
125. ds ae ae
126. ds Ae AE
127.\}
128.rm #[ #] #H #V #F C
129.\" ========================================================================
130.\"
131.IX Title "PerlIO::via 3"
132.TH PerlIO::via 3 "2002-06-01" "perl v5.8.0" "Perl Programmers Reference Guide"
133.SH "NAME"
134PerlIO::via \- Helper class for PerlIO layers implemented in perl
135.SH "SYNOPSIS"
136.IX Header "SYNOPSIS"
137.Vb 2
138\& use PerlIO::via::Layer;
139\& open($fh,"<:via(Layer)",...);
140.Ve
141.PP
142.Vb 2
143\& use Some::Other::Package;
144\& open($fh,">:via(Some::Other::Package)",...);
145.Ve
146.SH "DESCRIPTION"
147.IX Header "DESCRIPTION"
148The PerlIO::via module allows you to develop PerlIO layers in Perl, without
149having to go into the nitty gritty of programming C with \s-1XS\s0 as the interface
150to Perl.
151.PP
152One example module, PerlIO::via::QuotedPrint, is included with Perl
1535.8.0, and more example modules are available from \s-1CPAN\s0, such as
154PerlIO::via::StripHTML and PerlIO::via::Base64. The
155PerlIO::via::StripHTML module for instance, allows you to say:
156.PP
157.Vb 3
158\& use PerlIO::via::StripHTML;
159\& open( my $fh, "<:via(StripHTML)", "index.html" );
160\& my @line = <$fh>;
161.Ve
162.PP
163to obtain the text of an HTML-file in an array with all the HTML-tags
164automagically removed.
165.PP
166Please note that if the layer is created in the PerlIO::via:: namespace, it
167does \fBnot\fR have to be fully qualified. The PerlIO::via module will prefix
168the PerlIO::via:: namespace if the specified modulename does not exist as a
169fully qualified module name.
170.SH "EXPECTED METHODS"
171.IX Header "EXPECTED METHODS"
172To create a Perl module that implements a PerlIO layer in Perl (as opposed to
173in C using \s-1XS\s0 as the interface to Perl), you need to supply some of the
174following subroutines. It is recommended to create these Perl modules in the
175PerlIO::via:: namespace, so that they can easily be located on \s-1CPAN\s0 and use
176the default namespace feature of the PerlIO::via module itself.
177.PP
178Please note that this is an area of recent development in Perl and that the
179interface described here is therefore still subject to change (and hopefully
180will have better documentation and more examples).
181.PP
182In the method descriptions below \fI$fh\fR will be
183a reference to a glob which can be treated as a perl file handle.
184It refers to the layer below. \fI$fh\fR is not passed if the layer
185is at the bottom of the stack, for this reason and to maintain
186some level of \*(L"compatibility\*(R" with \s-1TIEHANDLE\s0 classes it is passed last.
187.IP "$class\->\s-1PUSHED\s0([$mode[,$fh]])" 4
188.IX Item "$class->PUSHED([$mode[,$fh]])"
189Should return an object or the class, or \-1 on failure. (Compare
190\&\s-1TIEHANDLE\s0.) The arguments are an optional mode string (\*(L"r\*(R", \*(L"w\*(R",
191\&\*(L"w+\*(R", ...) and a filehandle for the PerlIO layer below. Mandatory.
192.Sp
193When layer is pushed as part of an \f(CW\*(C`open\*(C'\fR call, \f(CW\*(C`PUSHED\*(C'\fR will be called
194\&\fIbefore\fR the actual open occurs whether than be via \f(CW\*(C`OPEN\*(C'\fR, \f(CW\*(C`SYSOPEN\*(C'\fR,
195\&\f(CW\*(C`FDOPEN\*(C'\fR or by letting lower layer do the open.
196.IP "$obj\->\s-1POPPED\s0([$fh])" 4
197.IX Item "$obj->POPPED([$fh])"
198Optional \- layer is about to be removed.
199.IP "$obj\->\s-1OPEN\s0($path,$mode[,$fh])" 4
200.IX Item "$obj->OPEN($path,$mode[,$fh])"
201Optional \- if not present lower layer does open.
202If present called for normal opens after layer is pushed.
203This function is subject to change as there is no easy way
204to get lower layer to do open and then regain control.
205.IP "$obj\->\s-1BINMODE\s0([,$fh])" 4
206.IX Item "$obj->BINMODE([,$fh])"
207Optional \- if not available layer is popped on binmode($fh) or when \f(CW\*(C`:raw\*(C'\fR
208is pushed. If present it should return 0 on success \-1 on error and undef
209to pop the layer.
210.IP "$obj\->\s-1FDOPEN\s0($fd[,$fh])" 4
211.IX Item "$obj->FDOPEN($fd[,$fh])"
212Optional \- if not present lower layer does open.
213If present called for opens which pass a numeric file
214descriptor after layer is pushed.
215This function is subject to change as there is no easy way
216to get lower layer to do open and then regain control.
217.IP "$obj\->\s-1SYSOPEN\s0($path,$imode,$perm,[,$fh])" 4
218.IX Item "$obj->SYSOPEN($path,$imode,$perm,[,$fh])"
219Optional \- if not present lower layer does open.
220If present called for sysopen style opens which pass a numeric mode
221and permissions after layer is pushed.
222This function is subject to change as there is no easy way
223to get lower layer to do open and then regain control.
224.IP "$obj\->\s-1FILENO\s0($fh)" 4
225.IX Item "$obj->FILENO($fh)"
226Returns a numeric value for Unix-like file descriptor. Return \-1 if
227there isn't one. Optional. Default is fileno($fh).
228.IP "$obj\->\s-1READ\s0($buffer,$len,$fh)" 4
229.IX Item "$obj->READ($buffer,$len,$fh)"
230Returns the number of octets placed in \f(CW$buffer\fR (must be less than or
231equal to \f(CW$len\fR). Optional. Default is to use \s-1FILL\s0 instead.
232.IP "$obj\->\s-1WRITE\s0($buffer,$fh)" 4
233.IX Item "$obj->WRITE($buffer,$fh)"
234Returns the number of octets from buffer that have been sucessfully written.
235.IP "$obj\->\s-1FILL\s0($fh)" 4
236.IX Item "$obj->FILL($fh)"
237Should return a string to be placed in the buffer. Optional. If not
238provided must provide \s-1READ\s0 or reject handles open for reading in
239\&\s-1PUSHED\s0.
240.IP "$obj\->\s-1CLOSE\s0($fh)" 4
241.IX Item "$obj->CLOSE($fh)"
242Should return 0 on success, \-1 on error.
243Optional.
244.IP "$obj\->\s-1SEEK\s0($posn,$whence,$fh)" 4
245.IX Item "$obj->SEEK($posn,$whence,$fh)"
246Should return 0 on success, \-1 on error.
247Optional. Default is to fail, but that is likely to be changed
248in future.
249.IP "$obj\->\s-1TELL\s0($fh)" 4
250.IX Item "$obj->TELL($fh)"
251Returns file postion.
252Optional. Default to be determined.
253.IP "$obj\->\s-1UNREAD\s0($buffer,$fh)" 4
254.IX Item "$obj->UNREAD($buffer,$fh)"
255Returns the number of octets from buffer that have been sucessfully
256saved to be returned on future \s-1FILL/READ\s0 calls. Optional. Default is
257to push data into a temporary layer above this one.
258.IP "$obj\->\s-1FLUSH\s0($fh)" 4
259.IX Item "$obj->FLUSH($fh)"
260Flush any buffered write data. May possibly be called on readable
261handles too. Should return 0 on success, \-1 on error.
262.IP "$obj\->\s-1SETLINEBUF\s0($fh)" 4
263.IX Item "$obj->SETLINEBUF($fh)"
264Optional. No return.
265.IP "$obj\->\s-1CLEARERR\s0($fh)" 4
266.IX Item "$obj->CLEARERR($fh)"
267Optional. No return.
268.IP "$obj\->\s-1ERROR\s0($fh)" 4
269.IX Item "$obj->ERROR($fh)"
270Optional. Returns error state. Default is no error until a mechanism
271to signal error (die?) is worked out.
272.IP "$obj\->\s-1EOF\s0($fh)" 4
273.IX Item "$obj->EOF($fh)"
274Optional. Returns end-of-file state. Default is function of return
275value of \s-1FILL\s0 or \s-1READ\s0.
276.SH "EXAMPLES"
277.IX Header "EXAMPLES"
278Check the PerlIO::via:: namespace on \s-1CPAN\s0 for examples of PerlIO layers
279implemented in Perl. To give you an idea how simple the implementation of
280a PerlIO layer can look, as simple example is included here.
281.Sh "Example \- a Hexadecimal Handle"
282.IX Subsection "Example - a Hexadecimal Handle"
283Given the following module, PerlIO::via::Hex :
284.PP
285.Vb 1
286\& package PerlIO::via::Hex;
287.Ve
288.PP
289.Vb 7
290\& sub PUSHED
291\& {
292\& my ($class,$mode,$fh) = @_;
293\& # When writing we buffer the data
294\& my $buf = '';
295\& return bless \e$buf,$class;
296\& }
297.Ve
298.PP
299.Vb 6
300\& sub FILL
301\& {
302\& my ($obj,$fh) = @_;
303\& my $line = <$fh>;
304\& return (defined $line) ? pack("H*", $line) : undef;
305\& }
306.Ve
307.PP
308.Vb 6
309\& sub WRITE
310\& {
311\& my ($obj,$buf,$fh) = @_;
312\& $$obj .= unpack("H*", $buf);
313\& return length($buf);
314\& }
315.Ve
316.PP
317.Vb 7
318\& sub FLUSH
319\& {
320\& my ($obj,$fh) = @_;
321\& print $fh $$obj or return -1;
322\& $$obj = '';
323\& return 0;
324\& }
325.Ve
326.PP
327.Vb 1
328\& 1;
329.Ve
330.PP
331the following code opens up an output handle that will convert any
332output to hexadecimal dump of the output bytes: for example \*(L"A\*(R" will
333be converted to \*(L"41\*(R" (on ASCII-based machines, on \s-1EBCDIC\s0 platforms
334the \*(L"A\*(R" will become \*(L"c1\*(R")
335.PP
336.Vb 2
337\& use PerlIO::via::Hex;
338\& open(my $fh, ">:via(Hex)", "foo.hex");
339.Ve
340.PP
341and the following code will read the hexdump in and convert it
342on the fly back into bytes:
343.PP
344.Vb 1
345\& open(my $fh, "<:via(Hex)", "foo.hex");
346.Ve