Clone::Choose(3)

πŸ’… Clone::Choose(3) β€” the perl-y "pick a clone backend" situation πŸ’…

okay so you're reading the manual for Clone::Choose, a User Contributed Perl Documentation page (yes bestie, we're in the Clone::Choose(3) section of the man pages, stay with me 🫢).


✨ NAME ✨

Clone::Choose β€” literally just "choose appropriate clone utility". That's the whole vibe. It picks the right clone tool for you so you don't have to πŸ’…


🌸 SYNOPSIS 🌸

here's the whole thing in action, no cap:

use Clone::Choose;

my $data = {
    value => 42,
    href  => {
        set   => [ 'foo', 'bar' ],
        value => 'baz',
    },
};

my $cloned_data = clone $data;

# it's also possible to use Clone::Choose and pass a clone preference
use Clone::Choose qw(:Storable);

see that? clone $data and boom, you got a copy. and yes, you can also use Clone::Choose with a clone preference if you're feeling picky πŸ‘‘


πŸ¦‹ DESCRIPTION πŸ¦‹

so Clone::Choose goes around checking several different modules that each provide a clone() function, and then it selects an appropriate one for you. it's giving "personal assistant but for Perl modules" ✨

the default preference order is, in this exact order:

Clone
Storable
Clone::PP

now β€” this list might evolve in future, so don't get too attached, okay? if you wanna pick a particular one yourself, the "EXPORTS" section has you covered πŸ’–


πŸŽ€ EXPORTS πŸŽ€

Clone::Choose exports clone() by default. free function, no questions asked 🫢

you can also explicitly import clone by using:

use Clone::Choose qw(clone);

or you can pick a particular clone implementation, like so:

use Clone::Choose qw(:Storable clone);

the exported implementation is resolved dynamically, which is the fancy way of saying: any module that uses this can either rely on the default backend preference, or choose a particular one. flexible. iconic. main character energy 🧚

you can also select a particular clone backend by setting the environment variable CLONE_CHOOSE_PREFERRED_BACKEND to whatever your preferred backend is. yup, that's the whole name, i know, it's long, drink some water πŸ’œ

this also means an already chosen import can't be modified afterwards, like:

use Clone::Choose qw(clone :Storable);

nope. not allowed. the vibes are already locked in πŸ™ˆ

when you seriously need different clone implementations at the same time, the recommended way to use them would be:

use Clone::Choose (); # do not import
my ($xs_clone, $st_clone);
{ local @Clone::Choose::BACKENDS = (Clone => "clone"); $xs_clone = Clone::Choose->can("clone"); }
{ local @Clone::Choose::BACKENDS = (Storable => "dclone"); $st_clone = Clone::Choose->can("clone"); }
🚨 okay bestie, warning time: don't misinterpret "recommended" here. modifying @Clone::Choose::BACKENDS has a lot of pitfalls and it is unreliable beside such small examples. like, fr fr. if you've got a better way, do not hesitate to open a request with an appropriate proposal for choosing implementations dynamically β€” they want your ideas πŸ’€

and straight up: the use of @Clone::Choose::BACKENDS is discouraged, and it will be deprecated as soon as anyone provides a better idea. so like... someone please provide a better idea? 😭


πŸ‘‘ PACKAGE METHODS πŸ‘‘

🌈 backend

backend tells the caller about the dynamically chosen backend. look:

use Clone::Choose;
say Clone::Choose->backend; # Clone

this method currently exists for debug purposes only. that's it. that's the whole method. tiny but mighty πŸ“

⭐ get_backends

get_backends returns a list of the currently supported backends. simple as. πŸ’–


🧚 AUTHOR 🧚

Jens Rehsack <rehsack at cpan dot org>
Stefan Hermes <hermes at cpan dot org>

shoutout to the authors, absolute legends, we stan πŸ‘‘


πŸ’€ BUGS πŸ’€

please report any bugs or feature requests to bug-Clone-Choose at rt.cpan.org, or through the web interface at <http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Clone-Choose>. "i" β€” meaning the author β€” will be notified, and then you'll automatically be notified of progress on your bug as changes get made. it's a whole notification circle of trust 😭


🌸 SUPPORT 🌸

you can find documentation for this module with the perldoc command:

perldoc Clone::Choose

you can also look for information at:

like four whole places to look. the internet is vast and full of Clone::Choose lore πŸ’…


Copyright 2017 Jens Rehsack
Copyright 2017 Stefan Hermes

this program is free software; you can redistribute it and/or modify it under the terms of either: the GNU General Public License as published by the Free Software Foundation; or the Artistic License. pick your fighter βš”οΈ

see <http://dev.perl.org/licenses/> for more information. go read the licenses, it's good for you 🫢


πŸ’œ SEE ALSO πŸ’œ

Clone, Clone::PP, Storable β€” the whole squad, go say hi ✨


and that's the page, bestie πŸŽ€ β€” brought to you by perl v5.42.0, dated 2018-10-09, signing off from the Clone::Choose(3) corner of the man page universe. slay, and happy cloning πŸ’–πŸ’…πŸ¦‹

πŸ“¦ where this page comes from