summaryrefslogtreecommitdiff
path: root/new-infra/TLDB.pm
blob: 3c23e94989c0d02a534a2589552e8024ea8904e2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#
# TLDB.pm
# module for using tldb files
# Copyright 2007 Norbert Preining
#
# This file is licensed under the GNU General Public Licence version 2
# or any later version

package TLDB;

use TLP;

sub new { 
	my $class = shift;
	my %params = @_;
	my $self = {};
	bless $self, $class;
	return $self;
}

sub add_tlp {
	my ($self,$tlp) = @_;
	$self->{$tlp->name} = $tlp;
}

sub from_file {
	my $self = shift;
	if (@_ != 1) {
		die("Need a filename for initialization!");
	}
	open(TMP,"<$_[0]") || die("Cannot open tldb file: $_[0]");
	do {
		my $tlp = TLP->new;
		my $found = $tlp->from_fh(\*TMP,1);
		if ($found) {
			$self->add_tlp($tlp);
		}
	} until (!$found);
}

sub writeout {
	my $self = shift;
	my $fd = (@_ ? $_[0] : STDOUT);
	foreach (sort keys %$self) {
		$self->{$_}->writeout($fd);
		print $fd "\n";
	}
}

1;

### Local Variables:
### perl-indent-level: 4
### tab-width: 4
### indent-tabs-mode: t
### End:
# vim:set tabstop=4: #