| 1 | package Config::XrmDatabase::Util; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||
| 3 | # ABSTRACT: Constants that won't change, and other utilitarian things. | ||||||||||||||||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||||||||||||||||
| 5 | 10 | ▶ | use v5.26; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 6 | 10 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||||||||||||
| 8 | 10 | our $VERSION = '0.09'; | |||||||||||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||||||||||||
| 10 | 10 | ▶ | use Config::XrmDatabase::Failure ':all'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||||||||||||
| 12 | 10 | ▶ | use namespace::clean; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||||||||||||
| 14 | 10 | ▶ | use Exporter 'import'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||||||||||||
| 16 | 10 | ▶ | use experimental qw( signatures postderef ); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||||||||||||
| 18 | 10 | my %CONSTANTS; | |||||||||||||||||||||||||||||||||||||||||
| 19 | 10 | our ( %META, %RMETA ); # these get exported | |||||||||||||||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||||||||||||||||
| 21 | 10 | ▶ | BEGIN { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 22 | 10 | %CONSTANTS = ( | |||||||||||||||||||||||||||||||||||||||||
| 23 | TIGHT => q{.}, | ||||||||||||||||||||||||||||||||||||||||||
| 24 | SINGLE => q{?}, | ||||||||||||||||||||||||||||||||||||||||||
| 25 | LOOSE => q{*}, | ||||||||||||||||||||||||||||||||||||||||||
| 26 | VALUE => '!!VALUE', | ||||||||||||||||||||||||||||||||||||||||||
| 27 | MATCH_COUNT => '!!MATCH_COUNT', | ||||||||||||||||||||||||||||||||||||||||||
| 28 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||||||||||||||||
| 30 | %META = ( | ||||||||||||||||||||||||||||||||||||||||||
| 31 | $CONSTANTS{VALUE} => 'value', | ||||||||||||||||||||||||||||||||||||||||||
| 32 | 10 | $CONSTANTS{MATCH_COUNT} => 'match_count', | |||||||||||||||||||||||||||||||||||||||||
| 33 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 34 | 10 | %RMETA = reverse %META; | |||||||||||||||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||||||||||||||||
| 36 | 10 | $CONSTANTS{META_QR} = qr/@{[ join '|', map { quotemeta } keys %META ]}/i; | |||||||||||||||||||||||||||||||||||||||||
| 37 | } | ||||||||||||||||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||||||||||||||||
| 39 | # so we can use the scalars here without complaints | ||||||||||||||||||||||||||||||||||||||||||
| 40 | 10 | ▶ | use vars map { q{$} . $_ } keys %CONSTANTS; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 41 | { | ||||||||||||||||||||||||||||||||||||||||||
| 42 | 10 | ▶ | no strict 'refs'; ## no critic(ProhibitNoStrict) | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 43 | 10 | *{$_} = \( $CONSTANTS{$_} ) for keys %CONSTANTS; | |||||||||||||||||||||||||||||||||||||||||
| 44 | } | ||||||||||||||||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||||||||||||||||
| 46 | 10 | ▶ | use constant \%CONSTANTS; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||||||||||||||||
| 48 | 10 | our %EXPORT_TAGS = ( | |||||||||||||||||||||||||||||||||||||||||
| 49 | scalar => [ map "\$$_", keys( %CONSTANTS ) ], | ||||||||||||||||||||||||||||||||||||||||||
| 50 | constants => [ keys( %CONSTANTS ) ], | ||||||||||||||||||||||||||||||||||||||||||
| 51 | hashes => [qw( %META %RMETA )], | ||||||||||||||||||||||||||||||||||||||||||
| 52 | funcs => [ | ||||||||||||||||||||||||||||||||||||||||||
| 53 | qw( parse_resource_name parse_fq_resource_name | ||||||||||||||||||||||||||||||||||||||||||
| 54 | normalize_key name_arr_to_str is_binding_operator is_wildcard ), | ||||||||||||||||||||||||||||||||||||||||||
| 55 | ], | ||||||||||||||||||||||||||||||||||||||||||
| 56 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||||||||||||||||
| 59 | 10 | our @EXPORT_OK = ( map { @$_ } values %EXPORT_TAGS ); | |||||||||||||||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||||||||||||||||
| 61 | 10 | $EXPORT_TAGS{all} = \@EXPORT_OK; | |||||||||||||||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||||||||||||||||
| 73 | 1621 | ▶ | sub parse_resource_name ( $name ) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
parse_resource_name: called CC=5 SCAR=16.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||||||||||||||||
| 75 | { | ||||||||||||||||||||||||||||||||||||||||||
| 76 | ## no critic (AmbiguousNames) | ||||||||||||||||||||||||||||||||||||||||||
| 77 | 1621 | my $last = substr( $name, -1 ); | |||||||||||||||||||||||||||||||||||||||||
| 78 | 1621 | ▶ | key_failure->throw( "last component of name may not be a binding operator: $name" ) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%6/6
$last eq "." or $last eq "?" or $last eq "*"
$last eq "." or $last eq "?"
MC/DC100%3/3
$last eq "." or $last eq "?" or $last eq "*"
$last eq "."
$last eq "?"
$last eq "*"
Truth table100%4/4
A or B or C
A= $last eq "."B= $last eq "?"C= $last eq "*"
| |||||||||||||||||||||||||||||||||||||||||||
| 79 | if $last eq TIGHT || $last eq SINGLE || $last eq LOOSE; | ||||||||||||||||||||||||||||||||||||||||||
| 80 | } | ||||||||||||||||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||||||||||||||||
| 82 | # all consecutive '.' characters are replaced with a single one. | ||||||||||||||||||||||||||||||||||||||||||
| 83 | 1618 | $name =~ s/[$TIGHT]+/$TIGHT/g; | |||||||||||||||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||||||||||||||||
| 85 | # any combination of '.' and '*' is replaced with a '*' | ||||||||||||||||||||||||||||||||||||||||||
| 86 | 1618 | $name =~ s/[${TIGHT}${LOOSE}]{2,}/$LOOSE/g; | |||||||||||||||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||||||||||||||||
| 88 | # toss out fields: | ||||||||||||||||||||||||||||||||||||||||||
| 89 | # - the tight binding operator; that is the default. | ||||||||||||||||||||||||||||||||||||||||||
| 90 | # - empty fields correspond to two sequential binding operators | ||||||||||||||||||||||||||||||||||||||||||
| 91 | # or a leading binding operator | ||||||||||||||||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||||||||||||||||
| 93 | return [ | ||||||||||||||||||||||||||||||||||||||||||
| 94 | 1618 | ▶ | grep { $_ ne TIGHT && $_ ne q{} } | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%3/3
$_ ne '.' && $_ ne ''
MC/DC100%2/2
$_ ne '.' && $_ ne ''
$_ ne '.'
$_ ne ''
Truth table100%3/3
A && B
A= $_ ne '.'B= $_ ne ''
| |||||||||||||||||||||||||||||||||||||||||||
| 95 | split( /([${TIGHT}${SINGLE}${LOOSE}])/, $name ) ]; | ||||||||||||||||||||||||||||||||||||||||||
| 96 | } | ||||||||||||||||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||||||||||||||||
| 108 | 81 | ▶ | sub parse_fq_resource_name ( $name ) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
parse_fq_resource_name: called CC=6 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||||||||||||||||
| 110 | 81 | ▶ | key_failure->throw( | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
index($name, "?") != -1 or index($name, "*") != -1
MC/DC100%2/2
index($name, "?") != -1 or index($name, "*") != -1
index($name, "?") != -1
index($name, "*") != -1
Truth table100%3/3
A or B
A= index($name, "?") != -1B= index($name, "*") != -1
| |||||||||||||||||||||||||||||||||||||||||||
| 111 | "cannot have '$LOOSE' or '$SINGLE' binding operators in a fully qualified name: $name", ) | ||||||||||||||||||||||||||||||||||||||||||
| 112 | if index( $name, SINGLE ) != -1 | ||||||||||||||||||||||||||||||||||||||||||
| 113 | or index( $name, LOOSE ) != -1; | ||||||||||||||||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||||||||||||||||
| 115 | 78 | ▶ | key_failure->throw( | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 116 | "cannot have multiple sequential '$TIGHT' binding operators in a fully qualified name: $name", ) | ||||||||||||||||||||||||||||||||||||||||||
| 117 | if $name =~ /[$TIGHT]{2,}/; | ||||||||||||||||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||||||||||||||||
| 119 | 77 | ▶ | key_failure->throw( | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 120 | "last component of a fully qualified name must not be a binding operator: $name", ) | ||||||||||||||||||||||||||||||||||||||||||
| 121 | if substr( $name, -1 ) eq TIGHT; | ||||||||||||||||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||||||||||||||||
| 123 | 77 | ▶ | key_failure->throw( | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 124 | "first component of a fully qualified name must not be a binding operator: $name", ) | ||||||||||||||||||||||||||||||||||||||||||
| 125 | if substr( $name, 0, 1 ) eq TIGHT; | ||||||||||||||||||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||||||||||||||||
| 127 | 76 | return [ split( /[$TIGHT]/, $name ) ]; | |||||||||||||||||||||||||||||||||||||||||
| 128 | } | ||||||||||||||||||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||||||||||||||||
| 137 | |||||||||||||||||||||||||||||||||||||||||||
| 138 | |||||||||||||||||||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||||||||||||||||
| 140 | 1536 | ▶ | sub normalize_key( $key ) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
normalize_key: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 141 | 1536 | $key =~ s/[$TIGHT]?[$LOOSE][$TIGHT]?/$LOOSE/g; | |||||||||||||||||||||||||||||||||||||||||
| 142 | 1536 | return $key; | |||||||||||||||||||||||||||||||||||||||||
| 143 | } | ||||||||||||||||||||||||||||||||||||||||||
| 144 | |||||||||||||||||||||||||||||||||||||||||||
| 145 | |||||||||||||||||||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||||||||||||||||
| 147 | |||||||||||||||||||||||||||||||||||||||||||
| 148 | |||||||||||||||||||||||||||||||||||||||||||
| 149 | |||||||||||||||||||||||||||||||||||||||||||
| 150 | |||||||||||||||||||||||||||||||||||||||||||
| 151 | |||||||||||||||||||||||||||||||||||||||||||
| 152 | |||||||||||||||||||||||||||||||||||||||||||
| 153 | 6 | ▶ | sub name_arr_to_str ( $name_arr ) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
name_arr_to_str: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 154 | 6 | return normalize_key( join( +TIGHT, @$name_arr ) ); | |||||||||||||||||||||||||||||||||||||||||
| 155 | } | ||||||||||||||||||||||||||||||||||||||||||
| 156 | |||||||||||||||||||||||||||||||||||||||||||
| 157 | |||||||||||||||||||||||||||||||||||||||||||
| 158 | |||||||||||||||||||||||||||||||||||||||||||
| 159 | |||||||||||||||||||||||||||||||||||||||||||
| 160 | |||||||||||||||||||||||||||||||||||||||||||
| 161 | |||||||||||||||||||||||||||||||||||||||||||
| 162 | |||||||||||||||||||||||||||||||||||||||||||
| 163 | |||||||||||||||||||||||||||||||||||||||||||
| 164 | |||||||||||||||||||||||||||||||||||||||||||
| 165 | 13 | ▶ | sub is_binding_operator( $string ) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
is_binding_operator: called CC=2 SCAR=7.2
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 166 | 13 | ▶ | return $string eq TIGHT || $string eq LOOSE; | ||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$string eq '.' || $string eq '*'
MC/DC100%2/2
$string eq '.' || $string eq '*'
$string eq '.'
$string eq '*'
Truth table100%3/3
A || B
A= $string eq '.'B= $string eq '*'
| |||||||||||||||||||||||||||||||||||||||||||
| 167 | } | ||||||||||||||||||||||||||||||||||||||||||
| 168 | |||||||||||||||||||||||||||||||||||||||||||
| 169 | |||||||||||||||||||||||||||||||||||||||||||
| 170 | |||||||||||||||||||||||||||||||||||||||||||
| 171 | |||||||||||||||||||||||||||||||||||||||||||
| 172 | |||||||||||||||||||||||||||||||||||||||||||
| 173 | |||||||||||||||||||||||||||||||||||||||||||
| 174 | |||||||||||||||||||||||||||||||||||||||||||
| 175 | |||||||||||||||||||||||||||||||||||||||||||
| 176 | |||||||||||||||||||||||||||||||||||||||||||
| 177 | |||||||||||||||||||||||||||||||||||||||||||
| 178 | |||||||||||||||||||||||||||||||||||||||||||
| 179 | |||||||||||||||||||||||||||||||||||||||||||
| 180 | |||||||||||||||||||||||||||||||||||||||||||
| 181 | |||||||||||||||||||||||||||||||||||||||||||
| 182 | |||||||||||||||||||||||||||||||||||||||||||
| 183 | |||||||||||||||||||||||||||||||||||||||||||
| 184 | |||||||||||||||||||||||||||||||||||||||||||
| 185 | |||||||||||||||||||||||||||||||||||||||||||
| 186 | |||||||||||||||||||||||||||||||||||||||||||
| 187 | 5 | ▶ | sub is_wildcard( $string ) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
is_wildcard: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 188 | 5 | warnings::warnif( 'deprecated', | |||||||||||||||||||||||||||||||||||||||||
| 189 | 'Config::XrmDatabase::Util::is_wildcard is deprecated; use is_binding_operator instead' ); | ||||||||||||||||||||||||||||||||||||||||||
| 190 | 5 | return is_binding_operator( $string ); | |||||||||||||||||||||||||||||||||||||||||
| 191 | } | ||||||||||||||||||||||||||||||||||||||||||
| 192 | |||||||||||||||||||||||||||||||||||||||||||
| 193 | 10 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 194 | |||||||||||||||||||||||||||||||||||||||||||
| 195 | # | ||||||||||||||||||||||||||||||||||||||||||
| 196 | # This file is part of Config-XrmDatabase | ||||||||||||||||||||||||||||||||||||||||||
| 197 | # | ||||||||||||||||||||||||||||||||||||||||||
| 198 | # This software is Copyright (c) 2021 by Smithsonian Astrophysical Observatory. | ||||||||||||||||||||||||||||||||||||||||||
| 199 | # | ||||||||||||||||||||||||||||||||||||||||||
| 200 | # This is free software, licensed under: | ||||||||||||||||||||||||||||||||||||||||||
| 201 | # | ||||||||||||||||||||||||||||||||||||||||||
| 202 | # The GNU General Public License, Version 3, June 2007 | ||||||||||||||||||||||||||||||||||||||||||
| 203 | # | ||||||||||||||||||||||||||||||||||||||||||
| 204 | |||||||||||||||||||||||||||||||||||||||||||
| 205 | __END__ | ||||||||||||||||||||||||||||||||||||||||||