| 1 | package App::IniDiff::IniFile; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | 19 | ▶ | use 5.006; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | 19 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | 19 | ▶ | use Carp; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | =head1 NAME | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | App::IniDiff::IniFile - perl module to diff and patch .ini files | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | =head1 VERSION | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | Version 0.19 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | 19 | ▶ | use vars qw($VERSION); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | 19 | $VERSION = '0.19'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | IniFile.pm - perl module to diff and patch .ini files | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | This file contains the following: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | =over 4 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | =item * package App::IniDiff::IniFile; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | =item * package App::IniDiff::IniFile::Field; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | =item * package App::IniDiff::IniFile::Key; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | =item * package App::IniDiff::IniFile::Filter; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | =back | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | Creates the following data structure: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | 'nextOrderId' => some-number, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | 'keys' => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | 'name' => "...", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | 'orderId' => some number, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | 'fields' => [ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | 'name' => "..." | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | 'value' => "...", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | 'deleted' => 0 or 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | 'annotation' => "...", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | ... | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | ], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | 'deleted' => 0 or 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | 'annotation' => "...", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | ... | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | =over 4 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | =item * 'orderId' is used to preserve the order in which keys appear in a file. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | =item * 'annotation' is used to decorate inidiff output. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | =item * 'deleted' is used when generating, writing, reading, and applying patch files. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | =back | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | Some terms used differ from what is normally used in WinINI file-speak | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | =over 4 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | =item * 'key' is INI 'section' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | =item * 'field' is INI 'entry' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | =item * 'field name' is INI 'key' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | =item * 'field value' is INI 'value' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | =back | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | 19 | ▶ | use vars qw(&new &write &findKey &keys &removekey &addKey); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | # added eol to support old end of line \r\n | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | 19 | ▶ | use vars qw($errorString $eol $commentchars); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | package App::IniDiff::IniFile::Field; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | 19 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | 19 | ▶ | use Carp; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | 19 | ▶ | use vars qw(&new &name &canonName &value &deleted &annotation | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | 19 | &setFrom &write &canonicalize ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | 19 | ▶ | use vars qw($eol); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | # end of line character - eol | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | 19 | $eol = "\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | sub new | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | 493 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=3 SCAR=11.6
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | 493 | my $proto = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | 493 | ▶ | confess "new App::IniDiff::IniFile::Field takes 4 arguments" if @_ != 4; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | 493 | my ($name, $value, $del, $annotation) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | 493 | my $field = { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | 'name' => $name, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | 'canonName' => canonicalize($name), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | 'value' => $value, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | 'deleted' => $del, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | 'annotation' => $annotation, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | 493 | ▶ | bless $field, (ref($proto) || $proto); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
ref $proto || $proto
MC/DC0%0/2
ref $proto || $proto
ref $proto
$proto
Truth table33%1/3
A || B
A= ref $protoB= $proto
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | 493 | return $field; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | 654 | ▶ | sub name { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
name: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | 654 | my $field = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | 654 | ▶ | if (@_) { $field->{'name'} = shift } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | 654 | return $field->{'name'}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | 350 | ▶ | sub canonName { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
canonName: called CC=2 SCAR=7.6
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | 350 | my $field = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | 0 | ▶ | if (@_) { $field->{'canonName'} = shift } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | 350 | return $field->{'canonName'}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | 609 | ▶ | sub value { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
value: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | 609 | my $field = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | 609 | ▶ | if (@_) { $field->{'value'} = shift } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | 609 | return $field->{'value'}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 146 | 199 | ▶ | sub deleted { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
deleted: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 147 | 199 | my $field = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 148 | 199 | ▶ | if (@_) { $field->{'deleted'} = shift } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 149 | 199 | return $field->{'deleted'}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 150 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 151 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 152 | 187 | ▶ | sub annotation { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
annotation: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 153 | 187 | my $field = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 154 | 187 | ▶ | if (@_) { $field->{'annotation'} = shift } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 155 | 187 | return $field->{'annotation'}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 156 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 157 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 158 | sub setFrom | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 159 | 2 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
setFrom: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 160 | 2 | my $field = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 161 | 2 | my $from = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 162 | 2 | $field->name($from->name); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 163 | 2 | $field->value($from->value); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 164 | 2 | $field->deleted($from->deleted); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 165 | 2 | $field->annotation($from->annotation); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 166 | 2 | return $field; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 167 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 168 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 169 | sub canonicalize | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 170 | 648 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
canonicalize: called CC=7 SCAR=25.7
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 171 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 172 | # Called as object method | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 173 | 648 | ▶ | if (@_ > 0 && ref $_[0]) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
@_ > 0 and ref $_[0]
MC/DC0%0/2
@_ > 0 and ref $_[0]
@_ > 0
ref $_[0]
Truth table33%1/3
A and B
A= @_ > 0B= ref $_[0]
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 174 | 0 | ▶ | return ${$_[0]}->canonName if (@_ == 1); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 175 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 176 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 177 | # Called as object or class method with argument | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 178 | 648 | ▶ | if (@_ == 2) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 179 | 155 | shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 180 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 181 | elsif (@_ != 1) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 182 | 0 | ▶ | confess "wrong number of args" if (@_ != 0); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 183 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 184 | 648 | my $name = $_[0]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 185 | 648 | $name =~ tr/A-Z/a-z/; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 186 | 648 | return $name; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 187 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 188 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 189 | sub write | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 190 | 181 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
write: called CC=4 SCAR=14.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 191 | 181 | my ($field, $fileHandle) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 192 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 193 | 181 | ▶ | print $fileHandle "; ", $field->annotation, $eol | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 194 | if defined $field->annotation; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 195 | 181 | print $fileHandle $field->name; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 196 | 181 | ▶ | if ($field->deleted) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 197 | 0 | print $fileHandle "-"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 198 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 199 | elsif (defined $field->value) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 200 | 136 | print $fileHandle "=", $field->value; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 201 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 202 | 181 | print $fileHandle $eol; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 203 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 204 | } # End package App::IniDiff::IniFile::Field; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 205 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 206 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 207 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 208 | 19 | package App::IniDiff::IniFile::Key; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 209 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 210 | 19 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 211 | 19 | ▶ | use Carp; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 212 | 19 | ▶ | use IO::File; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 213 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 214 | 19 | ▶ | use vars qw(&new &name &canonName &orderId &deleted &annotation &fields | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 215 | &canonicalize &findField &addField &appendField &removeField | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 216 | &write | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 217 | 19 | ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 218 | 19 | ▶ | use vars qw($eol); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 219 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 220 | # end of line character - eol | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 221 | 19 | $eol = "\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 222 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 223 | sub new | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 224 | 213 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=3 SCAR=11.6
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 225 | 213 | my $proto = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 226 | 213 | ▶ | confess "new App::IniDiff::IniFile::Key takes 3 arguments" if @_ != 3; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 227 | 213 | my ($name, $del, $annotation) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 228 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 229 | 213 | my $key = { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 230 | 'name' => $name, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 231 | 'canonName' => canonicalize($name), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 232 | 'orderId' => undef, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 233 | 'deleted' => $del, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 234 | 'annotation' => $annotation, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 235 | 'fields' => [], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 236 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 237 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 238 | 213 | ▶ | bless $key, (ref($proto) || $proto); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
ref $proto || $proto
MC/DC0%0/2
ref $proto || $proto
ref $proto
$proto
Truth table33%1/3
A || B
A= ref $protoB= $proto
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 239 | 213 | return $key; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 240 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 241 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 242 | 447 | ▶ | sub name { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
name: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 243 | 447 | my $key = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 244 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 245 | # Do not change canonName (see kludge in App::IniDiff::IniFile::new regarding patches) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 246 | 447 | ▶ | if (@_) { $key->{'name'} = shift } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 247 | 447 | return $key->{'name'}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 248 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 249 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 250 | 213 | ▶ | sub canonName { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
canonName: called CC=2 SCAR=7.6
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 251 | 213 | my $key = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 252 | 0 | ▶ | if (@_) { $key->{'canonName'} = shift } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 253 | 213 | return $key->{'canonName'}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 254 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 255 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 256 | 1076 | ▶ | sub orderId { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
orderId: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 257 | 1076 | my $key = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 258 | 1076 | ▶ | if (@_) { $key->{'orderId'} = shift } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 259 | 1076 | return $key->{'orderId'}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 260 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 261 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 262 | 633 | ▶ | sub deleted { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
deleted: called CC=2 SCAR=7.6
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 263 | 633 | my $key = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 264 | 0 | ▶ | if (@_) { $key->{'deleted'} = shift } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 265 | 633 | return $key->{'deleted'}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 266 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 267 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 268 | 83 | ▶ | sub annotation { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
annotation: called CC=2 SCAR=7.6
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 269 | 83 | my $key = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 270 | 0 | ▶ | if (@_) { $key->{'annotation'} = shift } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 271 | 83 | return $key->{'annotation'}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 272 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 273 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 274 | 907 | ▶ | sub fields { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
fields: called CC=2 SCAR=7.1
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 275 | 907 | my $key = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 276 | 907 | ▶ | confess "too many args" if @_ > 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 277 | 907 | return $key->{'fields'}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 278 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 279 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 280 | sub canonicalize | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 281 | 456 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
canonicalize: called CC=7 SCAR=25.7
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 282 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 283 | # Called as object method | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 284 | 456 | ▶ | if (@_ > 0 && ref $_[0]) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
@_ > 0 and ref $_[0]
MC/DC0%0/2
@_ > 0 and ref $_[0]
@_ > 0
ref $_[0]
Truth table33%1/3
A and B
A= @_ > 0B= ref $_[0]
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 285 | 0 | ▶ | return ${$_[0]}->canonName if (@_ == 1); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 286 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 287 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 288 | # Called as object or class method with argument | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 289 | 456 | ▶ | if (@_ == 2) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 290 | 243 | shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 291 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 292 | elsif (@_ != 1) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 293 | 0 | ▶ | confess "wrong number of args" if (@_ != 0); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 294 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 295 | 456 | my $name = $_[0]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 296 | 456 | $name =~ tr/A-Z/a-z/; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 297 | 456 | return $name; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 298 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 299 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 300 | # Note: only finds first field... | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 301 | sub findField | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 302 | 153 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
findField: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 303 | 153 | my ($key, $fieldName) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 304 | 153 | $fieldName = App::IniDiff::IniFile::Field->canonicalize($fieldName); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 305 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 306 | 153 | my ($field); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 307 | 153 | foreach $field (@{$key->fields}) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 308 | 342 | ▶ | return $field if ($field->canonName eq $fieldName); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 309 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 310 | 30 | return undef; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 311 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 312 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 313 | sub addField | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 314 | 32 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
addField: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 315 | 32 | my $key = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 316 | 32 | my $field = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 317 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 318 | 32 | my $xfield = $key->findField($field->name); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 319 | 32 | ▶ | if (defined $xfield) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 320 | 2 | $xfield->setFrom($field); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 321 | 2 | return $xfield; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 322 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 323 | 30 | return $key->appendField($field); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 324 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 325 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 326 | sub appendField | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 327 | 491 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
appendField: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 328 | 491 | my $key = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 329 | 491 | my $field = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 330 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 331 | 491 | push(@{$key->fields}, $field); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 332 | 491 | return $field; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 333 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 334 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 335 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 336 | # Remove a field, either by name or by reference | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 337 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 338 | sub removeField | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 339 | 6 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
removeField: called CC=6 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 340 | 6 | my $found = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 341 | 6 | my ($key, $arg) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 342 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 343 | 6 | ▶ | if (ref $arg) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 344 | 4 | my $fieldToast = $arg; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 345 | 4 | ▶ | for (my $i = 0 ; $i < @{$key->fields} ; $i++) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 346 | 14 | my $field = ${$key->fields}[$i]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 347 | 14 | ▶ | if ($field eq $fieldToast) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 348 | 4 | splice(@{$key->fields}, $i, 1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 349 | 4 | $i--; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 350 | 4 | $found++; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 351 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 352 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 353 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 354 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 355 | 2 | my $fieldName = App::IniDiff::IniFile::Field->canonicalize($arg); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 356 | 2 | ▶ | for (my $i = 0 ; $i < @{$key->fields} ; $i++) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 357 | 8 | my $field = ${$key->fields}[$i]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 358 | 8 | ▶ | if ($field->canonName eq $fieldName) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 359 | 2 | splice(@{$key->fields}, $i, 1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 360 | 2 | $i--; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 361 | 2 | $found++; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 362 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 363 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 364 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 365 | 6 | return $found; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 366 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 367 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 368 | sub write | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 369 | 81 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
write: called CC=5 SCAR=16.1
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 370 | 81 | my ($key, $fileHandle) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 371 | 81 | ▶ | my ($del) = $key->deleted ? '-' : ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 372 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 373 | 81 | ▶ | print $fileHandle "; ", $key->annotation, $eol | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 374 | if defined $key->annotation; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 375 | 81 | print $fileHandle "[", $key->name, "]", $del, $eol; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 376 | 81 | ▶ | if (!$key->deleted) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 377 | 77 | my $field; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 378 | 77 | foreach $field (@{$key->fields}) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 379 | 181 | $field->write($fileHandle); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 380 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 381 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 382 | 81 | print $fileHandle $eol; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 383 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 384 | } # End package App::IniDiff::IniFile::Key; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 385 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 386 | # $IniFile package Globals | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 387 | 19 | $errorString = undef; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 388 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 389 | # end of line character - eol | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 390 | 19 | $eol = "\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 391 | 19 | $commentchars = ';#'; # Allow DOS and Unix style comment. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 392 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 393 | sub new | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 394 | 36 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=33 SCAR=47.1
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 395 | 36 | my $proto = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 396 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 397 | 36 | my $ini = { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 398 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 399 | # Used to generate monotonically increasing key ids - used | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 400 | # to reserve order of ini file. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 401 | 'nextOrderId' => 0, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 402 | 'keys' => {}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 403 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 404 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 405 | 36 | ▶ | bless $ini, (ref($proto) || $proto); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
ref $proto || $proto
MC/DC0%0/2
ref $proto || $proto
ref $proto
$proto
Truth table33%1/3
A || B
A= ref $protoB= $proto
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 406 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 407 | 36 | ▶ | return $ini if (@_ == 0); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 408 | 36 | ▶ | confess "new called with too many arguments" if (@_ > 4); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 409 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 410 | 36 | my ($fileHandle, $isPatch, $addM, $stripComments) = | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 411 | @_; # Patches: allow duplicate key names | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 412 | 36 | my ($key); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 413 | 36 | my $ok = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 414 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 415 | 36 | ▶ | $isPatch = 0 if !defined $isPatch; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 416 | 36 | ▶ | $addM = 0 if !defined $addM; # add ^M if pre-NT | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 417 | 36 | ▶ | $stripComments = 0 if ! defined $stripComments; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 418 | # strip out trailing inline comments having semicolon | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 419 | # comment out stripComments if isPatch | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 420 | # - this may be a problem | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 421 | # - leave them in unless specifically asked | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 422 | # $stripComments = 1 if $isPatch; # always strip out comments from patches | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 423 | 36 | ▶ | if ($addM == 1) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 424 | 0 | $eol = "\r\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 425 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 426 | # set the children's eol members to this value as well ... | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 427 | # not using set() methods - oh dear | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 428 | 0 | $App::IniDiff::IniFile::Key::eol = "\r\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 429 | 0 | $App::IniDiff::IniFile::Field::eol = "\r\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 430 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 431 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 432 | 36 | ▶ | while (<$fileHandle>) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 433 | 881 | chomp; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 434 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 435 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 436 | # Strip comments - not in key names ([...]) and not in strings.. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 437 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 438 | # if a [key] section | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 439 | 881 | ▶ | if (/^\s*(\[[^]]+])(.*)$/) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 440 | 223 | my ($key, $rest) = ($1, $2); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 441 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 442 | # do care if it strips comments after [key] section | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 443 | 223 | ▶ | if ($stripComments) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 444 | 0 | $rest =~ s/[$commentchars].*//; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 445 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 446 | 223 | $_ = $key . $rest; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 447 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 448 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 449 | # not a comment starting with ; and has a " in it | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 450 | ▶ | elsif (!/^\s*[$commentchars]/ && /"/) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
not /^\s*[$App::IniDiff::IniFile::commentchars]/ and /"/
MC/DC0%0/2
not /^\s*[$App::IniDiff::IniFile::commentchars]/ and /"/
not /^\s*[$App::IniDiff::IniFile::commentchars]/
/"/
Truth table66%2/3
not(A) and B
A= not /^\s*[$App::IniDiff::IniFile::commentchars]/B= /"/
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 451 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 452 | # Slow, but perl won't go exponential... | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 453 | 0 | my $line = ''; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 454 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 455 | # walk through non comments and matched quoted strings | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 456 | # from left to right | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 457 | # until we hit a comment character or a non matched quote | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 458 | 0 | ▶ | while (/^([^"$commentchars]*"[^"]*")(.*)/) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 459 | 0 | $line .= $1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 460 | 0 | $_ = $2; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 461 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 462 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 463 | # Some (burnt) ini files have unmatched quotes... rather | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 464 | # than toast these, we assume they have no comments. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 465 | 0 | ▶ | if (!/"/) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 466 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 467 | # do not strip comments unless requested | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 468 | 0 | ▶ | if ($stripComments) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 469 | 0 | s/[$commentchars].*//; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 470 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 471 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 472 | 0 | $_ = $line . $_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 473 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 474 | elsif ($stripComments) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 475 | 0 | s/[$commentchars].*//; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 476 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 477 | 881 | s/\s*$//; # remove trailing space includes \r... | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 478 | # not skipping blank lines at this point results in errors when diffing | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 479 | 881 | ▶ | next if /^$/; # skip blank lines | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 480 | 661 | ▶ | if (/^\s*\[([^]]+)](-?)$/) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 481 | 200 | my ($name, $del) = ($1, $2); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 482 | 200 | ▶ | if ($isPatch) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 483 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 484 | # Patches are a bit strange as there can be duplicate | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 485 | # key names - to deal with this, the canonName (hash index) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 486 | # is a generated (unique) thing and we fix up the real name | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 487 | # after the key is created. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 488 | 24 | $key = $ini->addKey( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 489 | new App::IniDiff::IniFile::Key( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 490 | "[$ini->{'nextOrderId'}]", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 491 | $del eq '-', undef)); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 492 | 24 | $key->name($name); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 493 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 494 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 495 | 176 | ▶ | if ($del eq '-') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 496 | 0 | $errorString = "$.: non-patch file has deleted key"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 497 | 0 | $ok = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 498 | 0 | last; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 499 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 500 | 176 | ▶ | if ($ini->findKey($name)) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 501 | 1 | $errorString = "$.: duplicate key: $name"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 502 | 1 | $ok = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 503 | 1 | last; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 504 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 505 | $key = | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 506 | 175 | $ini->addKey(new App::IniDiff::IniFile::Key($name, $del eq '-', undef)); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 507 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 508 | 199 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 509 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 510 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 511 | # passed through, this is not a key, so it is something else | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 512 | 461 | my ($name, $value); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 513 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 514 | # fix quotes | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 515 | 461 | ▶ | if (/"/) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 516 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 517 | # Slow, but perl won't go exponential... | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 518 | 0 | my $line = ''; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 519 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 520 | # cycle through matched pairs of quotes in LHS $name | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 521 | # accepts = between pair of quotes in LHS | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 522 | 0 | ▶ | while (/^([^"=]*"[^"]*")(.*)$/) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 523 | 0 | $line .= $1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 524 | 0 | $_ = $2; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 525 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 526 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 527 | # no remaining quotes in LHS | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 528 | # allows unmatched quote in RHS | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 529 | 0 | ▶ | if (/^([^"]*)=(.*)$/) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 530 | 0 | $name = $line . $1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 531 | 0 | $value = $2; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 532 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 533 | elsif (/"/) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 534 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 535 | # Wonder if this will be a problem... | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 536 | 0 | $errorString = "$.: unmatched quote (no preceeding =)"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 537 | 0 | $ok = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 538 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 539 | # quits here ... maybe we shouldn't quit parsing | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 540 | 0 | last; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 541 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 542 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 543 | 0 | $name = $line . $_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 544 | 0 | $value = undef; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 545 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 546 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 547 | elsif (/^([^=]+)=(.*)$/) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 548 | 344 | $name = $1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 549 | 344 | $value = $2; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 550 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 551 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 552 | 117 | $name = $_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 553 | 117 | $value = undef; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 554 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 555 | 461 | my $del = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 556 | 461 | ▶ | if (!defined $value && $name =~ /-$/) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
not defined $value and $name =~ /-$/
MC/DC100%2/2
not defined $value and $name =~ /-$/
not defined $value
$name =~ /-$/
Truth table100%3/3
not(A) and B
A= not defined $valueB= $name =~ /-$/
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 557 | 2 | ▶ | if (!$isPatch) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 558 | 0 | $errorString = "$.: non-patch file has deleted field"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 559 | 0 | $ok = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 560 | 0 | last; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 561 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 562 | 2 | $del = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 563 | 2 | chop $name; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 564 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 565 | 461 | ▶ | if (!defined $key) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 566 | 0 | $errorString = "$.: field outside of key\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 567 | 0 | $ok = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 568 | 0 | last; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 569 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 570 | 461 | ▶ | if ($key->deleted) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 571 | 0 | $errorString = "$.: deleted key has field\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 572 | 0 | $ok = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 573 | 0 | last; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 574 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 575 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 576 | # when a comment precedes a new key (section), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 577 | # it gets stuck with the previous one | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 578 | # because the blank line at the end of a key section | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 579 | # must get eaten for inidiff to work | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 580 | 461 | $key->appendField(new App::IniDiff::IniFile::Field($name, $value, $del, undef)); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 581 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 582 | 36 | ▶ | return undef if !$ok; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 583 | 35 | return $ini; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 584 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 585 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 586 | sub write | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 587 | 16 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
write: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 588 | 16 | my ($ini, $fileHandle) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 589 | 16 | my ($key); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 590 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 591 | 16 | foreach $key (@{$ini->keys}) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 592 | 81 | $key->write($fileHandle); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 593 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 594 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 595 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 596 | sub findKey | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 597 | 241 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
findKey: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 598 | 241 | my ($ini, $keyName) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 599 | 241 | return $ini->{'keys'}->{App::IniDiff::IniFile::Key->canonicalize($keyName)}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 600 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 601 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 602 | sub keys | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 603 | 37 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
keys: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 604 | 37 | my ($ini) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 605 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 606 | return [ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 607 | 399 | sort { $a->orderId <=> $b->orderId } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 608 | 37 | values(%{$ini->{'keys'}}) ]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 609 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 610 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 611 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 612 | # Remove a key, either by name or by reference | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 613 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 614 | sub removeKey | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 615 | 4 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
removeKey: called CC=4 SCAR=13.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 616 | 4 | my ($ini, $arg) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 617 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 618 | 4 | ▶ | if (ref $arg) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 619 | 2 | my $keyToast = $arg; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 620 | 2 | my ($name, $key); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 621 | 2 | ▶ | while (($name, $key) = each %{$ini->{'keys'}}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 622 | 14 | ▶ | if ($key eq $keyToast) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 623 | 2 | delete $ini->{'keys'}->{$name}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 624 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 625 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 626 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 627 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 628 | 2 | my $keyName = $arg; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 629 | 2 | return delete $ini->{'keys'}->{App::IniDiff::IniFile::Key->canonicalize($keyName)}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 630 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 631 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 632 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 633 | sub addKey | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 634 | 213 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
addKey: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 635 | 213 | my ($ini, $key) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 636 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 637 | 213 | $ini->{'keys'}->{$key->canonName} = $key; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 638 | 213 | $key->orderId($ini->{'nextOrderId'}++); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 639 | 213 | return $key; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 640 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 641 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 642 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 643 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 644 | package App::IniDiff::IniFile::Filter; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 645 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 646 | 19 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 647 | 19 | ▶ | use Carp; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 648 | 19 | ▶ | use IO::File; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 649 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 650 | 19 | ▶ | use vars qw(&new &readConf &filter &export); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 651 | 19 | ▶ | use vars qw($errorString); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 652 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 653 | sub new | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 654 | 2 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=3 SCAR=11.8
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 655 | 2 | my $proto = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 656 | 2 | ▶ | confess "new App::IniDiff::IniFile::Filter takes no arguments" if @_ != 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 657 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 658 | 2 | my $field = { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 659 | 'keyFilters' => [] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 660 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 661 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 662 | 2 | ▶ | bless $field, (ref($proto) || $proto); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
ref $proto || $proto
MC/DC0%0/2
ref $proto || $proto
ref $proto
$proto
Truth table33%1/3
A || B
A= ref $protoB= $proto
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 663 | 2 | return $field; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 664 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 665 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 666 | sub readConf | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 667 | 4 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
readConf: called CC=32 SCAR=45.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 668 | 4 | my ($filter, $file) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 669 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 670 | 4 | my $in = new IO::File $file, "r"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 671 | 4 | ▶ | if (!defined $in) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 672 | 0 | $errorString = "can't open $file - $!"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 673 | 0 | return 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 674 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 675 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 676 | 4 | my ($keyActions) = undef; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 677 | 4 | my ($entryActions) = undef; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 678 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 679 | 4 | ▶ | while (<$in>) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 680 | 106 | ▶ | next if (/^\s*(#|$)/); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 681 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 682 | # Trim whitespace | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 683 | 52 | s/^\s+//; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 684 | 52 | s/\s+$//; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 685 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 686 | # include another filter file? | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 687 | 52 | ▶ | if (/^\s*include\s+"([^"]*)"\s*$/) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 688 | 2 | my ($ifile) = $1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 689 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 690 | # End the previous key (with error checking) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 691 | # added {} around keyActions | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 692 | 2 | ▶ | if (defined $keyActions && !@{$keyActions}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition33%1/3
defined $keyActions and not @{$keyActions;}
MC/DC0%0/2
defined $keyActions and not @{$keyActions;}
defined $keyActions
not @{$keyActions;}
Truth table33%1/3
A and not(B)
A= defined $keyActionsB= not @{$keyActions;}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 693 | 0 | $errorString = "$file:$.: previous key has no actions"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 694 | 0 | $in->close; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 695 | 0 | return 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 696 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 697 | # added {} around entryActions | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 698 | 2 | ▶ | elsif (defined $entryActions && !@{$entryActions}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
defined $entryActions and not @{$entryActions;}
MC/DC0%0/2
defined $entryActions and not @{$entryActions;}
defined $entryActions
not @{$entryActions;}
Truth table33%1/3
A and not(B)
A= defined $entryActionsB= not @{$entryActions;}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 699 | 0 | $errorString = | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 700 | "$file:$.: previous name/value pattern has no actions"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 701 | 0 | $in->close; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 702 | 0 | return 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 703 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 704 | 2 | $keyActions = $entryActions = undef; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 705 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 706 | # If not an absolute path, try relative to this file first. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 707 | 2 | my ($mypath) = $file; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 708 | 2 | $mypath =~ s:/+[^/]*$::; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 709 | 2 | ▶ | if ($ifile !~ /^\// | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%3/9
not $ifile =~ m[^/] and $mypath ne "" and $mypath ne $file and -e $mypath . '/' . $ifile
not $ifile =~ m[^/] and $mypath ne "" and $mypath ne $file
not $ifile =~ m[^/] and $mypath ne ""
MC/DC0%0/4
not $ifile =~ m[^/] and $mypath ne "" and $mypath ne $file and -e $mypath . '/' . $ifile
not $ifile =~ m[^/]
$mypath ne ""
$mypath ne $file
-e $mypath . '/' . $ifile
Truth table20%1/5
not(A) and B and C and D
A= not $ifile =~ m[^/]B= $mypath ne ""C= $mypath ne $fileD= -e $mypath . '/' . $ifile
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 710 | && $mypath ne '' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 711 | && $mypath ne $file | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 712 | && -e $mypath."/".$ifile) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 713 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 714 | 2 | ▶ | return 0 if (!$filter->readConf($mypath."/".$ifile)); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 715 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 716 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 717 | 0 | ▶ | return 0 if (!$filter->readConf($ifile)); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 718 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 719 | 2 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 720 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 721 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 722 | # A new key? | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 723 | 50 | ▶ | if (/^\[(.+)](|\s*-)$/) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 724 | 14 | ▶ | my ($keyPat, $isDel) = ($1, $2 eq '' ? 0 : 1); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 725 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 726 | 14 | ▶ | if (defined $keyActions && !@{$keyActions}) { # added {} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition66%2/3
defined $keyActions and not @{$keyActions;}
MC/DC0%0/2
defined $keyActions and not @{$keyActions;}
defined $keyActions
not @{$keyActions;}
Truth table66%2/3
A and not(B)
A= defined $keyActionsB= not @{$keyActions;}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 727 | 0 | $errorString = "$file:$.: previous key has no actions"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 728 | 0 | $in->close; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 729 | 0 | return 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 730 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 731 | 10 | ▶ | elsif (defined $entryActions && !@{$entryActions}) { # added {} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
defined $entryActions and not @{$entryActions;}
MC/DC0%0/2
defined $entryActions and not @{$entryActions;}
defined $entryActions
not @{$entryActions;}
Truth table66%2/3
A and not(B)
A= defined $entryActionsB= not @{$entryActions;}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 732 | 0 | $errorString = | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 733 | "$file:$.: previous name/value pattern has no actions"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 734 | 0 | $in->close; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 735 | 0 | return 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 736 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 737 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 738 | push( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 739 | 14 | @{$filter->{'keyFilters'}}, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 740 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 741 | 'keyPat' => $1, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 742 | 'deleteAll' => $isDel, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 743 | 'keyActions' => [] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 744 | }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 745 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 746 | # ${$filter} is not an array | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 747 | # $keyActions = $isDel ? undef : | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 748 | # ${$filter}[$#$filter]->{'keyActions'}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 749 | 14 | my @filterHashes = @{$filter->{'keyFilters'}}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 750 | 14 | my $numHashes = $#filterHashes; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 751 | $keyActions = | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 752 | 14 | ▶ | $isDel ? undef : $filterHashes[$numHashes]->{'keyActions'}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 753 | 14 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 754 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 755 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 756 | # A new entry match operator? | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 757 | 36 | ▶ | if (/^\s*(name|value)\s+(\S.*)$/) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 758 | 16 | my ($matchOn, $matchPat) = ($1, $2); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 759 | 16 | ▶ | if (!defined $keyActions) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 760 | 0 | $errorString = | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 761 | "$file:$.: name/value pattern found outside key"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 762 | 0 | $in->close; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 763 | 0 | return 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 764 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 765 | 16 | ▶ | if (defined $entryActions && !@{$entryActions}) { # added {} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $entryActions and not @{$entryActions;}
MC/DC0%0/2
defined $entryActions and not @{$entryActions;}
defined $entryActions
not @{$entryActions;}
Truth table66%2/3
A and not(B)
A= defined $entryActionsB= not @{$entryActions;}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 766 | 0 | $errorString = | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 767 | "$file:$.: previous name/value pattern has no actions"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 768 | 0 | $in->close; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 769 | 0 | return 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 770 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 771 | 16 | $entryActions = []; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 772 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 773 | # added {} to keyActions | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 774 | push( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 775 | 16 | @{$keyActions}, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 776 | { 'matchOn' => $matchOn, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 777 | 'matchPat' => $matchPat, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 778 | 'entryActions' => $entryActions, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 779 | }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 780 | 16 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 781 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 782 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 783 | # A entry substitution | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 784 | 20 | ▶ | if (/^\s*subst\s+(name|value)\s+(\S.*)$/) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 785 | 16 | my ($action, $subst) = ($1, $2); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 786 | 16 | ▶ | if (!defined $keyActions) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 787 | 0 | $errorString = "$file:$.: substitution found outside key"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 788 | 0 | $in->close; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 789 | 0 | return 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 790 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 791 | 16 | ▶ | if (!defined $entryActions) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 792 | 0 | $errorString = | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 793 | "$file:$.: substitution found outside entry/key pattern"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 794 | 0 | $in->close; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 795 | 0 | return 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 796 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 797 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 798 | # added {} to entryActions | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 799 | push( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 800 | 16 | @{$entryActions}, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 801 | { 'action' => "subst\u$action", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 802 | 'subst' => $subst, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 803 | }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 804 | 16 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 805 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 806 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 807 | # An entry deletion | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 808 | 4 | ▶ | if (/^\s*delete$/) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 809 | 4 | ▶ | if (!defined $keyActions) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 810 | 0 | $errorString = "$file:$.: delete entry found outside key"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 811 | 0 | $in->close; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 812 | 0 | return 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 813 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 814 | 4 | ▶ | if (!defined $entryActions) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 815 | 0 | $errorString = | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 816 | "$file:$.: delete entry found outside entry/key pattern"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 817 | 0 | $in->close; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 818 | 0 | return 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 819 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 820 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 821 | # added {} to entryActions | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 822 | push( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 823 | 4 | @{$entryActions}, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 824 | { 'action' => 'delete', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 825 | 'subst' => undef, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 826 | }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 827 | 4 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 828 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 829 | 0 | $errorString = "$file:$.: unexpected line"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 830 | 0 | $in->close; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 831 | 0 | return 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 832 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 833 | 4 | $in->close; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 834 | 4 | return 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 835 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 836 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 837 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 838 | # Given a ini object, modify it by applying the filtering commands | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 839 | # (deletions and substitutions) contained in the filter object. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 840 | # Returns true iff there are no problems. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 841 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 842 | sub filter | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 843 | 2 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
filter: called CC=15 SCAR=27.6
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 844 | 2 | my ($filter, $ini) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 845 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 846 | 2 | my $key; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 847 | 2 | foreach $key (@{$ini->keys}) { # was unblessed references | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 848 | 14 | my $keyFilt; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 849 | 14 | foreach $keyFilt (@{$filter->{'keyFilters'}}) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 850 | 98 | ▶ | next if ($key->name !~ /^$keyFilt->{'keyPat'}$/i); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 851 | 12 | ▶ | if ($keyFilt->{'deleteAll'}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 852 | 2 | $ini->removeKey($key); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 853 | 2 | next; # no point in going on... | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 854 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 855 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 856 | # remove end block here $keyFilt was not defined | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 857 | # Must be entry substituions/deletions | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 858 | 10 | my $keyAction; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 859 | 10 | foreach $keyAction (@{$keyFilt->{'keyActions'}}) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 860 | 12 | my $field; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 861 | 12 | foreach $field (@{$key->fields}) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 862 | my $target = | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 863 | 26 | ▶ | $keyAction->{'matchOn'} eq 'name' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 864 | ? $field->name | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 865 | : $field->value; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 866 | 26 | ▶ | next if ($target !~ /^$keyAction->{'matchPat'}$/i); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 867 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 868 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 869 | # Have a match - carry out entry actions | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 870 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 871 | 12 | my $entryAction; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 872 | 12 | foreach $entryAction (@{$keyAction->{'entryActions'}}) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 873 | 16 | ▶ | if ($entryAction->{'action'} eq 'substName') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 874 | 6 | my $name = $field->name; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 875 | 6 | eval "\$name =~ $entryAction->{'subst'}"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 876 | 6 | ▶ | if ($@ ne '') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 877 | 0 | $errorString = "error substituting " . | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 878 | "$target using $keyAction->{'subst'}"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 879 | 0 | return undef; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 880 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 881 | 6 | $field->name($name); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 882 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 883 | elsif ($entryAction->{'action'} eq 'substValue') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 884 | 6 | my $value = $field->value; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 885 | 6 | eval "\$value =~ $entryAction->{'subst'}"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 886 | 6 | ▶ | if ($@ ne '') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 887 | 0 | $errorString = "error substituting " . | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 888 | "$target using $keyAction->{'subst'}"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 889 | 0 | return undef; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 890 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 891 | 6 | $field->value($value); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 892 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 893 | elsif ($entryAction->{'action'} eq 'delete') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 894 | 4 | $key->removeField($field); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 895 | 4 | last; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 896 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 897 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 898 | 0 | $errorString = "inifilter::filter: internal " . | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 899 | "error - unknown entry action: " . | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 900 | "$entryAction->{'action'}"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 901 | 0 | return undef; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 902 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 903 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 904 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 905 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 906 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 907 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 908 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 909 | 2 | return 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 910 | } # End Sub Filter | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 911 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 912 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 913 | # Export all filtering commands to the command line (mainly for DEBUG) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 914 | # (deletions and substitutions) contained in the filter object. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 915 | # Returns true iff there are no problems. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 916 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 917 | sub export | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 918 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
export: not called CC=8 SCAR=42.8
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 919 | 0 | my ($filter) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 920 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 921 | 0 | my $keyFilt; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 922 | 0 | foreach $keyFilt (@{$filter->{'keyFilters'}}) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 923 | 0 | print "keyPat = " . $keyFilt->{'keyPat'} . "\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 924 | 0 | ▶ | if ($keyFilt->{'deleteAll'}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 925 | 0 | print "deleteAll = " . $keyFilt->{'deleteAll'} . "\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 926 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 927 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 928 | # remove end block here $keyFilt was not defined | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 929 | # Must be entry substituions/deletions | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 930 | 0 | my $keyAction; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 931 | 0 | foreach $keyAction (@{$keyFilt->{'keyActions'}}) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 932 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 933 | 0 | print "matchOn = " . $keyAction->{'matchOn'} . "\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 934 | 0 | print "matchPat = " . $keyAction->{'matchPat'} . "\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 935 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 936 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 937 | # Have a match - carry out entry actions | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 938 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 939 | 0 | my $entryAction; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 940 | 0 | foreach $entryAction (@{$keyAction->{'entryActions'}}) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 941 | 0 | print "entryAction = " . $entryAction->{'action'} . "\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 942 | 0 | ▶ | if ($entryAction->{'action'} eq 'substName') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 943 | 0 | print "subst name = " . $entryAction->{'subst'} . "\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 944 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 945 | elsif ($entryAction->{'action'} eq 'substValue') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 946 | 0 | print "subst value = " . $entryAction->{'subst'} . "\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 947 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 948 | elsif ($entryAction->{'action'} eq 'delete') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 949 | 0 | print "delete = " . $entryAction->{'subst'} . "\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 950 | 0 | last; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 951 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 952 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 953 | 0 | $errorString = "inifilter::export: internal error " . | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 954 | "- unknown entry action: $entryAction->{'action'}"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 955 | 0 | return undef; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 956 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 957 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 958 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 959 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 960 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 961 | 0 | return 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 962 | } # End Sub Export | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 963 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 964 | } # End package App::IniDiff::IniFile::Filter | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 965 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 966 | =pod | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 967 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 968 | =head1 AUTHOR | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 969 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 970 | Michael Rendell, Memorial University of Newfoundland | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 971 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 972 | =head1 MAINTAINERS | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 973 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 974 | Jeremy Squires <j.squires at computer.org> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 975 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 976 | =head1 SOURCE | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 977 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 978 | =over 4 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 979 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 980 | =item * The source for this package is available here: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 981 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 982 | L<https://github.com/jeremysquires/App-IniDiff> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 983 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 984 | =back | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 985 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 986 | =head1 ACKNOWLEDGEMENTS | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 987 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 988 | Michael Rendell, Memorial University of Newfoundland | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 989 | produced the first version of the Regutils package from which | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 990 | this package was derived. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 991 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 992 | =over 4 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 993 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 994 | =item * It is still available from: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 995 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 996 | L<https://sourceforge.net/projects/regutils/> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 997 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 998 | =back | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 999 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1000 | =head1 BUGS | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1001 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1002 | Please report any bugs or feature requests to | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1003 | C<bug-app-inidiff-inifile at rt.cpan.org>, or through | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1004 | the web interface at L<https://rt.cpan.org/NoAuth/ReportBug.html?Queue=App-IniDiff-IniFile>. I will be notified, and then you'll | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1005 | automatically be notified of progress on your bug as I make changes. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1006 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1007 | =head1 SUPPORT | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1008 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1009 | You can find documentation for this module with the perldoc command. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1010 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1011 | perldoc App::IniDiff::IniFile | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1012 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1013 | You can also look for information at: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1014 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1015 | =over 4 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1016 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1017 | =item * RT: CPAN's request tracker (report bugs here) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1018 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1019 | L<https://rt.cpan.org/NoAuth/Bugs.html?Dist=App-IniDiff-IniFile> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1020 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1021 | =item * AnnoCPAN: Annotated CPAN documentation | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1022 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1023 | L<http://annocpan.org/dist/App-IniDiff-IniFile> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1024 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1025 | =item * CPAN Ratings | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1026 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1027 | L<https://cpanratings.perl.org/d/App-IniDiff-IniFile> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1028 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1029 | =item * Search CPAN | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1030 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1031 | L<https://metacpan.org/release/App-IniDiff-IniFile> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1032 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1033 | =back | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1034 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1035 | =head1 LICENSE AND COPYRIGHT | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1036 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1037 | This software is Copyright (c) 1998 Memorial University of Newfoundland | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1038 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1039 | This is free software, licensed under: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1040 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1041 | The GNU General Public License, Version 3, July 2007 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1042 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1043 | See F<LICENSE> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1044 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1045 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1046 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1047 | 19 | 1; # End of App::IniDiff::IniFile | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1048 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1049 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||