DataStore::CAS::VirtualHandle - Handy base class for virtual filehandles
version 0.08
This class implements an API compatible with both IO::Handle and original-style GLOBREF handles. It acts as a proxy, passing all operations to the CAS instance which created it.
This object is a blessed globref, but it has a handy _data attribute which gives you access to the hash portion of the glob, so the CAS implementation can store per-handle details.
_data
See DataStore::CAS::Virtual for an example of how this is used, in the methods new_write_handle, _handle_write, _handle_seek, _handle_tell, and commit_write_handle.
new_write_handle
_handle_write
_handle_seek
_handle_tell
commit_write_handle
All methods normally pass through to the CAS that created it:
$handle->METHODNAME(@ARGS); # proxies to... $handle->_cas->_handle_METHODNAME($handle, @args)
thanks to AUTOLOAD. There are a few methods that have been given specific implementations though:
$handle= $class->new( $cas_instance, \%data ) # cas_instance is now found in $handle->cas # a shallow copy of %data is now found in $handle->_data
Creates a new VirtualHandle object. Blesses the globref and all that ugly stuff. Stores a reference to a CAS and some arbitrary fields for you.
The CAS instance this handle belongs to.
A hashref of arbitrary data the CAS owner wants to keep in this handle.
These methods all proxy to, or are implemented using read ($cas->_handle_read).
read
$cas->_handle_read
These methods all proxy to, or are implemented using getline ($cas->_handle_getline).
getline
$cas->_handle_getline
These methods all proxy to, or are implemented using write ($cas->_handle_write).
write
$cas->_handle_write
These methods return undef. (If you actually have a file descriptor, why would you need a virtual handle object?)
The Perl I/O abstraction.
But more specifically, you cannot yet use "Perl IO Layers" on these objects, because it appears I would have to re-implement the layers from scratch.
You also cannot use sysread/syswrite on them. (there doesn't appear to be any way to capture those calls with the TIE interface.)
These objects do not actually inherit from IO::Handle, because loading IO::Handle in a program that doesn't intend to use it is wasteful, and because it would make these objects appear to have methods which they don't support.
Michael Conrad <mconrad@intellitree.com>
This software is copyright (c) 2023 by Michael Conrad, and IntelliTree Solutions llc.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
To install DataStore::CAS, copy and paste the appropriate command in to your terminal.
cpanm
cpanm DataStore::CAS
CPAN shell
perl -MCPAN -e shell install DataStore::CAS
For more information on module installation, please visit the detailed CPAN module installation guide.