sub get_blogs { my ($self, $c, $page) = @_; my $blogs; foreach $blog ( $c->model('YourSpaceDB::Blog')->search( { blog_is_hidden => 0, blog_is_reply => 0, blog_is_draft => 0, }, { rows => 5, page => $page, order_by => 'blog_date DESC' } )->all) { push @$blogs, get_replies($c, $blog, $page); } $blogs; } sub get_replies { my ($c, $blog, $page) = @_; my $replies; my $ret; my $replies = $c->model('YourSpaceDB::Blog')->search( { blog_is_hidden => 0, blog_is_reply => 1, blog_is_draft => 0, blog_is_reply_to => $blog->blog_id, }, { rows => 5, page => $page, order_by => 'blog_date DESC', } ); return [ $blog, 0, undef ] unless $replies; foreach my $reply (@$replies) { push @$ret, get_replies($c, $reply, $page); } [ $blog, scalar (@$replies), $ret ]; } #### $blogs = [ # blog list [ # first blog blog, 2, [ # replies structure [ # first reply reply, 0, undef, # no replies ], [ # second reply reply, 1, [ # replies structure [ # first reply reply, 0, undef, # no replies ] ] ], ], ], # end of first blog [ # second blog ... ], ]; # end of blog list