Config::Apt::Sources - Parse and manipulate apt sources


Config-Apt-Sources documentation Contained in the Config-Apt-Sources distribution.

Index


Code Index:

NAME

Top

Config::Apt::Sources - Parse and manipulate apt sources

VERSION

Top

Version 0.10

SYNOPSIS

Top

    use Config::Apt::Sources;

    my $srcs = Config::Apt::Sources->new();
    $srcs->parse_stream(do { local $/; <> });

    my @sources = $srcs->get_sources();
    $sources[0]->set_uri("http://ftp.us.debian.org/debian/");
    $srcs->set_sources(@sources);
    print $srcs->to_string();

FUNCTIONS

Top

new

The Config::Apt::Sources constructor takes no arguments.

parse_stream

Parses the given string argument as the contents of an apt sources.list file.

    $srcs->parse_stream(do { local $/; <FILE> });

to_string

Returns the sources.list as a string. Takes no arguments.

    my $newsrcs = $srcs->to_string;

get_sources

Returns an array of Config::Apt::SourceEntry objects. Takes no arguments.

  my @sources = $srcs->get_sources();

set_sources

Reads an array of Config::Apt::SourceEntry objects. returns undef if any element is not a Config::Apt::SourceEntry object. Otherwise, returns 1.

  $srcs->set_sources(@sources);

AUTHOR

Top

Ian Kilgore, <iank at cpan.org>

BUGS

Top

Please report any bugs or feature requests to bug-config-apt-sources at rt.cpan.org, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Config-Apt-Sources. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.

SUPPORT

Top

You can find documentation for this module with the perldoc command.

    perldoc Config::Apt::Sources

You can also look for information at:

* AnnoCPAN: Annotated CPAN documentation

http://annocpan.org/dist/Config-Apt-Sources

* CPAN Ratings

http://cpanratings.perl.org/d/Config-Apt-Sources

* RT: CPAN's request tracker

http://rt.cpan.org/NoAuth/Bugs.html?Dist=Config-Apt-Sources

* Search CPAN

http://search.cpan.org/dist/Config-Apt-Sources

COPYRIGHT & LICENSE

Top


Config-Apt-Sources documentation Contained in the Config-Apt-Sources distribution.
package Config::Apt::Sources;

use warnings;
use strict;

use Carp;
use UNIVERSAL qw( isa );
use Config::Apt::SourceEntry;
our $VERSION = '0.10';

sub new {
  my ($class_name) = @_;
  my ($self) = { 'sources' => [ ] };

  bless($self, $class_name);
  return $self;
}

sub parse_stream {
  my $self = shift;
  my @lines = split("\n",shift);

  my @line;
  my @sources;
  for my $line (@lines) {
    next if $line =~ /(^\s*#|^$)/; # skip comments and blank lines
    chomp $line;
    push @sources,new Config::Apt::SourceEntry($line);
  }
  $self->{'sources'} = [ @sources ];
  return 1;
}

sub to_string {
  my $self = shift;
  my $ret = "";
  for (@{ $self->{'sources'} }) {
    $ret .= $_->to_string() . "\n";
  }
  return $ret;
}

sub get_sources {
  my $self = shift;
  return map { new Config::Apt::SourceEntry($_->to_string()) } @{$self->{'sources'}};
}

sub set_sources {
  my $self = shift;
  my @sources;

  foreach (@_) {
    unless (isa($_, 'Config::Apt::SourceEntry')) {
      carp "arguments must be Config::Apt::SourceEntry objects";
      return undef;
    }
    push @sources,$_;
  }
  $self->{'sources'} = [ @sources ];

  return 1;
}


1; # End of Config::Apt::Sources