# # 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 TLUtils; use TLP; sub new { my $class = shift; my %params = @_; my $self = { location => $params{'location'}, tlps => $params{'tlps'} }; if (defined($self->{'location'})) { $self->from_file($self->{'location'}); } bless $self, $class; return $self; } sub add_tlp { my ($self,$tlp) = @_; $self->{'tlps'}{$tlp->name} = $tlp; } sub from_file { my $self = shift; if (@_ != 1) { die("Need a filename for initialization!"); } if (defined($self->{'location'})) { if ($self->location ne $_[0]) { printf STDERR "Initialisation from different location as originally given.\nHope you are sure!\n"; } } $self->location($_[0]); open(TMP,"<$_[0]") || die("Cannot open tldb file: $_[0]"); my $found = 0; do { my $tlp = TLP->new; &TLUtils::debug("creating tlp ...\n"); $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->{'tlps'}}) { &TLUtils::debug("tlpname = $_\n"); &TLUtils::debug("foo: " . $self->{'tlps'}{$_}->name . "\n"); $self->{'tlps'}{$_}->writeout($fd); print $fd "\n"; } } sub save { my $self = shift; open(FOO,">$self->{'location'}") || die("Cannot open $self->{'location'} for writing: $!"); $self->writeout(\*FOO); close(FOO); } sub get_package { my ($self,$pkg) = @_; if (defined($self->{'tlps'}{$pkg})) { return($self->{'tlps'}{$pkg}); } else { return(undef); } } sub package_revision { my ($self,$pkg) = @_; if (defined($self->{'tlps'}{$pkg})) { return($self->{'tlps'}{$pkg}->revision); } else { return(undef); } } sub generate_packagelist { my $self = shift; my $fd = (@_ ? $_[0] : STDOUT); foreach (sort keys %{$self->{'tlps'}}) { print $fd $self->{'tlps'}{$_}->name, " ", $self->{'tlps'}{$_}->revision, "\n"; } } sub location { my $self = shift; if (@_) { $self->{'location'} = shift } return $self->{'location'}; } 1; ### Local Variables: ### perl-indent-level: 4 ### tab-width: 4 ### indent-tabs-mode: t ### End: # vim:set tabstop=4: #