        package ExampleTree2;

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

        # If the label of the tree node is 'foo',
        # we format it like this:
        #    +-----+
        #    | foo |
        #    +-----+
        sub text {
          my $self = shift;
          my $label = $$self;
          my $ln = length $label;
          $label .= " " x (5-$ln)  if $ln < 5;
          $ln = length $label;
          my $top = "." . "-" x $ln . ",";
          $top = "+" . "-" x $ln . "+";
          my $bot = "`" . "-" x $ln . "'";
          return [$top, "|$label|", $top];
        }

        sub children {
          my $self = shift;
          map $self->new($_), reverse 1 .. $$self-1;
        }

1;

