home *** CD-ROM | disk | FTP | other *** search
/ Clickx 115 / Clickx 115.iso / software / tools / windows / tails-i386-0.16.iso / live / filesystem.squashfs / usr / share / perl5 / Dpkg / Control.pm < prev    next >
Encoding:
Perl POD Document  |  2012-09-17  |  5.5 KB  |  198 lines

  1. # Copyright ┬⌐ 2007-2009 Rapha├½l Hertzog <hertzog@debian.org>
  2. #
  3. # This program is free software; you can redistribute it and/or modify
  4. # it under the terms of the GNU General Public License as published by
  5. # the Free Software Foundation; either version 2 of the License, or
  6. # (at your option) any later version.
  7. #
  8. # This program is distributed in the hope that it will be useful,
  9. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  11. # GNU General Public License for more details.
  12. #
  13. # You should have received a copy of the GNU General Public License
  14. # along with this program.  If not, see <http://www.gnu.org/licenses/>.
  15.  
  16. package Dpkg::Control;
  17.  
  18. use strict;
  19. use warnings;
  20.  
  21. our $VERSION = "1.00";
  22.  
  23. use Dpkg::Gettext;
  24. use Dpkg::ErrorHandling;
  25. use Dpkg::Control::Types;
  26. use Dpkg::Control::Hash;
  27. use Dpkg::Control::Fields;
  28.  
  29. use base qw(Dpkg::Control::Hash Exporter);
  30. our @EXPORT = qw(CTRL_UNKNOWN CTRL_INFO_SRC CTRL_INFO_PKG CTRL_INDEX_SRC
  31.                  CTRL_INDEX_PKG CTRL_PKG_SRC CTRL_PKG_DEB CTRL_FILE_CHANGES
  32.                  CTRL_FILE_VENDOR CTRL_FILE_STATUS CTRL_CHANGELOG);
  33.  
  34. =encoding utf8
  35.  
  36. =head1 NAME
  37.  
  38. Dpkg::Control - parse and manipulate official control-like information
  39.  
  40. =head1 DESCRIPTION
  41.  
  42. The Dpkg::Control object is a smart version of Dpkg::Control::Hash.
  43. It associates a type to the control information. That type can be
  44. used to know what fields are allowed and in what order they must be
  45. output.
  46.  
  47. The types are constants that are exported by default. Here's the full
  48. list:
  49.  
  50. =over 4
  51.  
  52. =item CTRL_UNKNOWN
  53.  
  54. This type is the default type, it indicates that the type of control
  55. information is not yet known.
  56.  
  57. =item CTRL_INFO_SRC
  58.  
  59. Corresponds to the first block of information in a debian/control file in
  60. a Debian source package.
  61.  
  62. =item CTRL_INFO_PKG
  63.  
  64. Corresponds to subsequent blocks of information in a debian/control file
  65. in a Debian source package.
  66.  
  67. =item CTRL_INDEX_SRC
  68.  
  69. Corresponds to an entry in a Sources file of an APT source package
  70. repository.
  71.  
  72. =item CTRL_INDEX_PKG
  73.  
  74. Corresponds to an entry in a Packages file of an APT binary package
  75. repository.
  76.  
  77. =item CTRL_PKG_SRC
  78.  
  79. Corresponds to a .dsc file of a Debian source package.
  80.  
  81. =item CTRL_PKG_DEB
  82.  
  83. Corresponds to the control file generated by dpkg-gencontrol
  84. (DEBIAN/control) and to the same file inside .deb packages.
  85.  
  86. =item CTRL_FILE_CHANGES
  87.  
  88. Corresponds to a .changes file.
  89.  
  90. =item CTRL_FILE_VENDOR
  91.  
  92. Corresponds to a vendor file in /etc/dpkg/origins/.
  93.  
  94. =item CTRL_FILE_STATUS
  95.  
  96. Corresponds to an entry in dpkg's status file (/var/lib/dpkg/status).
  97.  
  98. =item CTRL_CHANGELOG
  99.  
  100. Corresponds to the output of dpkg-parsechangelog.
  101.  
  102. =back
  103.  
  104. =head1 FUNCTIONS
  105.  
  106. All the methods of Dpkg::Control::Hash are available. Those listed below
  107. are either new or overridden with a different behaviour.
  108.  
  109. =over 4
  110.  
  111. =item my $c = Dpkg::Control->new(%opts)
  112.  
  113. If the "type" option is given, it's used to setup default values
  114. for other options. See set_options() for more details.
  115.  
  116. =cut
  117.  
  118. sub new {
  119.     my ($this, %opts) = @_;
  120.     my $class = ref($this) || $this;
  121.  
  122.     my $self = Dpkg::Control::Hash->new();
  123.     bless $self, $class;
  124.     $self->set_options(%opts);
  125.  
  126.     return $self;
  127. }
  128.  
  129. =item $c->set_options(%opts)
  130.  
  131. Changes the value of one or more options. If the "type" option is changed,
  132. it is used first to define default values for others options. The option
  133. "allow_pgp" is set to 1 for CTRL_PKG_SRC and CTRL_FILE_CHANGES and to 0
  134. otherwise. The option "drop_empty" is set to 0 for CTRL_INFO_PKG and
  135. CTRL_INFO_SRC and to 1 otherwise. The option "name" is set to a textual
  136. description of the type of control information.
  137.  
  138. The output order is also set to match the ordered list returned by
  139. Dpkg::Control::Fields::field_ordered_list($type).
  140.  
  141. =cut
  142.  
  143. sub set_options {
  144.     my ($self, %opts) = @_;
  145.     if (exists $opts{'type'}) {
  146.         my $t = $opts{'type'};
  147.         $$self->{'allow_pgp'} = ($t & (CTRL_PKG_SRC | CTRL_FILE_CHANGES)) ? 1 : 0;
  148.         $$self->{'drop_empty'} = ($t & (CTRL_INFO_PKG | CTRL_INFO_SRC)) ?  0 : 1;
  149.         if ($t == CTRL_INFO_SRC) {
  150.             $$self->{'name'} = _g("general section of control info file");
  151.         } elsif ($t == CTRL_INFO_PKG) {
  152.             $$self->{'name'} = _g("package's section of control info file");
  153.         } elsif ($t == CTRL_CHANGELOG) {
  154.             $$self->{'name'} = _g("parsed version of changelog");
  155.         } elsif ($t == CTRL_INDEX_SRC) {
  156.             $$self->{'name'} = sprintf(_g("entry of APT's %s file"), "Sources");
  157.         } elsif ($t == CTRL_INDEX_PKG) {
  158.             $$self->{'name'} = sprintf(_g("entry of APT's %s file"), "Packages");
  159.         } elsif ($t == CTRL_PKG_SRC) {
  160.             $$self->{'name'} = sprintf(_g("%s file"), ".dsc");
  161.         } elsif ($t == CTRL_PKG_DEB) {
  162.             $$self->{'name'} = _g("control info of a .deb package");
  163.         } elsif ($t == CTRL_FILE_CHANGES) {
  164.             $$self->{'name'} = sprintf(_g("%s file"), ".changes");
  165.         } elsif ($t == CTRL_FILE_VENDOR) {
  166.             $$self->{'name'} = _g("vendor file");
  167.         } elsif ($t == CTRL_FILE_STATUS) {
  168.             $$self->{'name'} = _g("entry in dpkg's status file");
  169.         }
  170.         $self->set_output_order(field_ordered_list($opts{'type'}));
  171.     }
  172.  
  173.     # Options set by the user override default values
  174.     $$self->{$_} = $opts{$_} foreach keys %opts;
  175. }
  176.  
  177. =item $c->get_type()
  178.  
  179. Returns the type of control information stored. See the type parameter
  180. set during new().
  181.  
  182. =cut
  183.  
  184. sub get_type {
  185.     my ($self) = @_;
  186.     return $$self->{'type'};
  187. }
  188.  
  189. =back
  190.  
  191. =head1 AUTHOR
  192.  
  193. Rapha├½l Hertzog <hertzog@debian.org>.
  194.  
  195. =cut
  196.  
  197. 1;
  198.