Unnecessary subs and complexity. This was hiding the fact
that $before is never used.
- my $self = shift;
- my $ordersub = shift;
+ my ($self, $ordersub) = @_;
# make a fake root
my $root = _get_cont_for_id($self, 'fakeroot');
# make a fake root
my $root = _get_cont_for_id($self, 'fakeroot');
-sub order_children {
- my $self = shift;
- my $ordersub = shift;
-
- return unless $ordersub;
-
- my $sub = sub {
- my $cont = shift;
- my $children = $cont->children;
- return if @$children < 2;
- $cont->set_children( $ordersub->( $children ) );
- };
- $self->iterate_down( undef, $sub );
- undef $sub;
-}
-
# non-recursive version of recurse_down to avoid stack depth warnings
sub recurse_down {
my ($self, $callback) = @_;
# non-recursive version of recurse_down to avoid stack depth warnings
sub recurse_down {
my ($self, $callback) = @_;
-sub iterate_down {
- my $self = shift;
- my ($before, $after) = @_;
+sub order_children {
+ my ($walk, $ordersub) = @_;
my $depth = 0;
my @visited;
while ($walk) {
my $depth = 0;
my @visited;
while ($walk) {
- push @visited, [ $walk, $depth ];
- $before->($walk, $depth) if $before;
# spot/break loops
$seen{$walk}++;
# spot/break loops
$seen{$walk}++;
- return unless $after;
- while (@visited) { $after->(@{ pop @visited }) }
+ foreach my $cont (@visited) {
+ my $children = $cont->children;
+ next if @$children < 2;
+ $children = $ordersub->($children);
+ $cont = $cont->{child} = shift @$children;
+ do {
+ $cont = $cont->{next} = shift @$children;
+ } while ($cont);
+ }