| 1 | # lib/Config/INI/RefVars/Builtins.pm | ||||||||||||||||||||||||||||
| 2 | package Config::INI::RefVars::Builtins; | ||||||||||||||||||||||||||||
| 3 | |||||||||||||||||||||||||||||
| 4 | 31 | ▶ | use 5.010; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 31 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | 31 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | 31 | ▶ | use File::Spec::Functions;# qw(catdir catfile); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | 31 | ▶ | use File::Basename qw(dirname basename); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | 31 | our $VERSION = '1.07'; | |||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | 192 | ▶ | sub default_dispatch_table { | ||||||||||||||||||||||||||
|
Subroutine
default_dispatch_table: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 16 | return { | ||||||||||||||||||||||||||||
| 17 | 192 | catdir => \&File::Spec::Functions::catdir, | |||||||||||||||||||||||||||
| 18 | catfile => \&File::Spec::Functions::catfile, | ||||||||||||||||||||||||||||
| 19 | catpath => \&_catpath, | ||||||||||||||||||||||||||||
| 20 | ignore => \&_ignore, | ||||||||||||||||||||||||||||
| 21 | concat => \&_concat, | ||||||||||||||||||||||||||||
| 22 | join => \&_join, | ||||||||||||||||||||||||||||
| 23 | substr => \&_substr, | ||||||||||||||||||||||||||||
| 24 | x => \&_x, | ||||||||||||||||||||||||||||
| 25 | 'and' => \&_and, | ||||||||||||||||||||||||||||
| 26 | 'or' => \&_or, | ||||||||||||||||||||||||||||
| 27 | 'if' => \&_if, | ||||||||||||||||||||||||||||
| 28 | s => \&_s, | ||||||||||||||||||||||||||||
| 29 | tr => \&_tr, | ||||||||||||||||||||||||||||
| 30 | m => \&_m, | ||||||||||||||||||||||||||||
| 31 | not => \&_not, | ||||||||||||||||||||||||||||
| 32 | eq => \&_eq, | ||||||||||||||||||||||||||||
| 33 | dirname => \&dirname, | ||||||||||||||||||||||||||||
| 34 | basename => \&basename, | ||||||||||||||||||||||||||||
| 35 | }; | ||||||||||||||||||||||||||||
| 36 | } | ||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||
| 38 | 0 | ▶ | sub _catpath { | ||||||||||||||||||||||||||
|
Subroutine
_catpath: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||
| 39 | 0 | ▶ | die("catpath: expected 3 arguments\n") unless @_ == 3; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 40 | 0 | return File::Spec::Functions::catpath(@_); | |||||||||||||||||||||||||||
| 41 | } | ||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||
| 44 | 2 | ▶ | sub _clean_error { | ||||||||||||||||||||||||||
|
Subroutine
_clean_error: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 45 | 2 | my ($error) = @_; | |||||||||||||||||||||||||||
| 46 | 2 | chomp($error); | |||||||||||||||||||||||||||
| 47 | 2 | $error =~ s/\s+at\s+\S+\s+line\s+\d+\.?\z//; | |||||||||||||||||||||||||||
| 48 | 2 | return $error; | |||||||||||||||||||||||||||
| 49 | } | ||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||
| 52 | 12 | ▶ | sub _ignore { | ||||||||||||||||||||||||||
|
Subroutine
_ignore: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 53 | 12 | return ""; | |||||||||||||||||||||||||||
| 54 | } | ||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||
| 57 | 9 | ▶ | sub _concat { | ||||||||||||||||||||||||||
|
Subroutine
_concat: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 58 | 9 | return join("", @_); | |||||||||||||||||||||||||||
| 59 | } | ||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||
| 62 | 14 | ▶ | sub _join { | ||||||||||||||||||||||||||
|
Subroutine
_join: called CC=2 SCAR=7.6
| |||||||||||||||||||||||||||||
| 63 | 14 | ▶ | return @_ ? join(shift(@_), @_) : ""; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 64 | } | ||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||
| 67 | 8 | ▶ | sub _substr { | ||||||||||||||||||||||||||
|
Subroutine
_substr: called CC=5 SCAR=16.1
| |||||||||||||||||||||||||||||
| 68 | 8 | ▶ | die("substr: expected 2 or 3 arguments\n") if @_ < 2 || @_ > 3; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
@_ < 2 or @_ > 3
MC/DC100%2/2
@_ < 2 or @_ > 3
@_ < 2
@_ > 3
Truth table100%3/3
A or B
A= @_ < 2B= @_ > 3
| |||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||
| 70 | 5 | my $warning = ""; | |||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||
| 72 | 2 | ▶ | local $SIG{__WARN__} = sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 73 | 2 | $warning = _clean_error($_[0]); | |||||||||||||||||||||||||||
| 74 | 5 | }; | |||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||
| 76 | 5 | ▶ | my $result = @_ == 2 | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 77 | ? substr($_[0], $_[1]) : substr($_[0], $_[1], $_[2]); | ||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||
| 79 | 5 | ▶ | die("substr: $warning\n") if $warning ne ""; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 80 | 3 | return $result; | |||||||||||||||||||||||||||
| 81 | } | ||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||
| 84 | 3 | ▶ | sub _x { | ||||||||||||||||||||||||||
|
Subroutine
_x: called CC=3 SCAR=11.4
| |||||||||||||||||||||||||||||
| 85 | 3 | ▶ | die("x: expected 2 arguments\n") if @_ != 2; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||
| 87 | 3 | my ($str, $n) = @_; | |||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||
| 89 | 3 | ▶ | die("x: second argument must be a non-negative integer\n") | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 90 | unless $n =~ /^\+?[0-9]+$/; | ||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||
| 92 | 3 | return $str x $n; | |||||||||||||||||||||||||||
| 93 | } | ||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||
| 96 | 5 | ▶ | sub _and { | ||||||||||||||||||||||||||
|
Subroutine
_and: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||
| 97 | 5 | foreach my $arg (@_) { | |||||||||||||||||||||||||||
| 98 | 8 | ▶ | return "" if $arg eq ""; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 99 | } | ||||||||||||||||||||||||||||
| 100 | 3 | ▶ | return @_ ? $_[-1] : ""; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 101 | } | ||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||
| 104 | 5 | ▶ | sub _or { | ||||||||||||||||||||||||||
|
Subroutine
_or: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||
| 105 | 5 | foreach my $arg (@_) { | |||||||||||||||||||||||||||
| 106 | 8 | ▶ | return $arg if $arg ne ""; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 107 | } | ||||||||||||||||||||||||||||
| 108 | 2 | return ""; | |||||||||||||||||||||||||||
| 109 | } | ||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||
| 112 | 6 | ▶ | sub _if { | ||||||||||||||||||||||||||
|
Subroutine
_if: called CC=5 SCAR=17.1
| |||||||||||||||||||||||||||||
| 113 | 6 | ▶ | die("if: expected 2 or 3 arguments\n") if @_ < 2 || @_ > 3; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
@_ < 2 or @_ > 3
MC/DC0%0/2
@_ < 2 or @_ > 3
@_ < 2
@_ > 3
Truth table33%1/3
A or B
A= @_ < 2B= @_ > 3
| |||||||||||||||||||||||||||||
| 114 | 6 | ▶ | return $_[0] ne "" ? $_[1] : ($_[2] // ""); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%2/2
$_[2] // ""
MC/DC100%1/1
$_[2] // ""
$_[2]
Truth table100%2/2
A
A= $_[2]
| |||||||||||||||||||||||||||||
| 115 | } | ||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||
| 118 | 10 | ▶ | sub _s { | ||||||||||||||||||||||||||
|
Subroutine
_s: called CC=9 SCAR=22.0
| |||||||||||||||||||||||||||||
| 119 | 10 | ▶ | die("s: expected 3 or 4 arguments\n") if @_ < 3 || @_ > 4; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
@_ < 3 or @_ > 4
MC/DC50%1/2
@_ < 3 or @_ > 4
@_ < 3
@_ > 4
Truth table66%2/3
A or B
A= @_ < 3B= @_ > 4
| |||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||
| 121 | 9 | my ($str, $pattern, $replacement, $mods) = @_; | |||||||||||||||||||||||||||
| 122 | 9 | ▶ | $mods //= ""; | ||||||||||||||||||||||||||
|
Condition100%2/2
$mods //= ""
MC/DC100%1/1
$mods //= ""
$mods
Truth table100%2/2
A
A= $mods
| |||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||
| 124 | 9 | ▶ | die("s: unsupported modifier '$mods'\n") if $mods !~ /^[gimsx]*$/; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||
| 126 | 7 | ▶ | die("s: regex code blocks are not allowed\n") if $pattern =~ /\(\?\??\{/; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||
| 128 | 5 | my $global = $mods =~ s/g//g; | |||||||||||||||||||||||||||
| 129 | 5 | ▶ | my $re = eval { $mods eq "" ? qr/$pattern/ : qr/(?$mods:$pattern)/; }; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 130 | 5 | ▶ | die("s: ", _clean_error($@), "\n") if $@; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||
| 132 | 5 | ▶ | if ($global) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 133 | 2 | $str =~ s/$re/$replacement/g; | |||||||||||||||||||||||||||
| 134 | } | ||||||||||||||||||||||||||||
| 135 | else { | ||||||||||||||||||||||||||||
| 136 | 3 | $str =~ s/$re/$replacement/; | |||||||||||||||||||||||||||
| 137 | } | ||||||||||||||||||||||||||||
| 138 | 5 | return $str; | |||||||||||||||||||||||||||
| 139 | } | ||||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||
| 141 | |||||||||||||||||||||||||||||
| 142 | 5 | ▶ | sub _pick_tr_delim { | ||||||||||||||||||||||||||
|
Subroutine
_pick_tr_delim: called CC=4 SCAR=14.5
| |||||||||||||||||||||||||||||
| 143 | 5 | my @values = @_; | |||||||||||||||||||||||||||
| 144 | |||||||||||||||||||||||||||||
| 145 | 31 | ▶ | no warnings 'qw'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 146 | 5 | foreach my $delim (qw(| ! / : ; # ~ @ % ^ * + = ?)) { | |||||||||||||||||||||||||||
| 147 | 5 | ▶ | return $delim if !grep { index($_ // "", $delim) >= 0 } @values; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%1/2
$_ // ""
MC/DC0%0/1
$_ // ""
$_
Truth table50%1/2
A
A= $_
| |||||||||||||||||||||||||||||
| 148 | } | ||||||||||||||||||||||||||||
| 149 | 0 | die("tr: no safe delimiter found\n"); | |||||||||||||||||||||||||||
| 150 | } | ||||||||||||||||||||||||||||
| 151 | |||||||||||||||||||||||||||||
| 152 | |||||||||||||||||||||||||||||
| 153 | 8 | ▶ | sub _tr { | ||||||||||||||||||||||||||
|
Subroutine
_tr: called CC=6 SCAR=18.0
| |||||||||||||||||||||||||||||
| 154 | 8 | ▶ | die("tr: expected 3 or 4 arguments\n") if @_ < 3 || @_ > 4; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
@_ < 3 or @_ > 4
MC/DC50%1/2
@_ < 3 or @_ > 4
@_ < 3
@_ > 4
Truth table66%2/3
A or B
A= @_ < 3B= @_ > 4
| |||||||||||||||||||||||||||||
| 155 | |||||||||||||||||||||||||||||
| 156 | 7 | my ($str, $search, $replacement, $mods) = @_; | |||||||||||||||||||||||||||
| 157 | 7 | ▶ | $mods //= ""; | ||||||||||||||||||||||||||
|
Condition100%2/2
$mods //= ""
MC/DC100%1/1
$mods //= ""
$mods
Truth table100%2/2
A
A= $mods
| |||||||||||||||||||||||||||||
| 158 | |||||||||||||||||||||||||||||
| 159 | 7 | ▶ | die("tr: unsupported modifier '$mods'\n") if $mods !~ /^[cds]*$/; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 160 | |||||||||||||||||||||||||||||
| 161 | 5 | my $delim = _pick_tr_delim($search, $replacement); | |||||||||||||||||||||||||||
| 162 | 5 | my $code = "\$str =~ tr${delim}${search}${delim}${replacement}${delim}${mods};"; | |||||||||||||||||||||||||||
| 163 | 5 | ▶ | eval "$code; 1" or die("tr: ", _clean_error($@), "\n"); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 164 | |||||||||||||||||||||||||||||
| 165 | 5 | return $str; | |||||||||||||||||||||||||||
| 166 | } | ||||||||||||||||||||||||||||
| 167 | |||||||||||||||||||||||||||||
| 168 | |||||||||||||||||||||||||||||
| 169 | 6 | ▶ | sub _m { | ||||||||||||||||||||||||||
|
Subroutine
_m: called CC=9 SCAR=24.3
| |||||||||||||||||||||||||||||
| 170 | 6 | ▶ | die("m: expected 2 or 3 arguments\n") if @_ < 2 || @_ > 3; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
@_ < 2 or @_ > 3
MC/DC0%0/2
@_ < 2 or @_ > 3
@_ < 2
@_ > 3
Truth table33%1/3
A or B
A= @_ < 2B= @_ > 3
| |||||||||||||||||||||||||||||
| 171 | |||||||||||||||||||||||||||||
| 172 | 6 | my ($str, $pattern, $mods) = @_; | |||||||||||||||||||||||||||
| 173 | 6 | ▶ | $mods //= ""; | ||||||||||||||||||||||||||
|
Condition50%1/2
$mods //= ""
MC/DC0%0/1
$mods //= ""
$mods
Truth table50%1/2
A
A= $mods
| |||||||||||||||||||||||||||||
| 174 | |||||||||||||||||||||||||||||
| 175 | 6 | ▶ | die("m: unsupported modifier '$mods'\n") if $mods !~ /^[imsx]*$/; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 176 | 6 | ▶ | die("m: regex code blocks are not allowed\n") if $pattern =~ /\(\?\??\{/; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 177 | |||||||||||||||||||||||||||||
| 178 | 6 | ▶ | my $re = eval { $mods eq "" ? qr/$pattern/ : qr/(?$mods:$pattern)/; }; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 179 | 6 | ▶ | die("m: ", _clean_error($@), "\n") if $@; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 180 | |||||||||||||||||||||||||||||
| 181 | 6 | ▶ | return $str =~ $re ? "1" : ""; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 182 | } | ||||||||||||||||||||||||||||
| 183 | |||||||||||||||||||||||||||||
| 184 | |||||||||||||||||||||||||||||
| 185 | 1 | ▶ | sub _not { | ||||||||||||||||||||||||||
|
Subroutine
_not: called CC=3 SCAR=12.0
| |||||||||||||||||||||||||||||
| 186 | 1 | ▶ | die("not: expected 1 argument\n") if @_ != 1; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 187 | 1 | ▶ | return $_[0] eq "" ? "1" : ""; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 188 | } | ||||||||||||||||||||||||||||
| 189 | |||||||||||||||||||||||||||||
| 190 | |||||||||||||||||||||||||||||
| 191 | 1 | ▶ | sub _eq { | ||||||||||||||||||||||||||
|
Subroutine
_eq: called CC=3 SCAR=12.0
| |||||||||||||||||||||||||||||
| 192 | 1 | ▶ | die("eq: expected 2 arguments\n") if @_ != 2; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 193 | 1 | ▶ | return $_[0] eq $_[1] ? "1" : ""; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 194 | } | ||||||||||||||||||||||||||||
| 195 | |||||||||||||||||||||||||||||
| 196 | 31 | 1; | |||||||||||||||||||||||||||
| 197 | |||||||||||||||||||||||||||||
| 198 | |||||||||||||||||||||||||||||
| 199 | __END__ | ||||||||||||||||||||||||||||