X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=pod%2Fperltie.pod;h=665265818d398d9d02fc573823bc01d73367aec4;hb=a7ae9550f26a080556f67048e2697d3c5a20f9f4;hp=79a749e68a738e7671b509567a709a3a621f423c;hpb=a60c0954410db87be540ee8439afcd54350bbb8e;p=p5sagit%2Fp5-mst-13.2.git diff --git a/pod/perltie.pod b/pod/perltie.pod index 79a749e..6652658 100644 --- a/pod/perltie.pod +++ b/pod/perltie.pod @@ -23,7 +23,7 @@ Now you can. The tie() function binds a variable to a class (package) that will provide the implementation for access methods for that variable. Once this magic has been performed, accessing a tied variable automatically triggers -method calls in the proper class. All of the complexity of the class is +method calls in the proper class. The complexity of the class is hidden behind magic methods calls. The method names are in ALL CAPS, which is a convention that Perl uses to indicate that they're called implicitly rather than explicitly--just like the BEGIN() and END() @@ -603,9 +603,9 @@ or have auxiliary state to clean up. Here's a very simple function: =back -Note that functions such as keys() and values() may return huge array -values when used on large objects, like DBM files. You may prefer to -use the each() function to iterate over such. Example: +Note that functions such as keys() and values() may return huge lists +when used on large objects, like DBM files. You may prefer to use the +each() function to iterate over such. Example: # print out history file offsets use NDBM_File; @@ -620,8 +620,8 @@ use the each() function to iterate over such. Example: This is partially implemented now. A class implementing a tied filehandle should define the following -methods: TIEHANDLE, at least one of PRINT, PRINTF, READLINE, GETC, or READ, -and possibly DESTROY. +methods: TIEHANDLE, at least one of PRINT, PRINTF, WRITE, READLINE, GETC, +READ, and possibly CLOSE and DESTROY. It is especially useful when perl is embedded in some other program, where output to STDOUT and STDERR may have to be redirected in some @@ -641,6 +641,17 @@ hold some internal information. sub TIEHANDLE { print "\n"; my $i; bless \$i, shift } +=item WRITE this, LIST + +This method will be called when the handle is written to via the +C function. + + sub WRITE { + $r = shift; + my($buf,$len,$offset) = @_; + print "WRITE called, \$buf=$buf, \$len=$len, \$offset=$offset"; + } + =item PRINT this, LIST This method will be triggered every time the tied handle is printed to @@ -663,15 +674,18 @@ passed to the printf function. print sprintf($fmt, @_)."\n"; } -=item READ this LIST +=item READ this, LIST This method will be called when the handle is read from via the C or C functions. sub READ { - $r = shift; - my($buf,$len,$offset) = @_; - print "READ called, \$buf=$buf, \$len=$len, \$offset=$offset"; + my $self = shift; + my $$bufref = \$_[0]; + my(undef,$len,$offset) = @_; + print "READ called, \$buf=$bufref, \$len=$len, \$offset=$offset"; + # add to $$bufref, set $len to number of characters read + $len; } =item READLINE this @@ -679,7 +693,7 @@ or C functions. This method will be called when the handle is read from via . The method should return undef when there is no more data. - sub READLINE { $r = shift; "PRINT called $$r times\n"; } + sub READLINE { $r = shift; "READLINE called $$r times\n"; } =item GETC this @@ -687,6 +701,13 @@ This method will be called when the C function is called. sub GETC { print "Don't GETC, Get Perl"; return "a"; } +=item CLOSE this + +This method will be called when the handle is closed via the C +function. + + sub CLOSE { print "CLOSE called.\n" } + =item DESTROY this As with the other types of ties, this method will be called when the