DBIx::...Ordered(3pm)
π DBIx::...Ordered β the manual, but make it cute π
okay bestie, so this is the page for DBIx::Class::Tree::AdjacencyList::Ordered, and it lives in the User Contributed Perl Documentation corner of the man pages (the (3pm) vibe, yk). Grab a strawberry π and let's get into it.
β¨ NAME β¨
DBIx::Class::Tree::AdjacencyList::Ordered β it glues DBIx::Class::Ordered and DBIx::Class::Tree::AdjacencyList together. That's it, that's the whole job. Two iconic modules, one slay little bridge. π
πΈ SYNOPSIS πΈ
First things first: make a table for your tree data. Not me writing SQL, but here we are:
CREATE TABLE items (
item_id INTEGER PRIMARY KEY AUTOINCREMENT,
parent_id INTEGER NOT NULL DEFAULT 0,
position INTEGER NOT NULL,
name TEXT NOT NULL
);
Then in your Schema or DB class, you add Tree::AdjacencyList::Ordered to the front of the component list. Front, bestie. Not the middle, not the back. The front. π
__PACKAGE__->load_components(qw( Tree::AdjacencyList::Ordered ... ));
Next, tell it which column holds the parent ID and which one holds the position of each row:
package My::Employee;
__PACKAGE__->position_column('position');
__PACKAGE__->parent_column('parent_id');
And now the fun part β this module hands you a few extra methods on top of whatever DBIx::Class::Ordered and DBIx::Class::Tree::AdjacencyList already gave you. Look at her go:
my $parent = $item->parent();
$item->parent( $parent_obj );
$item->parent( $parent_id );
my $children_rs = $item->children();
my @children = $item->children();
$parent->append_child( $child );
$parent->prepend_child( $child );
$this->attach_before( $that );
$this->attach_after( $that );
π¦ DESCRIPTION π¦
So what does it actually do? It gives you methods for working with adjacency lists and ordered rows at the same time. And all of the methods that DBIx::Class::Ordered and DBIx::Class::Tree::AdjacencyList provide? Yeah, those are all available with this module too. Nothing gets taken away, you just get more. We love an overachiever. π«Ά
π METHODS π
π parent_column
__PACKAGE__->parent_column('parent_id');
Works the same as AdjacencyList's parent_column() method β same energy, no notes β except it also declares the children() has-many relationship to be ordered by the position column. That's the glow-up right there. β¨
π parent
my $parent = $item->parent();
$item->parent( $parent_obj );
$item->parent( $parent_id );
This one overrides AdjacencyList's parent() method, but with a twist: it modifies it so the object is moved to the last position, then the parent is changed, and then it's moved to the last position of the new list β which keeps the integrity of your ordered lists intact. The way that it just... maintains order. π Iconic behaviour, fr fr.
π children
my $children_rs = $item->children();
my @children = $item->children();
Works exactly like it does in the DBIx::Class::Tree::AdjacencyList module, except β and this is the part β it orders the children by there position. Yes bestie, that's the original wording, we're keeping it, no cap. π
π append_child
$parent->append_child( $child );
Sets the child to have the specified parent and moves the child to the last position. Two jobs, zero complaints. π
π prepend_child
$parent->prepend_child( $child );
Sets the child to have the specified parent and moves the child to the first position. Main character energy, obviously. π
π attach_before
$this->attach_before( $that );
Attaches the object at the position just before the calling object's position. Sneaky little move, we respect it. π
π attach_after
$this->attach_after( $that );
Attaches the object at the position just after the calling object's position. Right behind you, bestie. π
π INHERITED METHODS π
Everything you inherit, all in one place, because you deserve the full list and not a summary:
π« DBIx::Class::Ordered
siblingsfirst_siblinglast_siblingprevious_siblingnext_siblingmove_previousmove_nextmove_firstmove_lastmove_toinsertdelete
π« DBIx::Class::Tree::AdjacencyList
parent_columnparentattach_childsiblingsattach_sibling
π« DBIx::Class
mk_classdatacomponent_base_class
π« DBIx::Class::Componentised
inject_baseload_componentsload_own_components
π« Class::Data::Accessor
mk_classaccessor
β AUTHOR β
Aran Clary Deltac <bluefeet@cpan.org> β thank you for your service, king π«‘
π LICENSE π
You may distribute this code under the same terms as Perl itself. Simple as that, bestie.
and that's the whole page!! π This lil' beauty is documented as perl v5.36.0, dated 2023-02-14 (yes, Valentine's Day, because she's a romantic π), and it's filed under DBIx::...Ordered(3pm). Go build your trees, ordered and iconic. bye bestie!! π
β¨π¦
π¦ where this page comes from
- debian trixie: libdbix-class-tree-perl 0.03003-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu noble: libdbix-class-tree-perl 0.03003-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu resolute: libdbix-class-tree-perl 0.03003-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu stonking: libdbix-class-tree-perl 0.03003-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms