From 5bb771334da8ed9cf53a8d4ae1cbdf1e795ade9a Mon Sep 17 00:00:00 2001 From: joey Date: Fri, 21 Apr 2000 07:33:07 +0000 Subject: [PATCH] packages automatically scan when the filename is set --- Alien/Package.pm | 37 +++++++++++++++++++++++++++---------- 1 file changed, 27 insertions(+), 10 deletions(-) diff --git a/Alien/Package.pm b/Alien/Package.pm index 96f288d..1c3f952 100644 --- a/Alien/Package.pm +++ b/Alien/Package.pm @@ -21,7 +21,7 @@ and populate those fields. And they can build the actual package using the data stored in the fields. A typical use of this object class will be to instantiate an object from -a class derived from this one, such as Alien::Package::Rpm Feed the object +a class derived from this one, such as Alien::Package::Rpm. Feed the object a rpm file, thus populating all of its fields. Then rebless the object into the destination class, such as Alien::Package::Deb. Finally, ask the object to build a package, and the package has been converted. @@ -124,10 +124,6 @@ The prerm script of the package. Points to a directory where the package has been unpacked. -=item filename - -The filename of the package the object represents. - =back =head1 METHODS @@ -144,7 +140,8 @@ parameters that specify the values of any fields in the class. sub new { my $proto = shift; my $class = ref($proto) || $proto; - my $this=bless ({@_}, $class); + my $this=bless ({}, $class); + $this->$_(shift) while $_=shift; # run named parameters as methods $this->init; return $this; } @@ -169,17 +166,37 @@ sub install { my $this=shift; } -=item scan +=item filename -This method looks at the actual package file the package represents, and -populates all the fields it can from that package file. The filename field -should already be set before this method is called. +Set/get the filename of the package the object represents. + +When it is set, it performs a scan of the file, populating most other +fields with data from it. (This is just a stub; child classes should override it to actually do something.) =cut +sub filename { + my $this=shift; + + # set + if (@_) { + $this->{filename} = shift; + $this->scan; + } + + return $this->{filename}; +} + +=item scan + +This method scans the file associated with an object, and populates as many +other fields as it can with data from it. + +=cut + sub scan { my $this=shift; my $file=$this->filename;