Documentation for method
WRITE assembled from the following types:
multi method WRITE(|)
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
say) gets stored in the defined
IO::Store class. Two things should be taken into account in this class. By default,
IO::Handles 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.