Links: Next Previous Up Top

How do I design my own classes?

In addition to the methods listed above, all of the classes used in have an ext method which returns a reference to an initially-empty hash table. You are free to use this hash table to store anything you want -- it should be especially useful if you are building your own, derived classes from the ones provided here. The following example builds a derived class My_Element from the SGMLS_Element class, adding methods to set and get the current font:

use SGMLS;

package My_Element;
@ISA = qw(SGMLS_Element);

sub new {
  my ($class,$element,$font) = @_;
  $element->ext->{'font'} = $font;
  return bless $element;

sub get_font {
  my ($self) = @_;
  return $self->ext->{'font'};

sub set_font {
  my ($self,$font) = @_;
  $self->ext->{'font'} = $font;

Note that the derived class does not need to have any knowledge about the underlying structure of the SGMLS_Element class, and need only avoid shadowing any of the methods currently existing there.

If you decide to create a derived class from the SGMLS, please note that in addition to the methods listed above, that class uses internal methods named element, line, and file, similar to the same methods in SGMLS_Event -- it is essential that you not shadow these method names.

Links: Next Previous Up Top

David Megginson <>