The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Thread::Task::Concurrent::Util - utility functions for threads::shared

SYNOPSIS

    use Thread::Task::Concurrent::Util qw(unshared_clone);

    $unshared_var = unshared_clone($shared_var);

DESCRIPTION

Thread::Task::Concurrent::Util provides utility functions for threads::shared.

SUBROUTINES

unshared_clone REF

unshared_clone takes a reference, and returns a UNshared version of its argument, performing a deep copy on any shared elements. Any unshared elements in the argument are used as is (i.e., they are not cloned).

  my $cpy = shared_clone({'foo' => [qw/foo bar baz/]});

  my $unshared_cpy = unshared_clone($cpy);

Object status (i.e., the class an object is blessed into) is also cloned. my $obj = {'foo' => [qw/foo bar baz/]}; bless($obj, 'Foo'); my $cpy = shared_clone($obj);

  my $unshared_cpy = unshared_clone($cpy);

This functionality comes in extremely handy for serialization purposes with e.g. YAML::XS. YAML::XS is not able to serialize shared variables with nested structures.

SEE ALSO

threads::shared, YAML::XS

AUTHOR

jw bargsten, <cpan at bargsten dot org>

ACKNOWLEDGEMENTS

Thanks to the authors of the module threads::shared form which the code was borrowed.

LICENSE

Thread::Task::Concurrent::Util is released under the same license as Perl.