[Bps-public-commit] UNNAMED PROJECT branch, master, updated. 494a7c9914ee1cda193882afc7eb4fabe17d3a64
jesse
jesse at bestpractical.com
Mon Mar 2 19:15:26 EST 2009
The branch, master has been updated
via 494a7c9914ee1cda193882afc7eb4fabe17d3a64 (commit)
via 12316288324a3146ddd251fa57c093785bf957c7 (commit)
via 147d6e5206e8aecc1b5a9d85324060540900a8da (commit)
via 017208bd9c696b6a5706446ea85acd24d9cf83b4 (commit)
from d48a7be30eeb415f40b567d8c25362386de73f1b (commit)
Summary of changes:
.gitignore | 7 ++
dist.ini | 10 ++
examples/simple.ini | 14 +++
lib/Config/INI/Ordered.pm | 15 +++
lib/Config/INI/Ordered/Reader.pm | 13 +++
lib/Config/INI/Ordered/Writer.pm | 8 ++
t/from-config-ini/00-load.t | 7 ++
t/from-config-ini/reader-err.t | 70 ++++++++++++++
t/from-config-ini/reader.t | 96 +++++++++++++++++++
t/from-config-ini/writer.t | 193 ++++++++++++++++++++++++++++++++++++++
xt/release/pod-coverage.t | 8 ++
xt/release/pod.t | 7 ++
12 files changed, 448 insertions(+), 0 deletions(-)
create mode 100644 dist.ini
create mode 100644 examples/simple.ini
create mode 100644 lib/Config/INI/Ordered.pm
create mode 100644 lib/Config/INI/Ordered/Reader.pm
create mode 100644 lib/Config/INI/Ordered/Writer.pm
create mode 100644 t/from-config-ini/00-load.t
create mode 100644 t/from-config-ini/reader-err.t
create mode 100644 t/from-config-ini/reader.t
create mode 100644 t/from-config-ini/writer.t
create mode 100644 xt/release/pod-coverage.t
create mode 100644 xt/release/pod.t
- Log -----------------------------------------------------------------
commit 017208bd9c696b6a5706446ea85acd24d9cf83b4
Author: Jesse Vincent <jesse at bestpractical.com>
Date: Mon Mar 2 19:14:18 2009 -0500
.gitignore update
diff --git a/.gitignore b/.gitignore
index e69de29..5589460 100644
--- a/.gitignore
+++ b/.gitignore
@@ -0,0 +1,7 @@
+blib
+pm_to_blib
+*.swp
+*~
+Makefile
+inc
+META.yml
commit 147d6e5206e8aecc1b5a9d85324060540900a8da
Author: Jesse Vincent <jesse at bestpractical.com>
Date: Mon Mar 2 19:14:35 2009 -0500
dist.ini
diff --git a/dist.ini b/dist.ini
new file mode 100644
index 0000000..001edee
--- /dev/null
+++ b/dist.ini
@@ -0,0 +1,10 @@
+name = Config-INI-Ordered
+version = 0.001
+author = Jesse Vincent <jesse at bestpractical.com>
+license = Perl_5
+copyright_holder = Best Practical Solutions
+
+[@Classic]
+
+[Prereq]
+Config::INI = 0
commit 12316288324a3146ddd251fa57c093785bf957c7
Author: Jesse Vincent <jesse at bestpractical.com>
Date: Mon Mar 2 19:14:50 2009 -0500
clone examples form config-ini so we don't break em
diff --git a/examples/simple.ini b/examples/simple.ini
new file mode 100644
index 0000000..a323b25
--- /dev/null
+++ b/examples/simple.ini
@@ -0,0 +1,14 @@
+root=something
+
+[section]
+one=two
+Foo=Bar
+this=Your Mother!
+blank=
+
+[section]
+moo=kooh
+
+[Section Two]
+something else=blah
+ remove = whitespace
diff --git a/t/from-config-ini/00-load.t b/t/from-config-ini/00-load.t
new file mode 100644
index 0000000..030528f
--- /dev/null
+++ b/t/from-config-ini/00-load.t
@@ -0,0 +1,7 @@
+#!perl -w
+use strict;
+
+use Test::More tests => 2;
+
+use_ok('Config::INI::Ordered::Reader');
+use_ok('Config::INI::Ordered::Writer');
diff --git a/t/from-config-ini/reader-err.t b/t/from-config-ini/reader-err.t
new file mode 100644
index 0000000..3abef5b
--- /dev/null
+++ b/t/from-config-ini/reader-err.t
@@ -0,0 +1,70 @@
+#!perl -Tw
+
+use strict;
+
+use Config::INI::Ordered::Reader;
+
+use Test::More tests => 7;
+
+eval { Config::INI::Ordered::Reader->read_file; };
+like($@, qr/no filename specified/i, 'read_file without args');
+
+{
+ my $filename = q{t/does/not/exist};
+
+ Carp::croak "unexpected file found in test directory t"
+ if -e 't/does/not/exist';
+
+ eval { Config::INI::Ordered::Reader->read_file($filename); };
+ like(
+ $@,
+ qr/file '$filename' does not exist/i,
+ 'read_file with non-existent file'
+ );
+}
+
+{
+ my $filename = 'lib';
+
+ eval { Config::INI::Ordered::Reader->read_file($filename); };
+ like($@, qr/not a plain file/i, 'read_file on non-plain-file');
+}
+
+SKIP: {
+ eval "require File::Temp;" or skip "File::Temp not available", 1;
+
+ # This could probably be limited to being required for Cygwin.
+ eval "require filetest;" or skip "filetest.pm not available", 1;
+ filetest->import('access');
+
+ my ($fh, $fn) = File::Temp::tempfile(UNLINK => 1);
+ close $fh;
+
+ chmod 0222, $fn;
+
+ if (-r $fn) {
+ chmod 0666, $fh;
+ skip "chmoding file 0222 left it -r", 1;
+ }
+
+ eval { Config::INI::Ordered::Reader->read_file($fn); };
+ like($@, qr/(?:couldn't|can't) read/, "can't read an unreadable file");
+
+ chmod 0666, $fh;
+}
+
+eval { Config::INI::Ordered::Reader->read_string; };
+like($@, qr/no string provided/i, 'read_string without args');
+
+{
+ my $input = 'foo bar moo';
+ eval { Config::INI::Ordered::Reader->read_string($input); };
+ like($@, qr/Syntax error at line 1: '$input'/i, 'syntax error');
+}
+
+{
+ # looks like a comment
+ my $input = "[foo ; bar]\nvalue = 1\n";
+ my $data = eval { Config::INI::Ordered::Reader->read_string($input); };
+ like($@, qr/Syntax error at line 1:/i, 'syntax error');
+}
diff --git a/t/from-config-ini/reader.t b/t/from-config-ini/reader.t
new file mode 100644
index 0000000..a7d25b7
--- /dev/null
+++ b/t/from-config-ini/reader.t
@@ -0,0 +1,96 @@
+#!perl -Tw
+
+use strict;
+
+use IO::File;
+use IO::String;
+use Test::More tests => 8;
+
+# Check their perl version
+use_ok('Config::INI::Ordered::Reader');
+
+# Try to read in a config
+my $hashref = Config::INI::Ordered::Reader->read_file( 'examples/simple.ini' );
+isa_ok($hashref, 'HASH', "return of Config::INI::Ordered::Reader->read_file");
+
+# Check the structure of the config
+my $expected = {
+ '_' => {
+ root => 'something',
+ },
+ section => {
+ one => 'two',
+ Foo => 'Bar',
+ this => 'Your Mother!',
+ blank => '',
+ moo => 'kooh',
+ },
+ 'Section Two' => {
+ 'something else' => 'blah',
+ 'remove' => 'whitespace',
+ },
+};
+
+is_deeply($hashref, $expected, 'Config structure matches expected');
+
+# Add some stuff to the trivial config and check write_string() for it
+my $Trivial = {};
+$Trivial->{_} = { root1 => 'root2' };
+$Trivial->{section} = {
+ foo => 'bar',
+ this => 'that',
+ blank => '',
+};
+$Trivial->{section2} = {
+ 'this little piggy' => 'went to market'
+};
+
+my $string = <<END;
+root1=root2
+
+[ section ]
+blank=
+foo=bar
+this=that
+
+[section2]
+this little piggy=went to market
+END
+
+{ # Test read_string
+ my $hashref = Config::INI::Ordered::Reader->read_string( $string );
+ isa_ok($hashref, 'HASH', "return of Config::INI::Ordered::Reader->read_string");
+
+ is_deeply( $hashref, $Trivial, '->read_string returns expected value' );
+}
+
+{ # Test read_handle
+ my $fh = IO::File->new('examples/simple.ini', 'r');
+ my $data = do { local $/ = undef; <$fh> };
+
+ is_deeply(
+ Config::INI::Ordered::Reader->new->read_handle( IO::String->new($data) ),
+ $expected,
+ '->read_handle returns expected value'
+ );
+}
+
+#####################################################################
+# Bugs that happened we don't want to happen again
+
+{
+ # Reading in an empty file, or a defined but zero length string, should yield
+ # a valid, but empty, object.
+ my $empty = Config::INI::Ordered::Reader->read_string('');
+ is_deeply($empty, {}, "an empty string gets an empty hashref");
+}
+
+{
+ # "0" is a valid section name
+ my $config = Config::INI::Ordered::Reader->read_string("[0]\nfoo = 1\n");
+ is_deeply(
+ $config,
+ { 0 => { foo => 1 } },
+ "we can use 0 as a section name",
+ );
+}
diff --git a/t/from-config-ini/writer.t b/t/from-config-ini/writer.t
new file mode 100644
index 0000000..55b9eb9
--- /dev/null
+++ b/t/from-config-ini/writer.t
@@ -0,0 +1,193 @@
+#!perl -Tw
+
+use strict;
+
+use Test::More tests => 20;
+
+my $R = 'Config::INI::Ordered::Reader';
+my $W = 'Config::INI::Ordered::Writer';
+
+use_ok($_) for $R, $W;
+
+my $data = {
+ _ => {
+ a => 1,
+ b => 2,
+ c => 3,
+ },
+ foo => {
+ bar => 'baz',
+ baz => 'bar',
+ },
+};
+
+is_deeply(
+ $R->read_string($W->write_string($data)),
+ $data,
+ 'we can round-trip hashy data',
+);
+
+is_deeply(
+ $R->read_string($W->new->write_string($data)),
+ $data,
+ 'we can round-trip hashy data, object method',
+);
+
+my $starting_first = [
+ _ => [
+ a => 1,
+ b => 2,
+ c => 3,
+ ],
+ foo => [
+ bar => 'baz',
+ baz => 'bar',
+ quux => undef,
+ ],
+];
+
+my $expected = <<'END_INI';
+a = 1
+b = 2
+c = 3
+
+[foo]
+bar = baz
+baz = bar
+END_INI
+
+is(
+ $W->write_string($starting_first),
+ $expected,
+ 'stringifying AOA, _ first',
+);
+
+is(
+ $W->new->write_string($starting_first),
+ $expected,
+ 'stringifying AOA, _ first, object method',
+);
+
+{
+ my $expected = <<'END_INI';
+[foo]
+bar = baz
+baz = bar
+
+[_]
+a = 1
+b = 2
+c = 3
+
+[foo]
+fer = agin
+END_INI
+
+ my $starting_later = [
+ foo => [
+ bar => 'baz',
+ baz => 'bar',
+ quux => undef,
+ ],
+ _ => [
+ a => 1,
+ b => 2,
+ c => 3,
+ ],
+ foo => [
+ fer => 'agin',
+ ],
+ ];
+
+ is(
+ $W->write_string($starting_later),
+ $expected,
+ 'stringifying AOA, _ later',
+ );
+
+ is(
+ $W->new->write_string($starting_later),
+ $expected,
+ 'stringifying AOA, _ later, object method',
+ );
+}
+
+{
+ my @possibilities = (
+ [ a => [ b => 1 ] ],
+ [ a => { b => 1 } ],
+ { a => { b => 1 } },
+ { a => [ b => 1 ] },
+ );
+
+ my $reference = $W->write_string(shift @possibilities);
+ my $failures = 0;
+ $failures++ unless $W->write_string(shift @possibilities) eq $reference;
+
+ ok(!$failures, "all array/hash combinations seem miscible");
+}
+
+eval { $W->write_string([ A => [ B => 1 ], A => [ B => 2 ] ]); };
+like($@, qr/multiple/, "you can't set property B in section A more than once");
+
+SKIP: {
+ eval "require File::Temp;" or skip "File::Temp not availabe", 3;
+
+ # This could probably be limited to being required for Cygwin.
+ eval "require filetest;" or skip "filetest.pm not available", 3;
+ filetest->import('access');
+
+ my ($fh, $fn) = File::Temp::tempfile(UNLINK => 1);
+ close $fh;
+ unlink $fn;
+
+ $W->write_file($data, $fn);
+
+ is_deeply(
+ $R->read_file($fn),
+ $data,
+ "round-trip data->file->data",
+ );
+
+ my $new_data = { foo => { a => 1, b => 69101 } };
+ $W->write_file($new_data, $fn);
+
+ is_deeply(
+ $R->read_file($fn),
+ $new_data,
+ "round-trip data->file->data, clobbering file",
+ );
+
+ chmod 0444, $fn;
+
+ if (-w $fn) {
+ chmod 0666, $fh;
+ skip "chmoding file 0444 left it -w", 1;
+ }
+
+ eval { Config::INI::Ordered::Writer->write_file($data, $fn); };
+ like($@, qr/couldn't write/, "can't clobber an unwriteable file");
+
+ chmod 0666, $fh;
+}
+
+eval { $W->write_file($data); };
+like($@, qr/no filename/, "you can't set write to a file without a filename");
+
+eval { $W->write_file($data, 't'); };
+like($@, qr/not a plain file/, "you can't write to a file that's -e -d");
+
+eval { $W->write_string(sub { 1 }) };
+like($@, qr/can't output CODE/, "you can't write out non-ARRAY/HASH data");
+
+eval { $W->write_string({ "[=]" => { a => 1 } }) };
+is($@, '', "a stupid section header ([=]) is allowed");
+
+eval { $W->write_string({ "[\n]" => { a => 1 } }) };
+like($@, qr/illegal/, "...but an impossible to parse one is not");
+
+eval { $W->write_string({ "[foo ;bar]" => { a => 1 } }) };
+like($@, qr/illegal/, "...we also can't emit things that would be comments");
+
+eval { $W->write_string({ "[foo;bar]" => { a => 1 } }) };
+is($@, '', "...but things -almost- like comments are okay");
diff --git a/xt/release/pod-coverage.t b/xt/release/pod-coverage.t
new file mode 100644
index 0000000..c15102a
--- /dev/null
+++ b/xt/release/pod-coverage.t
@@ -0,0 +1,8 @@
+#!perl -Tw
+use strict;
+
+use Test::More;
+eval "use Test::Pod::Coverage 1.06";
+plan skip_all => "Test::Pod::Coverage 1.06 required for testing POD coverage"
+ if $@;
+all_pod_coverage_ok();
diff --git a/xt/release/pod.t b/xt/release/pod.t
new file mode 100644
index 0000000..6a159d8
--- /dev/null
+++ b/xt/release/pod.t
@@ -0,0 +1,7 @@
+#!perl -Tw
+use strict;
+
+use Test::More;
+eval "use Test::Pod 1.14";
+plan skip_all => "Test::Pod 1.14 required for testing POD" if $@;
+all_pod_files_ok();
commit 494a7c9914ee1cda193882afc7eb4fabe17d3a64
Author: Jesse Vincent <jesse at bestpractical.com>
Date: Mon Mar 2 19:15:15 2009 -0500
stub out initial implementation
diff --git a/lib/Config/INI/Ordered.pm b/lib/Config/INI/Ordered.pm
new file mode 100644
index 0000000..3b2489e
--- /dev/null
+++ b/lib/Config/INI/Ordered.pm
@@ -0,0 +1,15 @@
+use warnings;
+use strict;
+
+package Config::INI::Ordered;
+
+our $VERSION = '0.001';
+
+=head1 NAME
+
+Config::INI::Ordered - Test
+
+
+=cut
+
+1;
diff --git a/lib/Config/INI/Ordered/Reader.pm b/lib/Config/INI/Ordered/Reader.pm
new file mode 100644
index 0000000..a8a4719
--- /dev/null
+++ b/lib/Config/INI/Ordered/Reader.pm
@@ -0,0 +1,13 @@
+
+use warnings;
+use strict;
+package Config::INI::Ordered::Reader;
+use base 'Config::INI::Reader';
+
+sub can_ignore {
+ my $self = shift;
+ my $line = shift;
+
+ return $self->SUPER::can_ignore($line);
+}
+1;
diff --git a/lib/Config/INI/Ordered/Writer.pm b/lib/Config/INI/Ordered/Writer.pm
new file mode 100644
index 0000000..a5c53e2
--- /dev/null
+++ b/lib/Config/INI/Ordered/Writer.pm
@@ -0,0 +1,8 @@
+
+use warnings;
+use strict;
+package Config::INI::Ordered::Writer;
+use base 'Config::INI::Writer';
+
+
+1;
-----------------------------------------------------------------------
More information about the Bps-public-commit
mailing list