| 1 | package Text::FixEOL; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 2 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 2 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||
| 6 | 2 | $Text::FixEOL::VERSION = '1.08'; | |||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | ########################################################################################## | ||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | 2 | my %_Platform_Defaults = ( | |||||||||||||||||||||||||||
| 11 | lf => { | ||||||||||||||||||||||||||||
| 12 | 'fixlast' => 'no', | ||||||||||||||||||||||||||||
| 13 | 'eof' => 'asis', | ||||||||||||||||||||||||||||
| 14 | 'eol' => "\012", | ||||||||||||||||||||||||||||
| 15 | }, | ||||||||||||||||||||||||||||
| 16 | cr => { | ||||||||||||||||||||||||||||
| 17 | 'fixlast' => 'no', | ||||||||||||||||||||||||||||
| 18 | 'eof' => 'asis', | ||||||||||||||||||||||||||||
| 19 | 'eol' => "\015", | ||||||||||||||||||||||||||||
| 20 | }, | ||||||||||||||||||||||||||||
| 21 | crlf => { | ||||||||||||||||||||||||||||
| 22 | 'fixlast' => 'no', | ||||||||||||||||||||||||||||
| 23 | 'eof' => 'asis', | ||||||||||||||||||||||||||||
| 24 | 'eol' => "\015\012", | ||||||||||||||||||||||||||||
| 25 | }, | ||||||||||||||||||||||||||||
| 26 | asis => { | ||||||||||||||||||||||||||||
| 27 | 'fixlast' => 'no', | ||||||||||||||||||||||||||||
| 28 | 'eof' => 'asis', | ||||||||||||||||||||||||||||
| 29 | 'eol' => "asis", | ||||||||||||||||||||||||||||
| 30 | }, | ||||||||||||||||||||||||||||
| 31 | network => { | ||||||||||||||||||||||||||||
| 32 | 'fixlast' => 'yes', | ||||||||||||||||||||||||||||
| 33 | 'eof' => 'remove', | ||||||||||||||||||||||||||||
| 34 | 'eol' => "\015\012", | ||||||||||||||||||||||||||||
| 35 | }, | ||||||||||||||||||||||||||||
| 36 | mac => { | ||||||||||||||||||||||||||||
| 37 | 'fixlast' => 'yes', | ||||||||||||||||||||||||||||
| 38 | 'eof' => 'remove', | ||||||||||||||||||||||||||||
| 39 | 'eol' => "\015", | ||||||||||||||||||||||||||||
| 40 | }, | ||||||||||||||||||||||||||||
| 41 | macos => { | ||||||||||||||||||||||||||||
| 42 | 'fixlast' => 'yes', | ||||||||||||||||||||||||||||
| 43 | 'eof' => 'remove', | ||||||||||||||||||||||||||||
| 44 | 'eol' => "\015", | ||||||||||||||||||||||||||||
| 45 | }, | ||||||||||||||||||||||||||||
| 46 | windows => { | ||||||||||||||||||||||||||||
| 47 | 'fixlast' => 'yes', | ||||||||||||||||||||||||||||
| 48 | 'eof' => 'asis', | ||||||||||||||||||||||||||||
| 49 | 'eol' => "\015\012", | ||||||||||||||||||||||||||||
| 50 | }, | ||||||||||||||||||||||||||||
| 51 | mswin32 => { | ||||||||||||||||||||||||||||
| 52 | 'fixlast' => 'yes', | ||||||||||||||||||||||||||||
| 53 | 'eof' => 'asis', | ||||||||||||||||||||||||||||
| 54 | 'eol' => "\015\012", | ||||||||||||||||||||||||||||
| 55 | }, | ||||||||||||||||||||||||||||
| 56 | os2 => { | ||||||||||||||||||||||||||||
| 57 | 'fixlast' => 'yes', | ||||||||||||||||||||||||||||
| 58 | 'eof' => 'asis', | ||||||||||||||||||||||||||||
| 59 | 'eol' => "\015\012", | ||||||||||||||||||||||||||||
| 60 | }, | ||||||||||||||||||||||||||||
| 61 | vms => { | ||||||||||||||||||||||||||||
| 62 | 'fixlast' => 'yes', | ||||||||||||||||||||||||||||
| 63 | 'eof' => 'remove', | ||||||||||||||||||||||||||||
| 64 | 'eol' => "\015\012", | ||||||||||||||||||||||||||||
| 65 | }, | ||||||||||||||||||||||||||||
| 66 | netware => { | ||||||||||||||||||||||||||||
| 67 | 'fixlast' => 'yes', | ||||||||||||||||||||||||||||
| 68 | 'eof' => 'asis', | ||||||||||||||||||||||||||||
| 69 | 'eol' => "\015\012", | ||||||||||||||||||||||||||||
| 70 | }, | ||||||||||||||||||||||||||||
| 71 | dos => { | ||||||||||||||||||||||||||||
| 72 | 'fixlast' => 'yes', | ||||||||||||||||||||||||||||
| 73 | 'eof' => 'asis', | ||||||||||||||||||||||||||||
| 74 | 'eol' => "\015\012", | ||||||||||||||||||||||||||||
| 75 | }, | ||||||||||||||||||||||||||||
| 76 | cygwin => { | ||||||||||||||||||||||||||||
| 77 | 'fixlast' => 'yes', | ||||||||||||||||||||||||||||
| 78 | 'eof' => 'asis', | ||||||||||||||||||||||||||||
| 79 | 'eol' => "\015\012", | ||||||||||||||||||||||||||||
| 80 | }, | ||||||||||||||||||||||||||||
| 81 | unix => { | ||||||||||||||||||||||||||||
| 82 | 'fixlast' => 'yes', | ||||||||||||||||||||||||||||
| 83 | 'eof' => 'remove', | ||||||||||||||||||||||||||||
| 84 | 'eol' => "\012", | ||||||||||||||||||||||||||||
| 85 | }, | ||||||||||||||||||||||||||||
| 86 | 'unknown' => { | ||||||||||||||||||||||||||||
| 87 | 'fixlast' => 'yes', | ||||||||||||||||||||||||||||
| 88 | 'eof' => 'remove', | ||||||||||||||||||||||||||||
| 89 | 'eol' => "\n", | ||||||||||||||||||||||||||||
| 90 | }, | ||||||||||||||||||||||||||||
| 91 | ); | ||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||
| 93 | ########################################################################################## | ||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||
| 95 | 322 | ▶ | sub new { | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=10 SCAR=23.0
Pod
documented
| |||||||||||||||||||||||||||||
| 96 | 322 | my $proto = shift; | |||||||||||||||||||||||||||
| 97 | 322 | my $proto_ref = ref($proto); | |||||||||||||||||||||||||||
| 98 | 322 | my $package = __PACKAGE__; | |||||||||||||||||||||||||||
| 99 | 322 | my $class; | |||||||||||||||||||||||||||
| 100 | 322 | ▶ | if ($proto_ref) { $class = $proto_ref; } | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 101 | 25 | elsif ($proto) { $class = $proto; } | |||||||||||||||||||||||||||
| 102 | 1 | else { $class = $package; } | |||||||||||||||||||||||||||
| 103 | 322 | my $self = bless {},$class; | |||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||
| 105 | 322 | $self->eol_handling('platform'); | |||||||||||||||||||||||||||
| 106 | 322 | $self->eof_handling('platform'); | |||||||||||||||||||||||||||
| 107 | 322 | $self->fix_last_handling('platform'); | |||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||
| 109 | 322 | my %raw_properties = (); | |||||||||||||||||||||||||||
| 110 | 322 | ▶ | if (1 < @_) { %raw_properties = @_; } | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 111 | elsif (1 == @_) { | ||||||||||||||||||||||||||||
| 112 | 301 | my $parm = shift; | |||||||||||||||||||||||||||
| 113 | 301 | my $parm_type = ref($parm); | |||||||||||||||||||||||||||
| 114 | 301 | ▶ | if ($parm_type eq 'HASH') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 115 | 300 | %raw_properties = %$parm; | |||||||||||||||||||||||||||
| 116 | } else { | ||||||||||||||||||||||||||||
| 117 | 1 | require Carp; | |||||||||||||||||||||||||||
| 118 | 1 | Carp::croak("${package}::new() - Unexpected parameter type passed to constructor: $parm_type"); | |||||||||||||||||||||||||||
| 119 | } | ||||||||||||||||||||||||||||
| 120 | } else { | ||||||||||||||||||||||||||||
| 121 | 17 | return $self; | |||||||||||||||||||||||||||
| 122 | } | ||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||
| 124 | 304 | my %properties = map { lc($_) => $raw_properties{$_} } keys %raw_properties; | |||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||
| 126 | 304 | ▶ | if ($properties{'eol'}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 127 | 302 | $self->eol_handling($properties{'eol'}); | |||||||||||||||||||||||||||
| 128 | 302 | delete $properties{'eol'}; | |||||||||||||||||||||||||||
| 129 | } | ||||||||||||||||||||||||||||
| 130 | 304 | ▶ | if ($properties{'eof'}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 131 | 298 | $self->eof_handling($properties{'eof'}); | |||||||||||||||||||||||||||
| 132 | 298 | delete $properties{'eof'}; | |||||||||||||||||||||||||||
| 133 | } | ||||||||||||||||||||||||||||
| 134 | 304 | ▶ | if ($properties{'fixlast'}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 135 | 298 | $self->fix_last_handling($properties{'fixlast'}); | |||||||||||||||||||||||||||
| 136 | 298 | delete $properties{'fixlast'}; | |||||||||||||||||||||||||||
| 137 | } | ||||||||||||||||||||||||||||
| 138 | 304 | my @extra_properties = keys %properties; | |||||||||||||||||||||||||||
| 139 | 304 | ▶ | if (0 < @extra_properties) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 140 | 2 | require Carp; | |||||||||||||||||||||||||||
| 141 | 2 | Carp::croak("${package}::new() - Unexpected attributes passed: " . join(', ',sort @extra_properties) . "\n"); | |||||||||||||||||||||||||||
| 142 | } | ||||||||||||||||||||||||||||
| 143 | |||||||||||||||||||||||||||||
| 144 | 302 | return $self; | |||||||||||||||||||||||||||
| 145 | } | ||||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||
| 147 | ########################################################################################## | ||||||||||||||||||||||||||||
| 148 | |||||||||||||||||||||||||||||
| 149 | 59 | ▶ | sub eol_to_unix { | ||||||||||||||||||||||||||
|
Subroutine
eol_to_unix: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 150 | 59 | my $self = shift; | |||||||||||||||||||||||||||
| 151 | |||||||||||||||||||||||||||||
| 152 | 59 | my $to_unix = $self->new({ | |||||||||||||||||||||||||||
| 153 | 'EOL' => 'unix', | ||||||||||||||||||||||||||||
| 154 | 'EOF' => 'unix', | ||||||||||||||||||||||||||||
| 155 | 'FixLast' => 'unix', | ||||||||||||||||||||||||||||
| 156 | })->fix_eol(@_); | ||||||||||||||||||||||||||||
| 157 | 59 | return $to_unix; | |||||||||||||||||||||||||||
| 158 | } | ||||||||||||||||||||||||||||
| 159 | |||||||||||||||||||||||||||||
| 160 | ########################################################################################## | ||||||||||||||||||||||||||||
| 161 | |||||||||||||||||||||||||||||
| 162 | 59 | ▶ | sub eol_to_dos { | ||||||||||||||||||||||||||
|
Subroutine
eol_to_dos: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 163 | 59 | my $self = shift; | |||||||||||||||||||||||||||
| 164 | |||||||||||||||||||||||||||||
| 165 | 59 | my $to_dos = $self->new({ | |||||||||||||||||||||||||||
| 166 | 'EOL' => 'dos', | ||||||||||||||||||||||||||||
| 167 | 'EOF' => 'dos', | ||||||||||||||||||||||||||||
| 168 | 'FixLast' => 'dos', | ||||||||||||||||||||||||||||
| 169 | })->fix_eol(@_); | ||||||||||||||||||||||||||||
| 170 | 59 | return $to_dos; | |||||||||||||||||||||||||||
| 171 | } | ||||||||||||||||||||||||||||
| 172 | |||||||||||||||||||||||||||||
| 173 | ########################################################################################## | ||||||||||||||||||||||||||||
| 174 | |||||||||||||||||||||||||||||
| 175 | 59 | ▶ | sub eol_to_mac { | ||||||||||||||||||||||||||
|
Subroutine
eol_to_mac: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 176 | 59 | my $self = shift; | |||||||||||||||||||||||||||
| 177 | |||||||||||||||||||||||||||||
| 178 | 59 | my $to_mac = $self->new({ | |||||||||||||||||||||||||||
| 179 | 'EOL' => 'mac', | ||||||||||||||||||||||||||||
| 180 | 'EOF' => 'mac', | ||||||||||||||||||||||||||||
| 181 | 'FixLast' => 'mac', | ||||||||||||||||||||||||||||
| 182 | })->fix_eol(@_); | ||||||||||||||||||||||||||||
| 183 | 59 | return $to_mac; | |||||||||||||||||||||||||||
| 184 | } | ||||||||||||||||||||||||||||
| 185 | |||||||||||||||||||||||||||||
| 186 | ########################################################################################## | ||||||||||||||||||||||||||||
| 187 | |||||||||||||||||||||||||||||
| 188 | 59 | ▶ | sub eol_to_network { | ||||||||||||||||||||||||||
|
Subroutine
eol_to_network: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 189 | 59 | my $self = shift; | |||||||||||||||||||||||||||
| 190 | |||||||||||||||||||||||||||||
| 191 | 59 | my $to_network= $self->new({ | |||||||||||||||||||||||||||
| 192 | 'EOL' => 'network', | ||||||||||||||||||||||||||||
| 193 | 'EOF' => 'network', | ||||||||||||||||||||||||||||
| 194 | 'FixLast' => 'yes', | ||||||||||||||||||||||||||||
| 195 | })->fix_eol(@_); | ||||||||||||||||||||||||||||
| 196 | 59 | return $to_network; | |||||||||||||||||||||||||||
| 197 | } | ||||||||||||||||||||||||||||
| 198 | |||||||||||||||||||||||||||||
| 199 | ########################################################################################## | ||||||||||||||||||||||||||||
| 200 | |||||||||||||||||||||||||||||
| 201 | 59 | ▶ | sub eol_to_crlf { | ||||||||||||||||||||||||||
|
Subroutine
eol_to_crlf: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 202 | 59 | my $self = shift; | |||||||||||||||||||||||||||
| 203 | |||||||||||||||||||||||||||||
| 204 | 59 | my $to_crlf = $self->new({ | |||||||||||||||||||||||||||
| 205 | 'EOL' => 'crlf', | ||||||||||||||||||||||||||||
| 206 | 'EOF' => 'remove', | ||||||||||||||||||||||||||||
| 207 | 'FixLast' => 'yes', | ||||||||||||||||||||||||||||
| 208 | })->fix_eol(@_); | ||||||||||||||||||||||||||||
| 209 | 59 | return $to_crlf; | |||||||||||||||||||||||||||
| 210 | } | ||||||||||||||||||||||||||||
| 211 | |||||||||||||||||||||||||||||
| 212 | ########################################################################################## | ||||||||||||||||||||||||||||
| 213 | |||||||||||||||||||||||||||||
| 214 | 424 | ▶ | sub fix_eol { | ||||||||||||||||||||||||||
|
Subroutine
fix_eol: called CC=13 SCAR=25.6
Pod
documented
| |||||||||||||||||||||||||||||
| 215 | 424 | my $self = shift; | |||||||||||||||||||||||||||
| 216 | |||||||||||||||||||||||||||||
| 217 | 424 | ▶ | unless (1 == @_) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 218 | 2 | require Carp; | |||||||||||||||||||||||||||
| 219 | 2 | my $package = __PACKAGE__; | |||||||||||||||||||||||||||
| 220 | 2 | Carp::croak("${package}::fix_eol() - Incorrect number of parameters passed. One string (only) is required."); | |||||||||||||||||||||||||||
| 221 | } | ||||||||||||||||||||||||||||
| 222 | |||||||||||||||||||||||||||||
| 223 | 422 | my ($string) = @_; | |||||||||||||||||||||||||||
| 224 | 422 | my $eol_mode = $self->eol_mode; | |||||||||||||||||||||||||||
| 225 | 422 | ▶ | if ($eol_mode ne 'asis') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 226 | 363 | $string = $self->_eol_to_base_lf($string); | |||||||||||||||||||||||||||
| 227 | } | ||||||||||||||||||||||||||||
| 228 | 422 | my $fix_last = $self->fix_last_mode; | |||||||||||||||||||||||||||
| 229 | 422 | ▶ | if ($fix_last eq 'yes') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 230 | 421 | my $old_eof = ''; | |||||||||||||||||||||||||||
| 231 | 421 | ▶ | if ($string =~ s/(\032+)$//s) { # \032 is Ctrl-Z | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 232 | 6 | $old_eof = "\032"; | |||||||||||||||||||||||||||
| 233 | } | ||||||||||||||||||||||||||||
| 234 | 421 | ▶ | if (($string ne '') and ($eol_mode ne 'asis')) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$string ne "" and $eol_mode ne "asis"
MC/DC100%2/2
$string ne "" and $eol_mode ne "asis"
$string ne ""
$eol_mode ne "asis"
Truth table100%3/3
A and B
A= $string ne ""B= $eol_mode ne "asis"
| |||||||||||||||||||||||||||||
| 235 | 358 | ▶ | if ($string !~ m/\012$/s) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 236 | 4 | $string .= "\012"; | |||||||||||||||||||||||||||
| 237 | } | ||||||||||||||||||||||||||||
| 238 | |||||||||||||||||||||||||||||
| 239 | } else { | ||||||||||||||||||||||||||||
| 240 | 63 | ▶ | if ($eol_mode ne 'asis') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 241 | 4 | $string = "\012"; | |||||||||||||||||||||||||||
| 242 | } | ||||||||||||||||||||||||||||
| 243 | } | ||||||||||||||||||||||||||||
| 244 | 421 | $string .= $old_eof; | |||||||||||||||||||||||||||
| 245 | } | ||||||||||||||||||||||||||||
| 246 | |||||||||||||||||||||||||||||
| 247 | 422 | my $eof_handling = $self->eof_mode; | |||||||||||||||||||||||||||
| 248 | 422 | ▶ | if ($eof_handling eq 'remove') { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 249 | 357 | $string =~ s/\032+$//s; | |||||||||||||||||||||||||||
| 250 | |||||||||||||||||||||||||||||
| 251 | ▶ | } elsif (($eof_handling eq 'add') and ($string !~ m/\032$/s)) { | |||||||||||||||||||||||||||
|
Condition100%3/3
$eof_handling eq "add" and not $string =~ /\032$/s
MC/DC100%2/2
$eof_handling eq "add" and not $string =~ /\032$/s
$eof_handling eq "add"
not $string =~ /\032$/s
Truth table100%3/3
A and not(B)
A= $eof_handling eq "add"B= not $string =~ /\032$/s
| |||||||||||||||||||||||||||||
| 252 | 2 | $string .= "\032"; | |||||||||||||||||||||||||||
| 253 | } | ||||||||||||||||||||||||||||
| 254 | |||||||||||||||||||||||||||||
| 255 | 422 | ▶ | if ($eol_mode ne 'asis') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 256 | 363 | my $eol_replacement = $eol_mode; | |||||||||||||||||||||||||||
| 257 | 363 | $string =~ s/\012/$eol_replacement/gs; | |||||||||||||||||||||||||||
| 258 | } | ||||||||||||||||||||||||||||
| 259 | 422 | return $string; | |||||||||||||||||||||||||||
| 260 | } | ||||||||||||||||||||||||||||
| 261 | |||||||||||||||||||||||||||||
| 262 | ########################################################################################## | ||||||||||||||||||||||||||||
| 263 | |||||||||||||||||||||||||||||
| 264 | 426 | ▶ | sub eol_mode { | ||||||||||||||||||||||||||
|
Subroutine
eol_mode: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 265 | 426 | my $self = shift; | |||||||||||||||||||||||||||
| 266 | 426 | my $eol_handling = $self->eol_handling; | |||||||||||||||||||||||||||
| 267 | |||||||||||||||||||||||||||||
| 268 | 426 | ▶ | if ($eol_handling =~ m/^literal:(.+)$/s) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 269 | 59 | return $1; | |||||||||||||||||||||||||||
| 270 | |||||||||||||||||||||||||||||
| 271 | } else { | ||||||||||||||||||||||||||||
| 272 | 367 | my $default_eol = $self->_platform_defaults($eol_handling, 'EOL'); | |||||||||||||||||||||||||||
| 273 | 367 | return $default_eol; | |||||||||||||||||||||||||||
| 274 | } | ||||||||||||||||||||||||||||
| 275 | } | ||||||||||||||||||||||||||||
| 276 | |||||||||||||||||||||||||||||
| 277 | ########################################################################################## | ||||||||||||||||||||||||||||
| 278 | |||||||||||||||||||||||||||||
| 279 | 422 | ▶ | sub eof_mode { | ||||||||||||||||||||||||||
|
Subroutine
eof_mode: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 280 | 422 | my $self = shift; | |||||||||||||||||||||||||||
| 281 | |||||||||||||||||||||||||||||
| 282 | 422 | my $eof_handling = $self->eof_handling; | |||||||||||||||||||||||||||
| 283 | 422 | my $default_eof = $self->_platform_defaults($eof_handling, 'EOF'); | |||||||||||||||||||||||||||
| 284 | 422 | return $default_eof; | |||||||||||||||||||||||||||
| 285 | } | ||||||||||||||||||||||||||||
| 286 | |||||||||||||||||||||||||||||
| 287 | ########################################################################################## | ||||||||||||||||||||||||||||
| 288 | |||||||||||||||||||||||||||||
| 289 | 422 | ▶ | sub fix_last_mode { | ||||||||||||||||||||||||||
|
Subroutine
fix_last_mode: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 290 | 422 | my $self = shift; | |||||||||||||||||||||||||||
| 291 | |||||||||||||||||||||||||||||
| 292 | 422 | my $fix_last = $self->fix_last_handling; | |||||||||||||||||||||||||||
| 293 | 422 | my $fix_last_mode = $self->_platform_defaults($fix_last, 'FixLast'); | |||||||||||||||||||||||||||
| 294 | 422 | return $fix_last_mode; | |||||||||||||||||||||||||||
| 295 | } | ||||||||||||||||||||||||||||
| 296 | |||||||||||||||||||||||||||||
| 297 | ########################################################################################## | ||||||||||||||||||||||||||||
| 298 | |||||||||||||||||||||||||||||
| 299 | 1212 | ▶ | sub _platform_defaults { | ||||||||||||||||||||||||||
|
Subroutine
_platform_defaults: called CC=8 SCAR=20.8
| |||||||||||||||||||||||||||||
| 300 | 1212 | my $self = shift; | |||||||||||||||||||||||||||
| 301 | 1212 | my $package = __PACKAGE__; | |||||||||||||||||||||||||||
| 302 | |||||||||||||||||||||||||||||
| 303 | 1212 | my ($platform_name, $property) = @_; | |||||||||||||||||||||||||||
| 304 | |||||||||||||||||||||||||||||
| 305 | 1212 | $platform_name = lc ($platform_name); | |||||||||||||||||||||||||||
| 306 | 1212 | $property = lc ($property); | |||||||||||||||||||||||||||
| 307 | |||||||||||||||||||||||||||||
| 308 | 1212 | ▶ | return $platform_name if (($property eq 'fixlast') and ($platform_name =~ m/^(yes|no)$/)); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$property eq "fixlast" and $platform_name =~ /^(yes|no)$/
MC/DC100%2/2
$property eq "fixlast" and $platform_name =~ /^(yes|no)$/
$property eq "fixlast"
$platform_name =~ /^(yes|no)$/
Truth table100%3/3
A and B
A= $property eq "fixlast"B= $platform_name =~ /^(yes|no)$/
| |||||||||||||||||||||||||||||
| 309 | 1085 | ▶ | return $platform_name if (($property eq 'eof') and ($platform_name =~ m/^(asis|remove|add)$/)); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$property eq "eof" and $platform_name =~ /^(asis|remove|add)$/
MC/DC100%2/2
$property eq "eof" and $platform_name =~ /^(asis|remove|add)$/
$property eq "eof"
$platform_name =~ /^(asis|remove|add)$/
Truth table100%3/3
A and B
A= $property eq "eof"B= $platform_name =~ /^(asis|remove|add)$/
| |||||||||||||||||||||||||||||
| 310 | |||||||||||||||||||||||||||||
| 311 | 1017 | ▶ | if ($platform_name eq 'platform') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 312 | 236 | $platform_name = lc ($^O); | |||||||||||||||||||||||||||
| 313 | } | ||||||||||||||||||||||||||||
| 314 | |||||||||||||||||||||||||||||
| 315 | 1017 | my $platform_defaults = $_Platform_Defaults{$platform_name}; | |||||||||||||||||||||||||||
| 316 | 1017 | ▶ | unless (defined ($platform_defaults)) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 317 | 236 | $platform_defaults = $_Platform_Defaults{'unknown'}; | |||||||||||||||||||||||||||
| 318 | } | ||||||||||||||||||||||||||||
| 319 | 1017 | my $property_value = $platform_defaults->{$property}; | |||||||||||||||||||||||||||
| 320 | 1017 | ▶ | unless (defined ($property_value)) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 321 | 1 | require Carp; | |||||||||||||||||||||||||||
| 322 | 1 | Carp::croak("${package}::_platform_defaults() - Unknown property of $property"); | |||||||||||||||||||||||||||
| 323 | } | ||||||||||||||||||||||||||||
| 324 | 1016 | return $property_value; | |||||||||||||||||||||||||||
| 325 | } | ||||||||||||||||||||||||||||
| 326 | |||||||||||||||||||||||||||||
| 327 | ########################################################################################## | ||||||||||||||||||||||||||||
| 328 | |||||||||||||||||||||||||||||
| 329 | 363 | ▶ | sub _eol_to_base_lf { | ||||||||||||||||||||||||||
|
Subroutine
_eol_to_base_lf: called CC=8 SCAR=20.8
| |||||||||||||||||||||||||||||
| 330 | 363 | my $self = shift; | |||||||||||||||||||||||||||
| 331 | |||||||||||||||||||||||||||||
| 332 | 363 | my ($string) = @_; | |||||||||||||||||||||||||||
| 333 | |||||||||||||||||||||||||||||
| 334 | # Undef converts to '' | ||||||||||||||||||||||||||||
| 335 | 363 | ▶ | return '' unless (defined $string); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 336 | |||||||||||||||||||||||||||||
| 337 | # If there are not any DOS EOLs (\015 characters), return the original string | ||||||||||||||||||||||||||||
| 338 | 362 | ▶ | return $string unless ($string =~ m/\015/s); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 339 | |||||||||||||||||||||||||||||
| 340 | # If there is nothing except DOS EOL, convert them to \012 directly | ||||||||||||||||||||||||||||
| 341 | 330 | ▶ | if ($string !~ m/\012/s) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 342 | 24 | $string =~ s/\015/\012/gs; | |||||||||||||||||||||||||||
| 343 | 24 | return $string; | |||||||||||||||||||||||||||
| 344 | } | ||||||||||||||||||||||||||||
| 345 | |||||||||||||||||||||||||||||
| 346 | # If the EOLs are all 'singletons', do in-place cleanup of the DOS EOLs | ||||||||||||||||||||||||||||
| 347 | 306 | ▶ | if (($string !~ m/\015\012/s) and ($string !~ m/\012\015/s)) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$string =~ /\015\012/s or $string =~ /\012\015/s
MC/DC100%2/2
$string =~ /\015\012/s or $string =~ /\012\015/s
$string =~ /\015\012/s
$string =~ /\012\015/s
Truth table100%3/3
A or B
A= $string =~ /\015\012/sB= $string =~ /\012\015/s
| |||||||||||||||||||||||||||||
| 348 | 36 | $string =~ s/\015/\012/gs; | |||||||||||||||||||||||||||
| 349 | 36 | return $string; | |||||||||||||||||||||||||||
| 350 | } | ||||||||||||||||||||||||||||
| 351 | |||||||||||||||||||||||||||||
| 352 | 270 | my @eols = $string =~ m/([\012\015]+)/sg; | |||||||||||||||||||||||||||
| 353 | 270 | my %replacement_map = (); | |||||||||||||||||||||||||||
| 354 | 270 | foreach my $eol_mode (@eols) { | |||||||||||||||||||||||||||
| 355 | 762 | ▶ | next if (defined $replacement_map{$eol_mode}); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 356 | 378 | my $replace_with = $eol_mode; | |||||||||||||||||||||||||||
| 357 | 378 | $replace_with =~ s/(\015\012|\012\015)/\012/gs; | |||||||||||||||||||||||||||
| 358 | 378 | $replace_with =~ s/\015/\012/gs; | |||||||||||||||||||||||||||
| 359 | 378 | $replacement_map{$eol_mode} = $replace_with; | |||||||||||||||||||||||||||
| 360 | } | ||||||||||||||||||||||||||||
| 361 | 270 | $string =~ s/([\012\015]+)/$replacement_map{$1}/gse; | |||||||||||||||||||||||||||
| 362 | |||||||||||||||||||||||||||||
| 363 | 270 | return $string; | |||||||||||||||||||||||||||
| 364 | } | ||||||||||||||||||||||||||||
| 365 | |||||||||||||||||||||||||||||
| 366 | ########################################################################################## | ||||||||||||||||||||||||||||
| 367 | |||||||||||||||||||||||||||||
| 368 | 1064 | ▶ | sub eol_handling { return shift->_property('eol_handling', @_); } | ||||||||||||||||||||||||||
|
Subroutine
eol_handling: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 369 | 1055 | ▶ | sub eof_handling { return shift->_property('eof_handling', @_); } | ||||||||||||||||||||||||||
|
Subroutine
eof_handling: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 370 | 1056 | ▶ | sub fix_last_handling { return shift->_property('fix_last_handling', @_); } | ||||||||||||||||||||||||||
|
Subroutine
fix_last_handling: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 371 | |||||||||||||||||||||||||||||
| 372 | ########################################################################################## | ||||||||||||||||||||||||||||
| 373 | # _property('property_name' => $property_value) | ||||||||||||||||||||||||||||
| 374 | # | ||||||||||||||||||||||||||||
| 375 | # get/set base accessor for property values | ||||||||||||||||||||||||||||
| 376 | |||||||||||||||||||||||||||||
| 377 | 3176 | ▶ | sub _property { | ||||||||||||||||||||||||||
|
Subroutine
_property: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||
| 378 | 3176 | my $self = shift; | |||||||||||||||||||||||||||
| 379 | |||||||||||||||||||||||||||||
| 380 | 3176 | my $property = shift; | |||||||||||||||||||||||||||
| 381 | |||||||||||||||||||||||||||||
| 382 | 3176 | my $package = __PACKAGE__; | |||||||||||||||||||||||||||
| 383 | 3176 | ▶ | if (0 == @_) { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 384 | 1290 | my $output = $self->{$package}->{$property}; | |||||||||||||||||||||||||||
| 385 | 1290 | return $output; | |||||||||||||||||||||||||||
| 386 | |||||||||||||||||||||||||||||
| 387 | } elsif (1 == @_) { | ||||||||||||||||||||||||||||
| 388 | 1885 | my $input = shift; | |||||||||||||||||||||||||||
| 389 | 1885 | $self->{$package}->{$property} = $input; | |||||||||||||||||||||||||||
| 390 | 1885 | return; | |||||||||||||||||||||||||||
| 391 | } else { | ||||||||||||||||||||||||||||
| 392 | 1 | die ("Bad calling parameters to ${package}::${property}()\n"); | |||||||||||||||||||||||||||
| 393 | } | ||||||||||||||||||||||||||||
| 394 | } | ||||||||||||||||||||||||||||
| 395 | |||||||||||||||||||||||||||||
| 396 | ########################################################################################## | ||||||||||||||||||||||||||||
| 397 | |||||||||||||||||||||||||||||
| 398 | 2 | 1; | |||||||||||||||||||||||||||