package Something::That::Stores::Filehandles; use TB2::Mouse; use TB2::ThreadSafeFilehandleAccessor fh_accessors => [qw(this_fh that_fh)]; my $obj = Something::That::Stores::Filehandles->new( this_fh => \*STDOUT, that_fh => \*STDERR, ); use threads; use threads::shared; $obj = shared_clone($obj);
This provides accessors specially written so objects can store and access filehandles without storing them internally. This is necessary if the object is to be shared across threads.
All structures which are shared between threads must have all their internal values and objects also be shared. Filehandles cannot be shared. This presents a bit of a problem for TB2::Formatter objects which contain TB2::Streamer objects which contain a filehandle.
use TB2::ThreadSafeFilehandleAccessor fh_accessors => [@names];
This will create an accessor for each name in @names.
The main limitation is changes to the filehandles in a thread will not be shared across threads or with the parent.
The filehandles will not be cleaned up on object destruction. This may hold the filehandle open and prevent the file from being flushed to the disk until the process exits.
TB2::Streamer::Print is the main target for this.
To install Test::Simple, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Test::Simple
CPAN shell
perl -MCPAN -e shell install Test::Simple
For more information on module installation, please visit the detailed CPAN module installation guide.