AllKnowingDNS

 view release on metacpan or  search on metacpan

lib/App/AllKnowingDNS/Util.pm  view on Meta::CPAN

# vim:ts=4:sw=4:expandtab
package App::AllKnowingDNS::Util;

use strict;
use warnings;
use Exporter 'import';
use App::AllKnowingDNS::Config;
use App::AllKnowingDNS::Zone;
use NetAddr::IP::Util qw(ipv6_aton);
use v5.10;

=head1 NAME

App::AllKnowingDNS::Util - utility functions

=head1 DESCRIPTION

Note: User documentation is in L<all-knowing-dns>(1).

=head1 FUNCTIONS

=cut

our @EXPORT = qw(parse_config netmask_to_ptrzone);

=head2 parse_config($lines)

Parses a block of text as configfile.

Returns a corresponding App::AllKnowingDNS::Config object.

=cut

sub parse_config {
    my ($input) = @_;
    my $config = App::AllKnowingDNS::Config->new;

    my @lines = split("\n", $input);
    my $current_zone;
    for my $line (@lines) {
        # Strip whitespace.
        $line =~ s/^\s+//;

        # Ignore comments.
        next if substr($line, 0, 1) eq '#';

        # Skip empty lines
        next if length($line) == 0;

        # If we are not currently parsing a zone, only the 'network' keyword is
        # appropriate.
        if (!defined($current_zone) &&
            !($line =~ /^network/i) && !($line =~ /^listen/i)) {
            say STDERR qq|all-knowing-dns: CONFIG: Expected 'network' or 'listen' keyword in line "$line"|;
            next;
        }

        if (my ($address) = ($line =~ /^listen (.*)/i)) {
            $config->add_listen_address(lc $address);
            next;
        }



( run in 0.984 second using v1.01-cache-2.11-cpan-97f6503c9c8 )