package SubTagGroup;
use strict;

sub new {
  my $proto = shift;
  my $class = ref($proto) || $proto;
  my $self  = {};
  my $line = undef;
  my $attr = undef;
  my $val = undef;
  my $nothing = undef;
  $self->{NAME}   = undef;
  $self->{SUBTAGS}  = [];

  # Load subtaggroup from stdin
  while(! ( ($line = <STDIN>) =~ /}/)) {
    next if $line =~ /^\#/;               # Skip comments
    next if $line eq "\n";        # Skip emptylines

    for ($line) {
      s/^\s+//;
      s/\s+$//;
    }

    ($attr,$val) = split /\s+/, $line, 2;

    for ($attr) {
      SWITCH: {
        /^name$/i && do { $self->{NAME} = $val; last SWITCH; };
        /^SubTag$/i && do { push @{$self->{SUBTAGS}}, $val; last SWITCH; };
        $nothing = 1;
      }
    }
  }

  bless ($self, $class);
  return $self;
}

sub print {
  my $self = shift;
  my $subtag;

  print "    SubTagGroup {\n";
  print "      name $self->{NAME}\n";
  foreach $subtag (@{$self->{SUBTAGS}}) {
    print "      SubTag $subtag\n";
  }
  print "    }\n";

  return;
}

sub name {
          my $self = shift;
          if (@_) { $self->{NAME} = shift }
          return $self->{NAME};
}

sub subtags {
          my $self = shift;
          if (@_) { @{ $self->{SUBTAGS} } = @_ }
          return @{ $self->{SUBTAGS} };
}

1;  # so the require or use succeeds
