mirror of
https://codeberg.org/scip/Config-General.git
synced 2025-12-17 12:41:07 +01:00
add new flag AlwaysQuoteOutput for write quoting
This commit is contained in:
12
General.pm
12
General.pm
@@ -32,7 +32,7 @@ use Carp::Heavy;
|
|||||||
use Carp;
|
use Carp;
|
||||||
use Exporter;
|
use Exporter;
|
||||||
|
|
||||||
$Config::General::VERSION = "2.65";
|
$Config::General::VERSION = "2.66";
|
||||||
|
|
||||||
use base qw(Exporter);
|
use base qw(Exporter);
|
||||||
our @EXPORT_OK = qw(ParseConfig SaveConfig SaveConfigString);
|
our @EXPORT_OK = qw(ParseConfig SaveConfig SaveConfigString);
|
||||||
@@ -96,7 +96,8 @@ sub new {
|
|||||||
NormalizeValue => 0,
|
NormalizeValue => 0,
|
||||||
Plug => {},
|
Plug => {},
|
||||||
UseApacheIfDefine => 0,
|
UseApacheIfDefine => 0,
|
||||||
Define => {}
|
Define => {},
|
||||||
|
AlwaysQuoteOutput => 0
|
||||||
};
|
};
|
||||||
|
|
||||||
# create the class instance
|
# create the class instance
|
||||||
@@ -1424,7 +1425,7 @@ sub _write_scalar {
|
|||||||
$line =~ s/([#\$\\\"])/\\$1/g;
|
$line =~ s/([#\$\\\"])/\\$1/g;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($line =~ /\s/) {
|
if ($line =~ /^\s/ || $line =~ /\s$/ || $this->{AlwaysQuoteOutput}) {
|
||||||
# quote lines containing whitespace
|
# quote lines containing whitespace
|
||||||
$line = "\"$line\"";
|
$line = "\"$line\"";
|
||||||
}
|
}
|
||||||
@@ -2119,6 +2120,11 @@ Same as B<-NormalizeBlock> but applied on options only.
|
|||||||
|
|
||||||
Same as B<-NormalizeBlock> but applied on values only.
|
Same as B<-NormalizeBlock> but applied on values only.
|
||||||
|
|
||||||
|
=item B<-AlwaysQuoteOutput>
|
||||||
|
|
||||||
|
If set to true, then values containing whitespace will always quoted
|
||||||
|
when calling C<save_string()> or C<save_file()>.
|
||||||
|
|
||||||
=back
|
=back
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
11
t/run.t
11
t/run.t
@@ -8,7 +8,7 @@
|
|||||||
|
|
||||||
|
|
||||||
use Data::Dumper;
|
use Data::Dumper;
|
||||||
use Test::More tests => 78;
|
use Test::More tests => 79;
|
||||||
#use Test::More qw(no_plan);
|
#use Test::More qw(no_plan);
|
||||||
|
|
||||||
# ahem, we deliver the test code with a local copy of
|
# ahem, we deliver the test code with a local copy of
|
||||||
@@ -791,3 +791,12 @@ foreach my $def (keys %defs) {
|
|||||||
my %hash = $conf->getall();
|
my %hash = $conf->getall();
|
||||||
is_deeply \%hash, $expected58, "UseApacheIfDefine, -Define => $def";
|
is_deeply \%hash, $expected58, "UseApacheIfDefine, -Define => $def";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# force quoting
|
||||||
|
my $cfg59 = "t/cfg.59";
|
||||||
|
my $expected59 = qq(foo "bar baz"
|
||||||
|
); # newline is important here, as we check write output
|
||||||
|
my $conf = Config::General->new(-ConfigFile => $cfg59,
|
||||||
|
-AlwaysQuoteOutput => 1);
|
||||||
|
my $got59 = $conf->save_string();
|
||||||
|
is_deeply \$expected59, \$got59, "quotes";
|
||||||
|
|||||||
Reference in New Issue
Block a user