Test::...:Scalar(3pm)
π NAME π
Okay bestie, gather round, because this is Test::Builder::IO::Scalar β a whole copy of IO::Scalar that lives inside Test::Builder so you can use scalar references as filehandles. Yes, that's the entire job description. She's a copy. She's iconic. She's on section 3pm of your manual and she's not sorry.
β¨ DESCRIPTION β¨
So here's the tea: this is a copy of IO::Scalar that ships with Test::Builder specifically to support scalar references acting as filehandles on Perl 5.6. Newer versions of Perl? They literally just use open()'s built-in support, no drama, no middleman. π
And why is she a copy instead of a dependency? Because Test::Builder can not have dependencies on other modules without careful consideration, so the whole thing simply got copied into the distribution. That's it. That's the lore. π«Ά
π COPYRIGHT and LICENSE π
This file came from the "IO-stringy" Perl5 toolkit.
Copyright (c) 1996 by Eryq. All rights reserved. Copyright (c) 1999,2001 by ZeeGee Software Inc. All rights reserved.
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. Slay, honestly. π
πΈ Construction πΈ
new [ARGS...]β Class method, bestie. Returns a brand-new, unattached scalar handle. If you hand it any arguments, they get sent straight toopen().open [SCALARREF]β Instance method. Opens the scalar handle on a new scalar, pointed to by SCALARREF. If you don't pass a SCALARREF, a "private" scalar gets created to hold the file data.
Returns the self object on success, undefined on error. (So like, check it. π)
openedβ Instance method. Is the scalar handle opened on something? Yes/no, that's the whole vibe check.closeβ Instance method. Disassociates the scalar handle from its underlying scalar. This happens automatically on destroy, so she cleans up after herself. β¨
π¦ Input and output π¦
flushβ Instance method. No-op, provided for OO compatibility. She's just standing there, being compatible. πgetcβ Instance method. Returns the next character, orundefif none remain.getlineβ Instance method. Returns the next line, orundefon end of string. Can safely be called in an array context. Currently, lines are delimited by"\n".getlinesβ Instance method. Gets all remaining lines. It willcroak()if you accidentally call it in a scalar context, so don't do that, okay? πprint ARGS...β Instance method. Prints ARGS to the underlying scalar.
Warning: this continues to always cause a seek to the end of the string, but if you performseek()s andtell()s, it is still safer to explicitly seek-to-end before subsequentprint()s.
read BUF, NBYTES, [OFFSET]β Instance method. Reads some bytes from the scalar. Returns the number of bytes actually read,0on end-of-file,undefon error.write BUF, NBYTES, [OFFSET]β Instance method. Writes some bytes to the scalar.sysread BUF, LEN, [OFFSET]β Instance method. Reads some bytes from the scalar. Returns the number of bytes actually read,0on end-of-file,undefon error.syswrite BUF, NBYTES, [OFFSET]β Instance method. Writes some bytes to the scalar.
β Seeking/telling and other attributes β
autoflushβ Instance method. No-op, provided for OO compatibility.binmodeβ Instance method. No-op, provided for OO compatibility.clearerrβ Instance method. Clears the error and EOF flags. A no-op.eofβ Instance method. Are we at end of file? That's the question.seek OFFSET, WHENCEβ Instance method. Seeks to a given position in the stream.sysseek OFFSET, WHENCEβ Instance method. Identical toseek OFFSET, WHENCE, q.v.tellβ Instance method. Returns the current position in the stream, as a numeric offset.use_RS [YESNO]β Instance method. Deprecated and ignored. Should it obey the current setting of$/, likeIO::Handledoes? Default is false in 1.x, but cold-welded true in 2.x and later. (Yes, "cold-welded". We don't make the rules. π)setpos POSβ Instance method. Sets the current position, using the opaque value returned bygetpos().getposβ Instance method. Returns the current position in the string, as an opaque object.srefβ Instance method. Returns a reference to the underlying scalar. Bestie reveal. π«Ά
β οΈ WARNINGS β οΈ
Okay so, important lore: Perl's TIEHANDLE spec was incomplete prior to 5.005_57. It was missing support for seek(), tell(), and eof(). So attempting to use these functions with an IO::Scalar will not work prior to 5.005_57. IO::Scalar will not have the relevant methods invoked β and even worse, this kind of bug can lie dormant for a while. Sneaky. π
If you turn warnings on (via $^W or perl -w), and you see something like this...
attempt to seek on unopened filehandle
...then you are probably trying to use one of these functions on an IO::Scalar with an old Perl. The remedy is to simply use the OO version; e.g.:
$SH->seek(0,0); ### GOOD: will work on any 5.005
seek($SH,0,0); ### WARNING: will only work on 5.005_57 and beyond
Periodt. Use the OO one. π
π VERSION π
$Id: Scalar.pm,v 1.6 2005/02/10 21:21:53 dfs Exp $
π AUTHORS π
π Primary Maintainer
David F. Skoll (dfs@roaringpenguin.com).
π Principal author
Eryq (eryq@zeegee.com). President, ZeeGee Software Inc (http://www.zeegee.com).
π Other contributors
The full set of contributors always includes the folks mentioned in "CHANGE LOG" in IO::Stringy. But just the same, special thanks to the following individuals for their invaluable contributions (if I've forgotten or misspelled your name, please email me!):
- Andy Glew, for contributing
getc(). - Brandon Browning, for suggesting
opened(). - David Richter, for finding and fixing the bug in
PRINTF(). - Eric L. Brine, for his offset-using read() and write() implementations.
- Richard Jones, for his patches to massively improve the performance of
getline()and addsysreadandsyswrite. - B. K. Oxley (binkley), for stringification and inheritance improvements, and sundry good ideas.
- Doug Wilson, for the
IO::Handleinheritance and automatic tie-ing.
π§ SEE ALSO π§
IO::String, which is quite similar but which was designed more-recently and with anIO::Handle-like interface in mind, so you could mix OO- and native-filehandle usage without usingtied().
Note: as of version 2.x, these classes all work like theirIO::Handlecounterparts, so we have comparable functionality toIO::String.
And that's the whole page, bestie!! This came to you from perl v5.36.0, dated 2023-12-03, and yes, the manpage title up top is that very same Test::...:Scalar(3pm) situation you scrolled past. Go forth and tie your scalars. π
β¨π
π¦ where this page comes from
- ubuntu noble: libtest-simple-perl 1.302198-1 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms