File: Config.pm

package info (click to toggle)
libapt-pkg-perl 0.1.24
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 272 kB
  • ctags: 104
  • sloc: perl: 1,208; ansic: 198; makefile: 39
file content (108 lines) | stat: -rw-r--r-- 1,992 bytes parent folder | download | duplicates (3)
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
package AptPkg::Config;

# $Id: Config.pm,v 1.7 2005-08-07 14:03:02 bod Exp $

require 5.005_62;
use strict;
use warnings;
use AptPkg;
use AptPkg::hash;
use Carp;

require Exporter;

our @ISA = qw(Exporter AptPkg::hash);
our @EXPORT_OK = qw($_config);
our @EXPORT = ();

our $VERSION = qw$Revision: 1.7 $[1] || 0.1;
our $_config = __PACKAGE__->new($AptPkg::_config::_config);

sub get
{
    my $xs = shift->_xs;
    return $xs->FindAny(@_) unless @_ and $_[0] =~ /(.+)::$/;

    # special case where name ends with ::
    my $tree = $xs->Tree($1);
    return unless $tree and $tree = $tree->Child;

    my @r;
    while ($tree)
    {
	my $v = $tree->Value;
	push @r, $v if defined $v;
	$tree = $tree->Next;
    }

    wantarray ? @r : "@r"; # what *should* this return in a scalar context?
}

sub get_file	{ shift->_xs->FindFile(@_) }
sub get_dir	{ shift->_xs->FindDir(@_) }
sub get_bool	{ shift->_xs->FindB(@_) }
sub set		{ shift->_xs->Set(@_) }
sub exists	{ shift->_xs->ExistsAny(@_) }
sub dump	{ shift->_xs->Dump(@_) }
sub read_file	{ shift->_xs->ReadConfigFile(@_) }
sub read_dir	{ shift->_xs->ReadConfigDir(@_) }

sub init
{
    AptPkg::_init_config shift->_xs;
}

sub system
{
    require AptPkg::System;
    AptPkg::_init_system shift->_xs;
}

sub parse_cmdline
{
    AptPkg::_parse_cmdline shift->_xs, @_;
}

sub AUTOLOAD
{
    (my $method = our $AUTOLOAD) =~ s/.*:://;

    return if $method eq 'DESTROY';

    my $self = shift;
    my $xs = $self->_xs;
    my $sub = $xs->can($method);

    croak "method `$method' not implemented" unless $sub;

    unshift @_, $xs;
    goto &$sub;
}

package AptPkg::Config::Iter;

sub new
{
    my $class = shift;
    my $obj = shift;
    my $self = $obj->_xs->Tree(@_);
    bless \$self, $class;
}

sub next
{
    my $self = shift;
    my $tree = $$self or return;
    my $key = $tree->FullTag;

    $$self = $tree->Child || $tree->Next;
    until ($$self)
    {
	last unless $tree = $tree->Parent;
	$$self = $tree->Next;
    }

    $key;
}

1;