NAME
MojoX::Tree - Mojolicious ♥ Tree
SYNOPSIS
use MojoX::Tree;
use MojoX::Mysql;
use Mojo::Util qw(dumper);
my %config = (
user=>'root',
password=>undef,
server=>[
{dsn=>'database=test;host=localhost;port=3306;mysql_connect_timeout=5;', type=>'master'},
{dsn=>'database=test;host=localhost;port=3306;mysql_connect_timeout=5;', type=>'slave'},
]
);
my $mysql = MojoX::Mysql->new(%config);
my $tree = MojoX::Tree->new(
mysql=>$mysql,
table=>'tree',
length=>10,
column=>{
id=>'tree_id',
name=>'name',
path=>'path',
level=>'level',
parent_id=>'parent_id'
}
);
DESCRIPTION
MojoX::Tree - Implementation of the materialized path for the Mojolicious real-time web framework.
METHODS
add
my $id = $tree->add('name'); # create root branch
$tree->add('name', $id); # sub branch
delete
$tree->delete(1); # delete branch and sub branch
move
$tree->move(1,2); # move branch (1) to branch (2)
get_id
say dumper $tree->get_id(1); # get branch (1)
EXAMPLE TABLE
CREATE TABLE `tree` (
`tree_id` int(14) unsigned NOT NULL AUTO_INCREMENT,
`name` varchar(255) NOT NULL,
`path` mediumtext NOT NULL,
`level` int(14) unsigned NOT NULL,
`parent_id` int(14) unsigned NULL,
PRIMARY KEY (`tree_id`),
KEY `path` (`path`(30))
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
Mojolicious Plugin
SEE ALSO Mojolicious::Plugin::Tree
TODO
1.Move root
2.Get all tree
AUTHOR
Kostya Ten, kostya@cpan.org
.
COPYRIGHT AND LICENSE
Copyright (C) 2014, Kostya Ten.
This program is free software, you can redistribute it and/or modify it under the terms of the Apache License version 2.0.