        package ExampleTree3;
        my $boxes = $ENV{BOXES} || 0;

        # Create a new tree object
        # arguments: ->(label of root node,
        #               [arguments for child 1],
        #               [arguments for child 2],
        #               ...);
        sub new {
          my ($self, $parts) = @_;
          $pack = ref $self || $self;
          bless $parts => $pack;
        }

        sub box {
          my $text = shift;
          my $visible = shift;
          my $width = 0;
          for (@$text) {
            $width = length($_) if length($_) > $width;
          }
          $height = @$text;
          if ($visible) {
            my $hp = "-" x $width;
            ["+$hp+", map("|$_|", @$text), "+$hp+"];
          } else {
            my $sp = " " x $width;
            [" $sp ", map(" $_ ", @$text), " $sp "];
          }
        }

        sub text {
          my $self = shift;
          my $label = join "", @$self;
          my $text = [" $label ", " " x (2+length $label)];
          $text = box($text, 0) for 1 .. $boxes-1;
          $text = box($text, 1) if $boxes;
          $text;
        }

        sub children {
          my $self = shift;
	  my ($largest, @rest) = @$self;  
	  my $min = $rest[0] || 1;
          my $max = int($largest/2);
	  my @children;
	  for ($min .. $max) {
	    push @children, $self->new([$largest-$_, $_, @rest]);
	  }
	  @children;
        }

1;

