TEST::BUILDER::IO::SCALAR(3perl)
π Test::Builder::IO::Scalar π
okay bestie, welcome to the manual page for Test::Builder::IO::Scalar, part of the Perl Programmers Reference Guide (that's the 3perl manual section, iykyk). sit down, grab a strawberry π, and let's get into it.
β¨ NAME β¨
Test::Builder::IO::Scalar β a copy of IO::Scalar for Test::Builder. literally just that. no cap.
πΈ DESCRIPTION πΈ
so this is a copy of IO::Scalar that ships inside Test::Builder, and the whole reason it exists is so you can use scalar references as filehandles on Perl 5.6. that's it, that's the job. newer versions of Perl just use open()'s built-in support for this and don't need it at all.
and why a copy instead of just depending on the module like a normal person? because Test::Builder can not have dependencies on other modules without careful consideration, so instead of going through all that, it's simply been copied into the distribution. iconic problem-solving honestly π
π 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.
π οΈ Construction π οΈ
new [ARGS...]β Class method. hands you back a brand new, unattached scalar handle. if you pass any arguments, they get sent straight toopen().open [SCALARREF]β Instance method. opens the scalar handle onto a new scalar, pointed to by SCALARREF. if you don't give it a SCALARREF, a "private" scalar gets created to hold the file data. returns the self object on success, and undefined on error.openedβ Instance method. is the scalar handle opened on something? yes/no, bestie.closeβ Instance method. disassociates the scalar handle from its underlying scalar. this also happens automatically on destroy, so no stress.
π₯ Input and output π€
flushβ Instance method. total no-op, it's just there for OO compatibility. it's giving decorative.getcβ Instance method. returns the next character, orundefif there aren't any left.getlineβ Instance method. returns the next line, orundefat end of string. totally safe to call in an array context. currently, lines are delimited by"\n".getlinesβ Instance method. grabs all remaining lines. it willcroak()if you accidentally call it in a scalar context β so don't do that. π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. so like. be careful. π
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? π₯Ί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. the original question was: obey the current setting of$/, likeIO::Handledoes? default is false in 1.x, but cold-welded true in 2.x and later.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.
π WARNINGS π
okay this part matters, so pay attention bestie.
Perl's TIEHANDLE spec was incomplete prior to 5.005_57; it was missing support for seek(), tell(), and eof(). 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. π³
so 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
β 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()andwrite()implementations. - Richard Jones, for his patches to massively improve the performance of
getline()and add"sysread"and"syswrite". - 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 an IO::Handle-like interface in mind, so you could mix OO- and native-filehandle usage without using tied().
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 was perl v5.40.1, dated 2026-06-12, straight out of the Test::...:Scalar(3perl) manual. go forth and scalar-handle responsibly. periodt. π
β¨
π¦ where this page comes from
- ubuntu questing: perl-doc 5.40.1-6ubuntu0.1
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms