2 # Lintian::Data -- interface to query lists of keywords
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::Data;
24 # The constructor loads a list into a hash in %data, which is private to this
25 # module. Use %data as a cache to avoid loading the same list more than once
26 # (which means lintian doesn't support having the list change over the life of
27 # the proces. The returned object knows what list, stored in %data, it is
32 my ($class, $type) = @_;
33 croak('no data type specified') unless $type;
34 unless (exists $data{$type}) {
35 my $dir = $ENV{LINTIAN_ROOT} . '/data';
36 open(LIST, '<', "$dir/$type")
37 or croak("unknown data type $type");
47 my $self = { data => $data{$type} };
53 # Query a data object for whether a particular keyword is valid.
55 my ($self, $keyword) = @_;
56 return (exists $self->{data}{$keyword}) ? 1 : undef;
61 Lintian::Data - Lintian interface to query lists of keywords
65 my $list = Lintian::Data->new('type');
66 if ($list->known($keyword)) {
72 Lintian::Data provides a way of loading a list of keywords from a file in
73 the Lintian root and then querying that list. The lists are stored in the
74 F<data> directory of the Lintian root and consist of one keyword per line.
75 Blank lines and lines beginning with C<#> are ignored. Leading and
76 trailing whitespace is stripped; other than that, keywords are taken
77 verbatim as they are listed in the file and may include spaces.
79 This module allows lists such as menu sections, doc-base sections,
80 obsolete packages, package fields, and so forth to be stored in simple,
81 easily editable files.
89 Creates a new Lintian::Data object for the given TYPE. TYPE is a partial
90 path relative to the F<data> directory and should correspond to a file in
91 that directory. The contents of that file will be loaded into memory and
92 returned as part of the newly created object. On error, new() throws an
95 A given file will only be loaded once. If new() is called again with the
96 same TYPE argument, the data previously loaded will be reused, avoiding
101 =head1 INSTANCE METHODS
107 Returns true if KEYWORD was listed in the data file represented by this
108 Lintian::Data instance and false otherwise.
116 =item no data type specified
118 new() was called without a TYPE argument.
120 =item unknown data type %s
122 The TYPE argument to new() did not correspond to a file in the F<data>
123 directory of the Lintian root.
131 =item LINTIAN_ROOT/data
133 The files loaded by this module must be located in this directory.
134 Relative paths containing a C</> are permitted, so files may be organized
135 in subdirectories in this directory.
145 This variable must be set to Lintian's root directory (normally
146 F</usr/share/lintian> when Lintian is installed as a Debian package). The
147 B<lintian> program normally takes care of doing this. This module doesn't
148 care about the contents of this directory other than expecting the F<data>
149 subdirectory of this directory to contain its files.
155 Originally written by Russ Allbery <rra@debian.org> for Lintian.
166 # indent-tabs-mode: nil
167 # cperl-indent-level: 4
169 # vim: syntax=perl sw=4 sts=4 ts=4 et shiftround