| 1 | package Zonemaster::Util v1.0.0; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 1 | ▶ | use 5.14.2; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 1 | ▶ | use parent 'Exporter'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 1 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | 1 | ▶ | use Zonemaster; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | 1 | ▶ | use Zonemaster::DNSName; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | 1 | ▶ | use Pod::Simple::SimpleTree; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | ## no critic (Modules::ProhibitAutomaticExportation) | ||||||||||||||||||||||||||||
| 12 | 1 | our @EXPORT = qw[ ns info name pod_extract_for ]; | |||||||||||||||||||||||||||
| 13 | 1 | our @EXPORT_OK = qw[ ns info name pod_extract_for policy ]; | |||||||||||||||||||||||||||
| 14 | 1 | our %EXPORT_TAGS = ( all => \@EXPORT_OK ); | |||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||
| 16 | ## no critic (Subroutines::RequireArgUnpacking) | ||||||||||||||||||||||||||||
| 17 | sub ns { | ||||||||||||||||||||||||||||
| 18 | 0 | ▶ | return Zonemaster->ns( @_ ); | ||||||||||||||||||||||||||
|
Subroutine
ns: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 19 | } | ||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | sub info { | ||||||||||||||||||||||||||||
| 22 | 0 | ▶ | my ( $tag, $argref ) = @_; | ||||||||||||||||||||||||||
|
Subroutine
info: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||
| 24 | 0 | return Zonemaster->logger->add( $tag, $argref ); | |||||||||||||||||||||||||||
| 25 | } | ||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||
| 27 | sub policy { | ||||||||||||||||||||||||||||
| 28 | 0 | ▶ | return Zonemaster->config->policy; | ||||||||||||||||||||||||||
|
Subroutine
policy: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 29 | } | ||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||
| 31 | sub name { | ||||||||||||||||||||||||||||
| 32 | 0 | ▶ | my ( $name ) = @_; | ||||||||||||||||||||||||||
|
Subroutine
name: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||
| 34 | 0 | return Zonemaster::DNSName->new( $name ); | |||||||||||||||||||||||||||
| 35 | } | ||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||
| 37 | # Functions for extracting POD documentation from test modules | ||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||
| 39 | sub _pod_process_tree { | ||||||||||||||||||||||||||||
| 40 | 0 | ▶ | my ( $node, $flags ) = @_; | ||||||||||||||||||||||||||
|
Subroutine
_pod_process_tree: not called CC=9 SCAR=45.0
| |||||||||||||||||||||||||||||
| 41 | 0 | my ( $name, $ahash, @subnodes ) = @$node; | |||||||||||||||||||||||||||
| 42 | 0 | my @res; | |||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||
| 44 | 0 | ▶ | $flags //= {}; | ||||||||||||||||||||||||||
|
Condition0%0/2
$flags //= {}
MC/DC0%0/1
$flags //= {}
$flags
Truth table0%0/2
A
A= $flags
| |||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||
| 46 | 0 | foreach my $node ( @subnodes ) { | |||||||||||||||||||||||||||
| 47 | 0 | ▶ | if ( ref( $node ) ne 'ARRAY' ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 48 | 0 | ▶ | $flags->{tests} = 1 if $name eq 'head1' and $node eq 'TESTS'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$name eq "head1" and $node eq "TESTS"
MC/DC0%0/2
$name eq "head1" and $node eq "TESTS"
$name eq "head1"
$node eq "TESTS"
Truth table0%0/3
A and B
A= $name eq "head1"B= $node eq "TESTS"
| |||||||||||||||||||||||||||||
| 49 | 0 | ▶ | if ( $name eq 'item-text' and $flags->{tests} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$name eq "item-text" and $flags->{"tests"}
MC/DC0%0/2
$name eq "item-text" and $flags->{"tests"}
$name eq "item-text"
$flags->{"tests"}
Truth table0%0/3
A and B
A= $name eq "item-text"B= $flags->{"tests"}
| |||||||||||||||||||||||||||||
| 50 | 0 | $node =~ s/^(\w+).*$/$1/; | |||||||||||||||||||||||||||
| 51 | 0 | $flags->{item} = $node; | |||||||||||||||||||||||||||
| 52 | 0 | push @res, $node; | |||||||||||||||||||||||||||
| 53 | } | ||||||||||||||||||||||||||||
| 54 | } | ||||||||||||||||||||||||||||
| 55 | else { | ||||||||||||||||||||||||||||
| 56 | 0 | ▶ | if ( $flags->{item} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 57 | 0 | push @res, _pod_extract_text( $node ); | |||||||||||||||||||||||||||
| 58 | } | ||||||||||||||||||||||||||||
| 59 | else { | ||||||||||||||||||||||||||||
| 60 | 0 | push @res, _pod_process_tree( $node, $flags ); | |||||||||||||||||||||||||||
| 61 | } | ||||||||||||||||||||||||||||
| 62 | } | ||||||||||||||||||||||||||||
| 63 | } | ||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||
| 65 | 0 | return @res; | |||||||||||||||||||||||||||
| 66 | } ## end sub _pod_process_tree | ||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||
| 68 | sub _pod_extract_text { | ||||||||||||||||||||||||||||
| 69 | 0 | ▶ | my ( $node ) = @_; | ||||||||||||||||||||||||||
|
Subroutine
_pod_extract_text: not called CC=4 SCAR=30.0
| |||||||||||||||||||||||||||||
| 70 | 0 | my ( $name, $ahash, @subnodes ) = @$node; | |||||||||||||||||||||||||||
| 71 | 0 | my $res = ''; | |||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||
| 73 | 0 | foreach my $node ( @subnodes ) { | |||||||||||||||||||||||||||
| 74 | 0 | ▶ | if ( $name eq 'item-text' ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 75 | 0 | $node =~ s/^(\w+).*$/$1/; | |||||||||||||||||||||||||||
| 76 | } | ||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||
| 78 | 0 | ▶ | if ( ref( $node ) eq 'ARRAY' ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 79 | 0 | $res .= _pod_extract_text( $node ); | |||||||||||||||||||||||||||
| 80 | } | ||||||||||||||||||||||||||||
| 81 | else { | ||||||||||||||||||||||||||||
| 82 | 0 | $res .= $node; | |||||||||||||||||||||||||||
| 83 | } | ||||||||||||||||||||||||||||
| 84 | } | ||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||
| 86 | 0 | return $res; | |||||||||||||||||||||||||||
| 87 | } ## end sub _pod_extract_text | ||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||
| 89 | sub pod_extract_for { | ||||||||||||||||||||||||||||
| 90 | 0 | ▶ | my ( $name ) = @_; | ||||||||||||||||||||||||||
|
Subroutine
pod_extract_for: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||
| 92 | 0 | my $parser = Pod::Simple::SimpleTree->new; | |||||||||||||||||||||||||||
| 93 | 0 | $parser->no_whining( 1 ); | |||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||
| 95 | 0 | my %desc = eval { _pod_process_tree( $parser->parse_file( $INC{"Zonemaster/Test/$name.pm"} )->root ) }; | |||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||
| 97 | 0 | return \%desc; | |||||||||||||||||||||||||||
| 98 | } | ||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||
| 100 | 1 | 1; | |||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||
| 102 | =head1 NAME | ||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||
| 104 | Zonemaster::Util - utility functions for other Zonemaster modules | ||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||
| 106 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||
| 108 | use Zonemaster::Util; | ||||||||||||||||||||||||||||
| 109 | info(TAG => { some => 'argument'}); | ||||||||||||||||||||||||||||
| 110 | my $ns = ns($name, $address); | ||||||||||||||||||||||||||||
| 111 | my $name = name('whatever.example.org'); | ||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||
| 113 | =head1 EXPORTED FUNCTIONS | ||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||
| 115 | =over | ||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||
| 117 | =item info($tag, $href) | ||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||
| 119 | Creates and returns a L<Zonemaster::Logger::Entry> object. The object | ||||||||||||||||||||||||||||
| 120 | is also added to the global logger object's list of entries. | ||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||
| 122 | =item ns($name, $address) | ||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||
| 124 | Creates and returns a nameserver object with the given name and address. | ||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||
| 126 | =item policy() | ||||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||
| 128 | Returns a reference to the global policy hash. | ||||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||
| 130 | =item name($string_name_or_zone) | ||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||
| 132 | Creates and returns a L<Zonemaster::DNSName> object for the given argument. | ||||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||
| 134 | =item pod_extract_for($testname) | ||||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||
| 136 | Will attempt to extract the POD documentation for the test methods in | ||||||||||||||||||||||||||||
| 137 | the test module for which the name is given. If it can, it returns a | ||||||||||||||||||||||||||||
| 138 | reference to a hash where the keys are the test method names and the | ||||||||||||||||||||||||||||
| 139 | values the documentation strings. | ||||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||
| 141 | This method blindly assumes that the structure of the POD is exactly | ||||||||||||||||||||||||||||
| 142 | like that in the Example and Basic test modules. If it's not, the | ||||||||||||||||||||||||||||
| 143 | results are undefined. | ||||||||||||||||||||||||||||
| 144 | |||||||||||||||||||||||||||||
| 145 | =back | ||||||||||||||||||||||||||||