1 # Maemian::Collect -- interface to package data collection
3 # Copyright (C) 2009 Jeremiah C. Foster
4 # Based on the work of 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 Maemian::Collect;
22 # Take the package name and type, initialize an appropriate collect object
23 # based on the package type, and return it. Returns undef for an unknown
26 my ($class, $pkg, $type) = @_;
28 if ($type eq 'source') {
29 require Maemian::Collect::Source;
30 $object = Maemian::Collect::Source->new ($pkg);
31 } elsif ($type eq 'binary' or $type eq 'udeb') {
32 require Maemian::Collect::Binary;
33 $object = Maemian::Collect::Binary->new ($pkg);
37 $object->{name} = $pkg;
38 $object->{type} = $type;
42 # Return the package name.
43 # sub name Needs-Info <>
49 # Return the package type.
50 # sub type Needs-Info <>
56 # Return the value of the specified control field of the package, or undef if
57 # that field wasn't present in the control file for the package. For source
58 # packages, this is the *.dsc file; for binary packages, this is the control
59 # file in the control section of the package.
60 # sub field Needs-Info <>
62 my ($self, $field) = @_;
63 return $self->{field}{$field} if exists $self->{field}{$field};
64 if (open(FIELD, '<', "fields/$field")) {
69 $self->{field}{$field} = $value;
71 $self->{field}{$field} = undef;
73 return $self->{field}{$field};
78 Maemian::Collect - Maemian interface to package data collection
82 my ($name, $type) = ('foobar', 'udeb');
83 my $collect = Maemian::Collect->new($name, $type);
84 $name = $collect->name;
85 $type = $collect->type;
89 Maemian::Collect provides the shared interface to package data used by
90 source, binary, and udeb packages. It creates an object of the
91 appropriate type and provides common functions used by the collection
92 interface to all three types of packages.
94 This module is in its infancy. Most of Maemian still reads all data from
95 files in the laboratory whenever that data is needed and generates that
96 data via collect scripts. The goal is to eventually access all data via
97 this module and its subclasses so that the module can cache data where
98 appropriate and possibly retire collect scripts in favor of caching that
105 =item new(PACKAGE, TYPE)
107 Creates a new object appropriate to the package type. Currently, the only
108 TYPE supported is C<source>, which creates a new Maemian::Collect::Source
109 object and returns it. TYPE can be retrieved later with the type()
110 method. Returns undef an unknown TYPE.
112 PACKAGE is the name of the package and is stored in the collect object.
113 It can be retrieved with the name() method.
117 =head1 INSTANCE METHODS
119 In addition to the instance methods documented here, see the documentation
120 of Maemian::Collect::Source for instance methods specific to source
127 Returns the value of the control field FIELD in the control file for the
128 package. For a source package, this is the *.dsc file; for a binary
129 package, this is the control file in the control section of the package.
130 The value will be read from the F<fields/> subdirectory of the current
131 directory if it hasn't previously been requested and cached in memory so
132 that subsequent requests for the same field can be answered without file
137 Returns the name of the package.
141 Returns the type of the package.
147 Originally written by Russ Allbery <rra@debian.org> for Maemian.
151 maemian(1), Maemian::Collect::Source(3)