See Original text in context
method WRITE(IO::Handle: Blob \data --> Bool)
Called whenever a write operation is performed on the handle. Always receives the data as a Blob
, even if a textual writing method has been called.
is IO::Handlemy = IO::Store.new();my = ::OUT;::OUT = ;.say for <one two three>;::OUT = ;say .lines(); # OUTPUT: «[one two three]»
In this example we are creating a simple WRITE
redirection which stores anything written to the filehandle to an array. Se need to save the standard output first, which we do in $output
, and then everything that is print
ed or said (through say
) gets stored in the defined IO::Store
class. Two things should be taken into account in this class. By default, IO::Handle
s are in binary mode, so we need to TWEAK
the objects if we want them to work with text. Second, a WRITE
operation should return True
if successful. It will fail if it does not.
See Original text in context
multi method WRITE(|)
The IO::CatHandle type overrides this method to throw a X::NYI
exception. If you have a good idea for how this method should behave, tell Rakudo developers about it!