##---------------------------------------------------------------------------## ## File: ## $Id: ListDef.pm,v 1.5 2003/07/16 00:49:58 ehood Exp $ ## Description: ##---------------------------------------------------------------------------## ## Copyright (C) 2002 Earl Hood ## ## This program is free software; you can redistribute it and/or modify ## it under the terms of the GNU General Public License as published by ## the Free Software Foundation; either version 2 of the License, or ## (at your option) any later version. ## ## This program is distributed in the hope that it will be useful, ## but WITHOUT ANY WARRANTY; without even the implied warranty of ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ## GNU General Public License for more details. ## ## You should have received a copy of the GNU General Public License ## along with this program; if not, write to the Free Software ## Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA ## 02111-1307, USA ##---------------------------------------------------------------------------## package MHArc::ListDef; sub _DEF_ORDER() { return '-X-DEF-ORDER-'; } sub new { my $self = { }; my $mod = shift; # Name of module my $fh = shift; # Filehandle to read definitions from my $class = ref($mod) || $mod; bless $self, $class; $self->{_DEF_ORDER} = [ ]; $self->load_file($fh); } sub load_file { my $self = shift; my $file = shift; my $fh; local(*LISTDEF); if (!ref($file)) { if (!open(LISTDEF, $file)) { die qq/ERROR: Unable to open "$file": $!\n/; } $fh = \*LISTDEF; } else { $fh = $file; } my $name = undef; my($key, $line); while (defined($line = <$fh>)) { next unless $line =~ /\S/; next if $line =~ /^\s*#/; chomp $line; ($key, $value) = $line =~ /^([^:]+):\s*(.*)$/; $key = lc $key; if ($key eq 'name') { $value =~ s/\s//g; $name = $value; push(@{$self->{_DEF_ORDER}}, $name); $self->{$name}{'name'} = [ $name ]; next; } if (!defined($name)) { warn qq/Warning: No name defined for '$line'\n/; next; } if (defined($self->{$name}{$key})) { push(@{$self->{$name}{$key}}, $value); } else { $self->{$name}{$key} = [ $value ]; } } if (!ref($file)) { close($fh); } $self; } sub get_names { my $self = shift; @{$self->{_DEF_ORDER}}; } 1; __END__ =head1 NAME MHArc::ListDef - Load mailing lists definition file =head1 SYNOPSIS $def = MHArc::ListDef->new($fh); $def = MHArc::ListDef->new($filename); # Return list of names in order defined @names = $def->get_names; # Access an option $description = $def->{$name}{'description'}[0]; =head1 DESCRIPTION This module parses a mailing list definition file for use in the auto-mail archiving system. The C method either takes a filehandle reference or a filename string. =head1 SEE ALSO L =head1 VERSION C<$Id: ListDef.pm,v 1.5 2003/07/16 00:49:58 ehood Exp $> =head1 AUTHOR Earl Hood, earl@earlhood.com This module is part of the mharc archiving system and comes with ABSOLUTELY NO WARRANTY and may be copied only under the terms of the GNU General Public License, which may be found in the MHArc distribution. =cut