Data::COW - clone deep data structures copy-on-write
my $array = [ 0, 1, 2 ];
my $copy = make_cow_ref $array;
push @$array, 3;
# $copy-> is 3
push @$copy, 4;
# $array-> is not defined (and doesn't even exist)
# $copy is a real copy now
push @$array, 5;
# $copy is unaffected
Data::COW makes copies of data structures copy-on-write, or "lazily". So if you have a data structure that takes up ten megs of memory, it doesn't take ten megs to copy it. Even if you change part of it, Data::COW only copies the parts that need to be copied in order to reflect the change.
Data::COW exports one function: make_cow_ref. This takes a reference and returns a copy-on-write reference to it. If you don't want this in your namespace, and you want to use it as Data::COW::make_cow_ref, use the module like this:
use Data::COW ();
Data::COW won't be able to copy filehandles or glob references. But how do you change those anyway? It's also probably a bad idea to give it objects that refer to XS internal state without providing a value type interface. Also, don't use stringified references from this data structure: they're different each time you access them!
Luke Palmer <email@example.com>
Copyright (C) 2005 by Luke Palmer
This library is free software; you can redistribute it and/or modify it under
the same terms as Perl itself, either Perl version 5.8.3 or, at your option,
any later version of Perl 5 you may have available.
To install Data::COW, copy and paste the appropriate command in to your terminal.
perl -MCPAN -e shell
For more information on module installation, please visit the detailed CPAN module installation guide.