Data::G...::Parent(3)

🌸 NAME 🌸

Data::Grove::Parent β€” bestie, this is the module that gives your Data::Grove objects their very own parent properties, and honestly? It's giving backstage-pass energy πŸ’…


✨ SYNOPSIS ✨

use Data::Grove::Parent;

$root = $object->root;
$rootpath = $object->rootpath;
$tied = $object->add_magic([ $parent ]);

$node = Data::Grove::Parent->new($hash [, $parent]);
$node_list = Data::Grove::ParentList->new($array [, $parent]);

πŸ¦‹ DESCRIPTION πŸ¦‹

So Data::Grove::Parent is literally an extension to Data::Grove, and what it does is add "Parent" and "Raw" properties to your Data::Grove objects πŸŽ€. It also brings the methods for returning the root node of a grove, for returning a list of nodes between and including the root node and the current node, and for creating parented nodes. Iconic, honestly.

Here's the vibe: it works by creating a Perl "tied" object that contains a parent reference ("Parent") plus a reference to the original Data::Grove object ("Raw") 🫢. Tying-magic is doing all the work behind the scenes, so every single time you reference the Data::Grove::Parent object, it actually references the underlying raw object. Sneaky? No. Slay? Yes.

And when you retrieve a list or a property of the Raw object, Data::Grove::Parent automatically adds magic to the returned list or node ✨. Which means β€” and this is the good part β€” you only call add_magic() once to create the very first Data::Grove::Parent object, and then you just use the grove objects like you normally would. No cap, that's it.

The most obvious use of this is so you don't have to call a "delete" method when you want to release a grove or part of a grove πŸ“ β€” because Data::Grove and Data::Grove::Parent objects have no cyclic references, Perl can garbage collect them normally. Cleaning up after itself, we love to see it πŸ‘‘

A secondary use is to allow you to reuse grove or property set fragments in multiple trees 🌈.

WARNING: Data::Grove currently does not protect you from creating your own cyclic references! 😭 That could lead to infinite loops if you don't take care to avoid them. Seriously bestie, watch out β€” infinite loops are not the cute kind of chaos πŸ’€

πŸ’– METHODS πŸ’–

🌟 $object->root() / $object->rootpath()

root() returns the root node if $object is a "Data::Grove::Parent" object. rootpath() returns an array of all the nodes between and including the root node and $object. Basically a whole ancestry reveal, main character energy πŸ‘‘

🌟 $tied = $object->add_magic([ $parent ])

add_magic() returns a "Data::Grove::Parent" object with $object as its "Raw" object ✨. And if $parent is given, that becomes the tied object's parent object. Easy πŸŽ€


🧚 AUTHOR 🧚

Ken MacLeod, ken@bitsko.slc.ut.us β€” thank you for your service 🫢


⭐ SEE ALSO ⭐


That's the whole page, bestie πŸ’œπŸ’… β€” brought to you by perl v5.42.0, dated 2024-03-04, and filed under the User Contributed Perl Documentation. Go forth and parent responsibly πŸ¦‹πŸŒΈ

πŸ“¦ where this page comes from