
# task.check – Validate flattened DNS BIND configuration in dot-per-line format
# Each line: <section>.<key> = <value>  (optionally followed by ;)
# Example lines:
#   options.directory = "/var/named";
#   zone.example.com.type = master
#   zone.example.com.file = "db.example.com";

# Soft check: options.directory
regexp: options \. directory \s* \= \s* \" (<-[ \"]>+ ) \" \s* \;?
code: <<CODE
!raku
if matched() {
    my $c = capture();
    update_state({ directory => $c[0] });
}
CODE
generator: <<CODE
!raku
if captures() -> @c {
    for @c -> $c {
        say "assert: 1 options.directory is '$c[0]'";
    }
} else {
    say "assert: 0 options.directory not found";
}
CODE

# Soft check: zone.<name>.type (master or slave)
regexp: zone \. ( <-[ \= ; ]>+ ) \. type \s* \= \s* ( master | slave ) \s* \;?
code: <<CODE
!raku
# capture handled in generator
CODE
generator: <<CODE
!raku
if captures() -> @c {
    for @c -> $c {
        my $zone = $c[0];
        my $type = $c[1];
        say "assert: 1 zone $zone type is $type";
    }
} else {
    say "assert: 0 no zone type definitions found";
}
CODE

# Soft check: zone.<name>.file
regexp: zone \. ( <-[ \= ; ]>+ ) \. file \s* \= \s* \" ( <-[ \"]>+ ) \" \s* \;?
code: <<CODE
!raku
# capture handled in generator
CODE
generator: <<CODE
!raku
if captures() -> @c {
    for @c -> $c {
        my $zone = $c[0];
        my $file = $c[1];
        my $nonempty = $file ne '';
        say "assert: {$nonempty} zone $zone file is '$file'";
    }
} else {
    say "assert: 0 no zone file definitions found";
}
CODE

# Soft check: zone.<name>.masters (optional)
regexp: zone \. ( <-[ \= ; ]>+ ) \. masters \s* \= \s* \{ \s* ( <-[ } ]>+ ) \s* \} \s* \;?
code: <<CODE
!raku
# capture handled in generator
CODE
generator: <<CODE
!raku
if captures() -> @c {
    for @c -> $c {
        my $zone = $c[0];
        my $masters = $c[1];
        say "assert: 1 zone $zone masters configured: $masters";
    }
} else {
    say "assert: 0 no zone masters definitions found (optional)";
}
CODE