File: List.pm

package info (click to toggle)
dpkg-scriptlib 0.1-2hamm1
  • links: PTS
  • area: main
  • in suites: hamm, slink
  • size: 188 kB
  • ctags: 230
  • sloc: python: 1,685; perl: 534; makefile: 41; sh: 18
file content (53 lines) | stat: -rw-r--r-- 1,050 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
use strict;
use Carp;
require 5.001;

use Dpkg::Package::Package;

package Dpkg::Package::List;

sub new {
    my $this = shift;
    my $class = ref ($this) || $this;
    my %args = @_;

    my $self = {};
    my @packages = ();
    $self->{'packages'} = \@packages;

    if (! defined $args{'filename'}) {
	croak ("requires 'filename' as parameter"); 
    }

    bless ($self, $class);
    $self->parse ('filename' => $args{'filename'});
    return $self;
}

sub parse {
    my $self = shift;
    my %args = @_;

    if (! defined $args{'filename'}) { 
	croak ("requires 'filename' as parameter"); 
    }
    my $filename = $args{'filename'};
    if (! open (PACKAGE_FILE, $filename)) {
	croak ("Unable to load $filename: $!");
    }

    $/ = "";
    while (<PACKAGE_FILE>) {
	if (/^\s*$/) { next; }
	my $package = Dpkg::Package::Package->new ('data' => $_);
	my $packages = $self->{'packages'};
	unshift @$packages, $package;
    }
    $/ = "\n";
    close (PACKAGE_FILE);
}

sub packages {
    my $self = shift;
    return $self->{'packages'};
}