chiark / gitweb /
Start docs
authorJeff Ober <jober@ziprecruiter.com>
Mon, 13 Jan 2020 16:26:50 +0000 (11:26 -0500)
committerJeff Ober <jober@ziprecruiter.com>
Mon, 13 Jan 2020 16:26:50 +0000 (11:26 -0500)
README.pod
cpanfile
lib/TOML/Tiny.pm
t/parity.t

index dd2287f51aa38ac9a6836b0b7b5c2637ab870946..c65dc47804c3c55e5d1a6fa9fbbbf35e1da87c33 100644 (file)
@@ -10,6 +10,61 @@ TOML::Tiny - a minimal, pure perl TOML parser and serializer
 
 version 0.01
 
+=head1 SYNOPSIS
+
+  use TOML::Tiny qw(from_toml to_toml);
+
+  binmode STDIN,  ':encoding(UTF-8)';
+  binmode STDOUT, ':encoding(UTF-8)';
+
+  # Decoding TOML
+  my $toml = do{ local $/; <STDIN> };
+  my ($parsed, $error) = from_toml $toml;
+
+  # Encoding TOML
+  say to_toml({
+    stuff => {
+      about => ['other', 'stuff'],
+    },
+  });
+
+  # Object API
+  my $parser = TOML::Tiny->new;
+  my $result = $parser->parse($toml);
+
+=head1 DESCRIPTION
+
+C<TOML::Tiny> implements a pure-perl parser and generator for the
+L<TOML|https://github.com/toml-lang/toml> data format. It conforms to TOML
+v5.0.
+
+C<TOML::Tiny> strives to maintain an interface compatible to the L<TOML> and
+L<TOML::Parser> modules, and could even be used to override C<$TOML::Parser>:
+
+  use TOML;
+  use TOML::Tiny;
+
+  local $TOML::Parser = TOML::Tiny->new(...);
+  say to_toml(...);
+
+=head1 EXPORTS
+
+=head2 from_toml
+
+=head2 to_toml
+
+=head1 OBJECT API
+
+=head2 new
+
+=head2 decode
+
+=head2 encode
+
+=head2 parse
+
+=head1 COMPATIBILITY
+
 =head1 AUTHOR
 
 Jeff Ober <sysread@fastmail.fm>
index 93bb50a81d38eeed683ec3ac491e2752e4be944e..40ed7674185ac01c0aeecd17ced4af81b86a5aa0 100644 (file)
--- a/cpanfile
+++ b/cpanfile
@@ -1,12 +1,14 @@
 requires 'perl' => '>= 5.018';
-requires 'Scalar::Util' => '>= 1.14';
-requires 'Data::Dumper' => '0';
+
+requires 'Scalar::Util'              => '>= 1.14';
+requires 'Data::Dumper'              => '0';
+requires 'DateTime::Format::RFC3339' => '0';
 
 recommends 'Types::Serialiser' => 0;
 
 on test => sub{
   requires 'Data::Dumper'              => '0';
-  requires 'DateTime::Format::ISO8601' => '0';
+  requires 'DateTime::Format::RFC3339' => '0';
   requires 'TOML::Parser'              => '0';
   requires 'Test2::V0'                 => '0';
   requires 'Test::Pod'                 => '0';
index 7ccee72ba1f618cad530a733fccd1ba9ef5c86cd..284a4ad97c6babde082625c6b0cd7d892f3b9ca7 100644 (file)
@@ -16,6 +16,9 @@ our @EXPORT = qw(
   to_toml
 );
 
+#-------------------------------------------------------------------------------
+# TOML module compatibility
+#-------------------------------------------------------------------------------
 sub from_toml {
   my $source = shift;
   my $parser = TOML::Tiny::Parser->new(@_);
@@ -32,4 +35,88 @@ sub to_toml {
   goto \&TOML::Tiny::Writer::to_toml;
 }
 
+#-------------------------------------------------------------------------------
+# Object API
+#-------------------------------------------------------------------------------
+sub new {
+  my ($class, %param) = @_;
+  bless{ parser => TOML::Tiny::Parser->new(%param) }, $class;
+}
+
+sub encode {
+  my ($self, $source) = @_;
+  $self->{parser}->parse;
+}
+
+sub decode {
+  my ($self, $data) = @_;
+  TOML::Tiny::Writer::to_toml($data);
+}
+
+#-------------------------------------------------------------------------------
+# For compatibility with TOML::from_toml's use of $TOML::Parser
+#-------------------------------------------------------------------------------
+sub parse {
+  goto \&encode;
+}
+
 1;
+
+=head1 SYNOPSIS
+
+  use TOML::Tiny qw(from_toml to_toml);
+
+  binmode STDIN,  ':encoding(UTF-8)';
+  binmode STDOUT, ':encoding(UTF-8)';
+
+  # Decoding TOML
+  my $toml = do{ local $/; <STDIN> };
+  my ($parsed, $error) = from_toml $toml;
+
+  # Encoding TOML
+  say to_toml({
+    stuff => {
+      about => ['other', 'stuff'],
+    },
+  });
+
+  # Object API
+  my $parser = TOML::Tiny->new;
+  my $result = $parser->parse($toml);
+
+
+=head1 DESCRIPTION
+
+C<TOML::Tiny> implements a pure-perl parser and generator for the
+L<TOML|https://github.com/toml-lang/toml> data format. It conforms to TOML
+v5.0.
+
+C<TOML::Tiny> strives to maintain an interface compatible to the L<TOML> and
+L<TOML::Parser> modules, and could even be used to override C<$TOML::Parser>:
+
+  use TOML;
+  use TOML::Tiny;
+
+  local $TOML::Parser = TOML::Tiny->new(...);
+  say to_toml(...);
+
+
+=head1 EXPORTS
+
+=head2 from_toml
+
+=head2 to_toml
+
+
+=head1 OBJECT API
+
+=head2 new
+
+=head2 decode
+
+=head2 encode
+
+=head2 parse
+
+
+=head1 COMPATIBILITY
index 29e00c82dc03fcb1f6335a15c5f22ea7b4a90af3..3ae9a454637e63c9eb53676a431157cc0efe5d12 100644 (file)
@@ -29,8 +29,8 @@ subtest 'TOML::Parser' => sub{
   };
 
   subtest 'inflate_datetime' => sub{
-    require DateTime::Format::ISO8601;
-    my $inflate = sub{ DateTime::Format::ISO8601->parse_datetime(shift) };
+    require DateTime::Format::RFC3339;
+    my $inflate = sub{ DateTime::Format::RFC3339->parse_datetime(shift) };
     my $exp = TOML::Parser->new(inflate_datetime => $inflate)->parse($toml);
     my $got = TOML::Tiny::Parser->new(inflate_datetime => $inflate)->parse($toml);
     is $got, $exp, 'equivalence'