.\" Automatically generated by Pod::Man 4.14 (Pod::Simple 3.43) .\" .\" Standard preamble: .\" ======================================================================== .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" Set up some character translations and predefined strings. \*(-- will .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left .\" double quote, and \*(R" will give a right double quote. \*(C+ will .\" give a nicer C++. Capital omega is used to do unbreakable dashes and .\" therefore won't be available. \*(C` and \*(C' expand to `' in nroff, .\" nothing in troff, for use with C<>. .tr \(*W- .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p' .ie n \{\ . ds -- \(*W- . ds PI pi . if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch . if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch . ds L" "" . ds R" "" . ds C` "" . ds C' "" 'br\} .el\{\ . ds -- \|\(em\| . ds PI \(*p . ds L" `` . ds R" '' . ds C` . ds C' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" .\" If the F register is >0, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .\" .\" Avoid warning from groff about undefined register 'F'. .de IX .. .nr rF 0 .if \n(.g .if rF .nr rF 1 .if (\n(rF:(\n(.g==0)) \{\ . if \nF \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{\ . nr % 0 . nr F 2 . \} . \} .\} .rr rF .\" ======================================================================== .\" .IX Title "Test::MockFile::FileHandle 3pm" .TH Test::MockFile::FileHandle 3pm "2023-02-04" "perl v5.36.0" "User Contributed Perl Documentation" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l .nh .SH "NAME" Test::MockFile::FileHandle \- Provides a class for Test::MockFile to tie to on open or sysopen. .SH "VERSION" .IX Header "VERSION" Version 0.035 .SH "SYNOPSIS" .IX Header "SYNOPSIS" This is a helper class for Test::MockFile. It leverages data in the Test::MockFile namespace but lives in its own package since it is the class that file handles are tied to when created in Test::MockFile .PP .Vb 2 \& use Test::MockFile::FileHandle; \& tie *{ $_[0] }, \*(AqTest::MockFile::FileHandle\*(Aq, $abs_path, $rw; .Ve .SH "EXPORT" .IX Header "EXPORT" No exports are provided by this module. .SH "SUBROUTINES/METHODS" .IX Header "SUBROUTINES/METHODS" .SS "\s-1TIEHANDLE\s0" .IX Subsection "TIEHANDLE" Args: ($class, \f(CW$file\fR, \f(CW$mode\fR) .PP Returns a blessed object for Test::MockFile to tie against. There are no error conditions handled here. .PP One of the object variables tracked here is a pointer to the file contents in \f(CW%Test::MockFile::files_being_mocked\fR. In order to allow MockFiles to be \s-1DESTROYED\s0 when they go out of scope, we have to weaken this pointer. .PP See Test::MockFile for more info. .SS "\s-1PRINT\s0" .IX Subsection "PRINT" This method will be triggered every time the tied handle is printed to with the \fBprint()\fR or \fBsay()\fR functions. Beyond its self reference it also expects the list that was passed to the print function. .PP We append to \&\f(CW\*(C`$Test::MockFile::files_being_mocked{$file}\-\*(C'\fR{'contents'}> with what was sent. If the file handle wasn't opened in a read mode, then this call with throw \s-1EBADF\s0 via $! .SS "\s-1PRINTF\s0" .IX Subsection "PRINTF" This method will be triggered every time the tied handle is printed to with the \fBprintf()\fR function. Beyond its self reference it also expects the format and list that was passed to the printf function. .PP We use sprintf to format the output and then it is sent to \s-1PRINT\s0 .SS "\s-1WRITE\s0" .IX Subsection "WRITE" This method will be called when the handle is written to via the syswrite function. .PP Arguments passed are:\f(CW\*(C`( $self, $buf, $len, $offset )\*(C'\fR .PP This is one of the more complicated functions to mimic properly because \&\f(CW$len\fR and \f(CW$offset\fR have to be taken into account. Reviewing how syswrite works reveals there are all sorts of weird corner cases. .SS "\s-1READLINE\s0" .IX Subsection "READLINE" This method is called when the handle is read via <\s-1HANDLE\s0> or readline \&\s-1HANDLE.\s0 .PP Based on the numeric location we are in the file (tell), we read until the \s-1EOF\s0 separator (\f(CW$/\fR) is seen. tell is updated after the line is read. undef is returned if tell is already at \s-1EOF.\s0 .SS "\s-1GETC\s0" .IX Subsection "GETC" \&\fB\s-1UNIMPLEMENTED\s0\fR: Open a ticket in github if you need this feature. .PP This method will be called when the getc function is called. It reads 1 character out of contents and adds 1 to tell. The character is returned. .SS "\s-1READ\s0" .IX Subsection "READ" Arguments passed are:\f(CW\*(C`( $self, $file_handle, $len, $offset )\*(C'\fR .PP This method will be called when the handle is read from via the read or sysread functions. Based on \f(CW$offset\fR and \f(CW$len\fR, it's possible to end up with some really weird strings with null bytes in them. .SS "\s-1CLOSE\s0" .IX Subsection "CLOSE" This method will be called when the handle is closed via the close function. The object is untied and the file contents (weak reference) is removed. Further calls to this object should fail. .SS "\s-1UNTIE\s0" .IX Subsection "UNTIE" As with the other types of ties, this method will be called when untie happens. It may be appropriate to \*(L"auto \s-1CLOSE\*(R"\s0 when this occurs. See The untie Gotcha below. .PP What's strange about the development of this class is that we were unable to determine how to trigger this call. At the moment, the call is just redirected to \s-1CLOSE.\s0 .SS "\s-1DESTROY\s0" .IX Subsection "DESTROY" As with the other types of ties, this method will be called when the tied handle is about to be destroyed. This is useful for debugging and possibly cleaning up. .PP At the moment, the call is just redirected to \s-1CLOSE.\s0 .SS "\s-1EOF\s0" .IX Subsection "EOF" This method will be called when the eof function is called. Based on \&\f(CW\*(C`$self\->{\*(Aqtell\*(Aq}\*(C'\fR, we determine if we're at \s-1EOF.\s0 .SS "\s-1BINMODE\s0" .IX Subsection "BINMODE" Binmode does nothing as whatever format you put the data into the file as is how it will come out. Possibly we could decode the \s-1SV\s0 if this was done but then we'd have to do it every time contents are altered. Please open a ticket if you want this to do something. .PP No perldoc documentation exists on this method. .SS "\s-1OPEN\s0" .IX Subsection "OPEN" \&\fB\s-1UNIMPLEMENTED\s0\fR: Open a ticket in github if you need this feature. .PP No perldoc documentation exists on this method. .SS "\s-1FILENO\s0" .IX Subsection "FILENO" \&\fB\s-1UNIMPLEMENTED\s0\fR: Open a ticket in github if you need this feature. .PP No perldoc documentation exists on this method. .SS "\s-1SEEK\s0" .IX Subsection "SEEK" Arguments passed are:\f(CW\*(C`( $self, $pos, $whence )\*(C'\fR .PP Moves the location of our current tell location. .PP \&\fB\f(CB$whence\fB is \s-1UNIMPLEMENTED\s0\fR: Open a ticket in github if you need this feature. .PP No perldoc documentation exists on this method. .SS "\s-1TELL\s0" .IX Subsection "TELL" Returns the numeric location we are in the file. The \f(CW\*(C`TELL\*(C'\fR tells us where we are in the file contents. .PP No perldoc documentation exists on this method.