Config-Wrest
view release on metacpan or search on metacpan
lib/Config/Wrest.pm
lib/Data/Serializer/Config/Wrest.pm
t/Config-Wrest-internals.t
t/Read-allowempty.t
t/Read-base.t
t/Read-blocks.t
t/Read-directives-errors.t
t/Read-directives.t
t/Read-errors.t
t/Read-lists.t
t/Read-unicode.t
t/Read-unicode1.t
t/Read-xlate-lineending.t
t/Serializer-1.t
t/Write.t
t/data/Reader_1.cfg
t/data/Reader_bad_config.cfg
t/data/Reader_badnesting.cfg
t/data/Reader_directives1.cfg
t/data/Reader_directives2.cfg
t/data/Reader_directives3.cfg
t/data/Reader_dosfile.cfg
t/data/Reader_short.cfg
t/data/Reader_unclosed.cfg
t/data/Reader_underflow.cfg
t/data/Reader_unicode.cfg
t/data/Reader_unicode2.cfg
t/data/Reader_unicode3.cfg
t/data/Writer_1.cfg
t/pod.t
t/pod_coverage.t
META.yml Module meta-data (added by MakeMaker)
lib/Config/Wrest.pm view on Meta::CPAN
if the value would create bad config data.
In general you will want to use the 'Escapes' option described above. This makes it hard to produce bad configuration files.
If you want to dump out cyclic / self-referential data structures you'll need to set the 'WriteWithReferences' option, otherwise the deep recursion
will be detected and the serialization will throw a fatal error.
=head1 SEE ALSO
parse_file(), write_file() and the '@include' directive load L<File::Slurp::WithinPolicy> on demand to perform the file input/output operations.
See L<perlunicode> for more details on perl's Unicode handling, and L<Encode> for character recoding.
See L<Any::Template>, and the relevant templating modules, if the 'Subs' option is true.
Although this module can read and write data structures it is not intended as an all-purpose serialization system. For that
see L<Storable>.
Unicode Newline Guidelines from http://www.unicode.org/versions/Unicode4.0.0/ch05.pdf#G10213
=head1 VERSION
$Revision: 1.36 $ on $Date: 2006/08/22 14:09:50 $ by $Author: mattheww $
=head1 AUTHOR
IF&L Software Engineers <cpan _at_ bbc _dot_ co _dot_ uk>
=head1 COPYRIGHT
t/Read-unicode.t view on Meta::CPAN
#!/usr/local/bin/perl
# Unicode-related functionality
# $Id: Read-unicode.t,v 1.2 2006/08/25 14:26:34 mattheww Exp $
use strict;
use Getopt::Std;
use lib("./lib","../lib");
use Config::Wrest;
use Test::Assertions('test');
use Log::Trace;
use Cwd;
use vars qw($opt_t $opt_T);
t/Read-unicode.t view on Meta::CPAN
if($opt_t) {
import Log::Trace qw(print);
}
if($opt_T) {
deep_import Log::Trace qw(print);
}
BEGIN {
if ($] && $] < 5.006001) {
print "1..1\n";
print "ok 1 (Skipping all - perl version is $] which is too low for these unicode-related tests)\n";
exit(0);
}
}
eval "use HTML::Template;";
if ($@) {
print "1..1\n";
print "ok 1 (Skipping all - HTML::Template required for testing this templated configuration)\n";
exit (0);
}
#########################################################
#
# Note:
# Some of these tests are known to fail on perl 5.6.1
# This is how it should behave because of various known
# issues with the 5.6 unicode implementation. I think
# that the main issue is the way that regexps don't
# create polymorphic opcodes, and hence when a string
# goes through a regexp it goes from wide-chars to bytes.
# The config parsing is done with regexes so this can be
# an issue (esp. when the config data is a string
# containing wide-chars, rather than a file continaing
# escape sequences.
#
# Please see the perlunicode page for perl 5.6.1 for
# more information
#
#########################################################
my $is_5_point_6 = 0;
if ($^V && $^V ge chr(5).chr(8).chr(0)) {
binmode(STDOUT, ':utf8');
plan tests => 53;
} else {
$is_5_point_6 = 1;
plan tests => 26;
}
chdir 't' if -d 't';
my $cr = new Config::Wrest( TemplateBackend => "HTML::Template", TemplateOptions => { die_on_bad_params => 0 }, Escapes => 1, UseQuotes => 1 );
#########################################################
# from a string containing unicode data
my $vars = $cr->deserialize(
"midorder 'copy\x{a9}right'\n".
"highorder 'c\x{153}ur'"
);
ASSERT(ref($cr), 'new object created from unicode string');
DUMP('Variables', $vars);
my $str = $vars->{'midorder'};
my $l = length($str);
if ($is_5_point_6) {
ASSERT(1, "skipped - String contents test");
ASSERT(1, "skipped - length test");
} else {
ASSERT($str eq "copy\x{a9}right", "String is <$str>");
ASSERT(($l == 10), "length is $l");
t/Read-unicode.t view on Meta::CPAN
$str = $vars->{'highorder'};
$l = length($str);
ASSERT($str eq "c\x{153}ur", "String is <$str>");
if ($is_5_point_6) {
ASSERT(1, "skipped - length test");
} else {
ASSERT(($l == 4), "length is $l");
}
#########################################################
# from a file with unicode escapes - not /read/ as actual utf8 though
$cr = new Config::Wrest( TemplateBackend => "HTML::Template", TemplateOptions => { die_on_bad_params => 0 }, Escapes => 1, UseQuotes => 1, Subs => 1 );
$vars = $cr->parse_file("./data/Reader_unicode.cfg");
ASSERT(ref($cr), 'new object created from file');
my $d = $vars->{"unicode_tests"};
DUMP("test data block", $d);
ASSERT(ref($d), "some data returned");
$str = $d->{"loworder"};
$l = length($str);
ASSERT( $str eq "C BBC" , "String is <$str>");
ASSERT(($l == 5), "length is $l");
$str = $d->{"midorder1"};
$l = length($str);
t/Read-unicode.t view on Meta::CPAN
#########################################################
# brief test of externally-read files
# irrelevant, and indeed error-causing, for perl 5.6
if ($is_5_point_6) {
ASSERT(1, "skipped - remaining tests are not relevant to perl 5.6");
exit(0);
}
$str = _read_disc("./data/Reader_unicode.cfg", "utf8");
$cr = new Config::Wrest( TemplateBackend => "HTML::Template", TemplateOptions => { die_on_bad_params => 0 }, Escapes => 1, UseQuotes => 1, Subs => 1 );
$vars = $cr->deserialize($str);
$d = $vars->{"unicode_tests"};
DUMP("file read - test data block", $d);
$str = $d->{"highorder"};
$l = length($str);
ASSERT( $str eq "C\x{153}ur et amour" , "String is <$str>");
ASSERT(($l == 13), "length is $l");
$str = _read_disc("./data/Reader_unicode2.cfg", "utf8");
$cr = new Config::Wrest( TemplateBackend => "HTML::Template", TemplateOptions => { die_on_bad_params => 0 }, Escapes => 1, UseQuotes => 1, Subs => 1 );
$vars = $cr->deserialize($str);
$d = $vars->{"io_tests"};
DUMP("file read - test data block", $d);
$str = $d->{"gar\x{e7}on"};
ASSERT( ref($str), "Data against unicode key");
$str = $d->{"gar\x{e7}on"}{"\x{de}e_old_tea_shoppe"}[0];
$l = length($str);
ASSERT( $str eq "\x{b1}23volts", "String is <$str>");
ASSERT(($l == 8), "length is $l");
$str = $d->{"gar\x{e7}on"}{"\x{de}e_old_tea_shoppe"}[1];
$l = length($str);
ASSERT( $str eq "\x{201c}Hello!\x{201d}", "String is <$str>");
ASSERT(($l == 8), "length is $l");
t/Read-unicode.t view on Meta::CPAN
$str = $d->{"inserted"};
$l = length($str);
ASSERT( $str eq "soup\x{e7}on", "String is <$str>");
ASSERT(($l == 7), "length is $l");
### We will assume that other input disciplines have been suitably well-tested
### and that they work, but we'll do a quick test here just to check
$str = _read_disc("./data/Reader_unicode3.cfg", "encoding(iso-8859-7)");
$cr = new Config::Wrest( TemplateBackend => "HTML::Template", TemplateOptions => { die_on_bad_params => 0 }, Escapes => 1, UseQuotes => 1, Subs => 1 );
$vars = $cr->deserialize($str);
$d = $vars;
DUMP("file read - test data block", $d);
$str = $d->{'plainname'};
$l = length($str);
ASSERT( $str eq "delta", "String is <$str>");
ASSERT(($l == 5), "length is $l");
$str = $d->{"\x{394}\x{3b5}\x{3bb}\x{3c4}\x{3b1}"};
$l = length($str);
ASSERT( $str eq "Force", "String is <$str>");
ASSERT(($l == 5), "length is $l");
$str = $d->{"\x{3a3}umma"};
ASSERT(ref($str), "Data against unicode key");
$str = $d->{"\x{3a3}umma"}[0];
$l = length($str);
ASSERT( $str eq "\x{391}\x{3b8}ens", "String is <$str>");
ASSERT(($l == 5), "length is $l");
#########################################################
t/Read-unicode1.t view on Meta::CPAN
#!/usr/local/bin/perl
# Unicode-related functionality
# $Id: Read-unicode1.t,v 1.1 2006/08/25 14:26:34 mattheww Exp $
use strict;
use Getopt::Std;
use lib("./lib","../lib");
use Config::Wrest;
use Test::Assertions('test');
use Log::Trace;
use Cwd;
use vars qw($opt_t $opt_T);
t/Read-unicode1.t view on Meta::CPAN
if($opt_t) {
import Log::Trace qw(print);
}
if($opt_T) {
deep_import Log::Trace qw(print);
}
BEGIN {
if ($] && $] < 5.006001) {
print "1..1\n";
print "ok 1 (Skipping all - perl version is $] which is too low for these unicode-related tests)\n";
exit(0);
}
}
#########################################################
#
# Note:
# Some of these tests are known to fail on perl 5.6.1
# This is how it should behave because of various known
# issues with the 5.6 unicode implementation. I think
# that the main issue is the way that regexps don't
# create polymorphic opcodes, and hence when a string
# goes through a regexp it goes from wide-chars to bytes.
# The config parsing is done with regexes so this can be
# an issue (esp. when the config data is a string
# containing wide-chars, rather than a file continaing
# escape sequences.
#
# Please see the perlunicode page for perl 5.6.1 for
# more information
#
#########################################################
my $is_5_point_6 = 0;
if ($^V && $^V ge chr(5).chr(8).chr(0)) {
binmode(STDOUT, ':utf8');
} else {
$is_5_point_6 = 1;
}
plan tests => 5;
chdir 't' if -d 't';
my $cr = new Config::Wrest( Escapes => 1, UseQuotes => 1 );
#########################################################
# from a string containing unicode data
my $vars = $cr->deserialize(
"midorder 'copy\x{a9}right'\n".
"highorder 'c\x{153}ur'"
);
ASSERT(ref($cr), 'new object created from unicode string');
DUMP('Variables', $vars);
my $str = $vars->{'midorder'};
my $l = length($str);
if ($is_5_point_6) {
ASSERT(1, "skipped - String contents test");
ASSERT(1, "skipped - length test");
} else {
ASSERT($str eq "copy\x{a9}right", "String is <$str>");
ASSERT(($l == 10), "length is $l");
t/data/Reader_unicode.cfg view on Meta::CPAN
## Test cases specifically for Unicode handling
## This file can be read with any ascii-compatible discipline
##
## Version $Id: Reader_unicode.cfg,v 1.2 2006/08/25 14:26:34 mattheww Exp $
<unicode_tests>
loworder "C BBC"
midorder1 "%a9 BBC"
midorder2 "%{a9} BBC"
highorder "C%{153}ur et amour"
[list]
foo%a9bbc
"foo%a9bbc"
C%{153}ur
"C%{153}ur"
@set UnicodeFoo C%{153}ur
t/data/Reader_unicode2.cfg view on Meta::CPAN
## Test cases specifically for Unicode handling
## This file is designed to be read with the :utf8 discipline
##
## Version $Id: Reader_unicode2.cfg,v 1.2 2006/08/25 14:26:34 mattheww Exp $
<io_tests>
plainname creéme
élan brulee
<garçon>
[Ãe_old_tea_shoppe]
±23volts
âHello!â
'âHello!â said Kate'
[/]
t/data/Reader_unicode3.cfg view on Meta::CPAN
## Test cases specifically for Unicode handling
## This file is designed to be read with the single-byte encoding discipline
##
## Version $Id: Reader_unicode3.cfg,v 1.1 2005/09/08 12:37:36 piersk Exp $
plainname delta
Äåëôá Force # 'Delta'
[Óumma] # 'Summa'
Áèens # 'Athens'
[/]
( run in 0.657 second using v1.01-cache-2.11-cpan-88abd93f124 )