2 # Lintian::Collect -- interface to package data collection
4 # Copyright (C) 2008 Russ Allbery
6 # This program is free software; you can redistribute it and/or modify it
7 # under the terms of the GNU General Public License as published by the Free
8 # Software Foundation; either version 2 of the License, or (at your option)
11 # This program is distributed in the hope that it will be useful, but WITHOUT
12 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
16 # You should have received a copy of the GNU General Public License along with
17 # this program. If not, see <http://www.gnu.org/licenses/>.
19 package Lintian::Collect;
22 use Lintian::Collect::Binary;
23 use Lintian::Collect::Source;
25 # Take the package name and type, initialize an appropriate collect object
26 # based on the package type, and return it. Returns undef for an unknown
29 my ($class, $pkg, $type) = @_;
31 if ($type eq 'source') {
32 $object = Lintian::Collect::Source->new ($pkg);
33 } elsif ($type eq 'binary' or $type eq 'udeb') {
34 $object = Lintian::Collect::Binary->new ($pkg);
38 $object->{name} = $pkg;
39 $object->{type} = $type;
43 # Return the package name.
49 # Return the package type.
55 # Return the value of the specified control field of the package, or undef if
56 # that field wasn't present in the control file for the package. For source
57 # packages, this is the *.dsc file; for binary packages, this is the control
58 # file in the control section of the package.
60 my ($self, $field) = @_;
61 return $self->{field}{$field} if exists $self->{field}{$field};
62 if (open(FIELD, '<', "fields/$field")) {
67 $self->{field}{$field} = $value;
69 $self->{field}{$field} = undef;
71 return $self->{field}{$field};
76 Lintian::Collect - Lintian interface to package data collection
80 my $collect = Lintian::Collect->new($name, $type);
81 $name = $collect->name;
82 $type = $collect->type;
86 Lintian::Collect provides the shared interface to package data used by
87 source, binary, and udeb packages. It creates an object of the
88 appropriate type and provides common functions used by the collection
89 interface to all three types of packages.
91 This module is in its infancy. Most of Lintian still reads all data from
92 files in the laboratory whenever that data is needed and generates that
93 data via collect scripts. The goal is to eventually access all data via
94 this module and its subclasses so that the module can cache data where
95 appropriate and possibly retire collect scripts in favor of caching that
102 =item new(PACKAGE, TYPE)
104 Creates a new object appropriate to the package type. Currently, the only
105 TYPE supported is C<source>, which creates a new Lintian::Collect::Source
106 object and returns it. TYPE can be retrieved later with the type()
107 method. Returns undef an unknown TYPE.
109 PACKAGE is the name of the package and is stored in the collect object.
110 It can be retrieved with the name() method.
114 =head1 INSTANCE METHODS
116 In addition to the instance methods documented here, see the documentation
117 of Lintian::Collect::Source for instance methods specific to source
124 Returns the value of the control field FIELD in the control file for the
125 package. For a source package, this is the *.dsc file; for a binary
126 package, this is the control file in the control section of the package.
127 The value will be read from the F<fields/> subdirectory of the current
128 directory if it hasn't previously been requested and cached in memory so
129 that subsequent requests for the same field can be answered without file
134 Returns the name of the package.
138 Returns the type of the package.
144 Originally written by Russ Allbery <rra@debian.org> for Lintian.
148 lintian(1), Lintian::Collect::Source(3)
155 # indent-tabs-mode: nil
156 # cperl-indent-level: 4
158 # vim: syntax=perl sw=4 sts=4 ts=4 et shiftround