Dpkg
view release on metacpan or search on metacpan
lib/Dpkg/Control/Info.pm view on Meta::CPAN
Options:
=over
=item B<filename>
Loads the file from the filename, instead of F<debian/control>.
=back
=cut
sub new {
my ($this, @args) = @_;
my $class = ref($this) || $this;
my $self = {
source => undef,
packages => [],
};
bless $self, $class;
my %opts;
if (scalar @args == 0) {
$opts{filename} = 'debian/control';
} elsif (scalar @args == 1) {
$opts{filename} = $args[0];
} else {
%opts = @args;
}
$self->load($opts{filename}) if $opts{filename};
return $self;
}
=item $c->reset()
Resets what got read.
=cut
sub reset {
my $self = shift;
$self->{source} = undef;
$self->{packages} = [];
}
=item $c->parse($fh, $description)
Parse a control file from the given filehandle. Exits in case of errors.
$description is used to describe the filehandle, ideally it's a filename
or a description of where the data comes from. It is used in error messages.
The data in the object is reset before parsing new control files.
=cut
sub parse {
my ($self, $fh, $desc) = @_;
$self->reset();
my $cdata = Dpkg::Control->new(type => CTRL_TMPL_SRC);
return if not $cdata->parse($fh, $desc);
$self->{source} = $cdata;
unless (exists $cdata->{Source}) {
$cdata->parse_error($desc, g_("first stanza lacks a '%s' field"),
'Source');
}
while (1) {
$cdata = Dpkg::Control->new(type => CTRL_TMPL_PKG);
last if not $cdata->parse($fh, $desc);
push @{$self->{packages}}, $cdata;
unless (exists $cdata->{Package}) {
$cdata->parse_error($desc, g_("stanza lacks the '%s' field"),
'Package');
}
unless (exists $cdata->{Architecture}) {
$cdata->parse_error($desc, g_("stanza lacks the '%s' field"),
'Architecture');
}
}
}
=item $c->load($file)
Load the content of $file. Exits in case of errors. If file is "-", it
loads from the standard input.
=item $c->[0]
=item $c->get_source()
Returns a L<Dpkg::Control> object containing the fields concerning the
source package.
=cut
sub get_source {
my $self = shift;
return $self->{source};
}
=item $c->get_pkg_by_idx($idx)
Returns a L<Dpkg::Control> object containing the fields concerning the binary
package numbered $idx (starting at 1).
=cut
sub get_pkg_by_idx {
my ($self, $idx) = @_;
return $self->{packages}[--$idx];
}
=item $c->get_pkg_by_name($name)
Returns a L<Dpkg::Control> object containing the fields concerning the binary
package named $name.
=cut
sub get_pkg_by_name {
my ($self, $name) = @_;
foreach my $pkg (@{$self->{packages}}) {
return $pkg if ($pkg->{Package} eq $name);
}
return;
}
=item $c->get_packages()
Returns a list containing the L<Dpkg::Control> objects for all binary packages.
=cut
sub get_packages {
my $self = shift;
( run in 1.151 second using v1.01-cache-2.11-cpan-d7f47b0818f )