        package ExampleTree5;

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

        # If the label of the tree node is 'foo',
        # we format it like this:
        #    +-----+
        #    | foo |
        #    +-----+
        sub text {
          my $self = shift;
          my $n = $self->[0];
          return ["*"] if $n == 1;
          return [] if $n == 0;
          my @text = ("|" . "*" x ($n-2) . "|") x ($n-2);
          my $top =  ("+" . "-" x ($n-2) . "+");
          [$top, @text, $top];
        }

        sub children {
          my $self = shift;
          my @children = @$self;
          shift @children;  # throw away the label
          @children;
        }

1;

