Config-General
view release on metacpan or search on metacpan
pod for details.
- added test case for the code.
- fixed unindented half of the pod, which was largely no
readable because of this. However, I wonder why this hasn't
reported, seems nobody reads the docs :)
- fixed tab/space issues here and there
2.61 - fix rt.cpan.org#113671: ignore utf BOM, if any and turn on
UTF8 support if not yet enabled.
2.60 - fix rt.cpan.org#107929: added missing test config.
2.59 - fix rt.cpan.org#107108 by adding support for IncludeOptional.
- clarified documentation on StoreDelimiter.
2.58 - bumbp version
2.57 - fix rt.cpan.org#104548, dont allow special chars like newline
use Carp;
use Exporter;
$Config::General::VERSION = "2.67";
use base qw(Exporter);
our @EXPORT_OK = qw(ParseConfig SaveConfig SaveConfigString);
use constant _UTF8_BOM => "\x{ef}\x{bb}\x{bf}";
sub new {
#
# create new Config::General object
#
my($this, @param ) = @_;
my $class = ref($this) || $this;
# define default options
my $self = {
sub _openfile_for_read {
#
# actually open a file, turn on utf8 mode if requested by bom
#
my ($this, $file) = @_;
my $fh = IO::File->new( $file, 'r')
or croak "Config::General: Could not open $file!($!)\n";
# attempt to read an initial utf8 byte-order mark (BOM)
my $n_read = sysread $fh, my $read_BOM, length(_UTF8_BOM);
my $has_BOM = $n_read == length(_UTF8_BOM) && $read_BOM eq _UTF8_BOM;
# set utf8 perlio layer if BOM was found or if option -UTF8 is turned on
binmode $fh, ":utf8" if $this->{UTF8} || $has_BOM;
# rewind to beginning of file if we read chars that were not the BOM
sysseek $fh, 0, 0 if $n_read && !$has_BOM;
return $fh;
}
sub _read {
#
# store the config contents in @content
# and prepare it somewhat for easier parsing later
my %hash55 = $cfg55->getall();
is($hash55{b}, "nochop", "check continuation followed by empty line");
my $cfg56 = Config::General->new();
eval {
$cfg56->save_file("t/56.out", { "new\nline" => 9, "brack<t" => 8 });
};
ok($@, "catch special chars in keys");
# UTF8[BOM] tests
my $cfg57 = "t/utf8_bom/foo.cfg";
my $expected57 = {foo => {"\x{e9}" => "\x{e8}", bar => {"\x{f4}" => "\x{ee}"}}};
for my $bool (0, 1) {
my $conf = Config::General->new(-ConfigFile => $cfg57,
-IncludeRelative => 1,
-UTF8 => $bool);
my %hash = $conf->getall;
is_deeply \%hash, $expected57, "-UTF8 => $bool";
}
( run in 0.927 second using v1.01-cache-2.11-cpan-f29a10751f0 )