Код: Выделить всё
package MyApp::Controller::view_section;
use warnings;
use parent 'Catalyst::Controller';
use DBIx::Tree;
=head1 NAME
MyApp::Controller::view_section - Catalyst Controller
=head1 DESCRIPTION
Catalyst Controller.
=head1 METHODS
=cut
=head2 index
=cut
sub view_section : Global {
my ( $self, $c, @args ) = @_;
$c->stash->{template} = 'view_section.tt';
my $sql;
if (defined($args[0])) {
$sql = "SELECT id_se, name_se, parent_se_id
FROM section
WHERE active_se = 1 AND privat_se = 1
";
} else {
$sql = "SELECT id_se, name_se, parent_se_id
FROM section
WHERE active_se = 1 AND privat_se = 1
";
}
my $dbh = $c->model('DBI')->dbh;
my $tree = new DBIx::Tree(connection => $dbh,
sql => $sql,
method => sub { disp_tree(@_) },
columns => ['id_se', 'name_se', 'parent_se_id'],
start_id => $args[0],
recursive => '1'
);
$tree->traverse;
my $tree_a;
while ($curr_level > 0) {
$curr_level--;
}
# End the HTML.
#
# This is the callback function for creating the tree. It's called for
# each node in the tree.
#
sub disp_tree {
# Get the parameters.
#
my %parms = @_;
# We are interested in the item and its level.
#
my $item = $parms{item};
my $level = $parms{level};
my $id = $parms{id};
my $created = $parms{created};
# Strip leading and trailing space from the item.
#
$item =~ s/^\s+//;
$item =~ s/\s+$//;
# If the level increases, start a new list at the new level.
#
push @{$tree_a}, { 'level' => '   ' x ($level), 'item' => $item, 'created' => $args[0], 'id' => $id };
# If the level decreases, end the lists between levels.
#
if ($level < $curr_level) {
while ($curr_level > $level) {
$curr_level--;
}
}
$curr_level = $level;
# Display each item.
#
}
$c->stash->{tree} = $tree_a;
}
если нажать на обновить страницу более чем 2 раза, то дерево не выводиться вообще, потом если обновить еще несколько раз, то все работает, потом опять пропадает связь и не выводит...
из-за чего это может быть? может внешний переменные какие-то??
в Catalyst::Model::DBI есть метод который поддерживает соединения... (но это не pool connection по-моиму)
(может быть надо сделать модель для DBIx::Tree?)
фигня по-моиму тут:
Код: Выделить всё
method => sub { disp_tree(@_) },
Код: Выделить всё
sub disp_tree {