This is an automated email from the git hooks/post-receive script. js pushed a commit to branch master in repository libcatmandu-perl.
commit fa8cbfc67eda0bbc47d97b02ed57c0c9c5193028 Author: Nicolas Steenlant <nicolas.steenl...@ugent.be> Date: Tue Jan 5 13:44:45 2016 +0100 line delimited JSON no longer the default --- lib/Catmandu/Cmd/config.pm | 2 +- lib/Catmandu/Exporter/JSON.pm | 44 ++++++++------ lib/Catmandu/Fix/Bind/hashmap.pm | 12 ++-- lib/Catmandu/Importer/JSON.pm | 39 +++++++------ t/Catmandu-Cmd-config.t | 4 +- t/Catmandu-Cmd-convert.t | 8 +-- t/Catmandu-Cmd-data.t | 69 ++++++++++++---------- t/Catmandu-Cmd-export.t | 10 ++-- t/Catmandu-Exporter-JSON.t | 6 +- t/Catmandu-Exporter-Multi.t | 4 +- t/Catmandu-Fix-Bind-hashmap.t | 12 ++-- t/Catmandu-Fix-Bind-importer.t | 8 +-- t/Catmandu-Importer-JSON.t | 22 ++++++- t/Catmandu-Interactive.t | 122 +++++++++++++++++++++++---------------- t/run.fix | 4 +- 15 files changed, 213 insertions(+), 153 deletions(-) diff --git a/lib/Catmandu/Cmd/config.pm b/lib/Catmandu/Cmd/config.pm index 7017aea..00cbc38 100644 --- a/lib/Catmandu/Cmd/config.pm +++ b/lib/Catmandu/Cmd/config.pm @@ -39,7 +39,7 @@ sub command { if (@$into_args || %$into_opts) { $into = Catmandu->exporter($into_args->[0], $into_opts); } else { - $into = Catmandu->exporter('JSON', pretty => 1); + $into = Catmandu->exporter('JSON', pretty => 1, array => 0); } $into->add(defined $path ? diff --git a/lib/Catmandu/Exporter/JSON.pm b/lib/Catmandu/Exporter/JSON.pm index 8abb5e1..5929fcc 100644 --- a/lib/Catmandu/Exporter/JSON.pm +++ b/lib/Catmandu/Exporter/JSON.pm @@ -11,23 +11,24 @@ use namespace::clean; with 'Catmandu::Exporter'; -has pretty => (is => 'ro', alias => 'multiline', default => sub { 0 }); -has indent => (is => 'ro', default => sub { 0 }); -has space_before => (is => 'ro', default => sub { 0 }); -has space_after => (is => 'ro', default => sub { 0 }); -has canonical => (is => 'ro', default => sub { 0 }); -has array => (is => 'ro', default => sub { 0 }); -has json => (is => 'ro', lazy => 1, builder => '_build_json'); +has line_delimited => (is => 'ro', default => sub { 0 }); +has array => (is => 'ro', default => sub { 1 }); +has pretty => (is => 'ro', default => sub { 0 }); +has indent => (is => 'ro', default => sub { 0 }); +has space_before => (is => 'ro', default => sub { 0 }); +has space_after => (is => 'ro', default => sub { 0 }); +has canonical => (is => 'ro', default => sub { 0 }); +has json => (is => 'lazy'); sub _build_json { my ($self) = @_; JSON::XS->new ->utf8(0) ->allow_nonref - ->pretty($self->pretty) - ->indent($self->pretty || $self->indent) - ->space_before($self->pretty || $self->space_before) - ->space_after($self->pretty || $self->space_after) + ->pretty($self->line_delimited ? 0 : $self->pretty) + ->indent($self->line_delimited ? 0 : $self->pretty || $self->indent) + ->space_before($self->line_delimited ? 0 : $self->pretty || $self->space_before) + ->space_after($self->line_delimited ? 0 : $self->pretty || $self->space_after) ->canonical($self->canonical); } @@ -35,6 +36,12 @@ sub add { my ($self, $data) = @_; my $fh = $self->fh; my $json = $self->json->encode($data); + if ($self->line_delimited) { + print $fh $json; + print $fh "\n"; + return; + } + if ($self->pretty) { chomp $json; } @@ -45,16 +52,13 @@ sub add { } else { print $fh "["; } - print $fh $json; - } else { - print $fh $json; - print $fh "\n"; } + print $fh $json; } sub commit { my ($self, $data) = @_; - if ($self->array) { + if (!$self->line_delimited && $self->array) { my $fh = $self->fh; unless ($self->count) { print $fh "["; @@ -124,8 +128,6 @@ Binmode of the output stream C<fh>. Set to "C<:utf8>" by default. =item pretty -=item multiline - Pretty-print JSON =item indent @@ -140,7 +142,11 @@ L<JSON> serialization options =item array -Seralize items as one JSON array instead of concatenated JSON objects +Structure the data as a JSON array. Default is C<1>. + +=item line_delimited + +Export objects as newline delimited JSON. Default is C<0>. The C<array>, C<pretty>, C<indent>, C<space_before> and C<space_after> options will be ignored if C<line_delimited> is C<1>. =back diff --git a/lib/Catmandu/Fix/Bind/hashmap.pm b/lib/Catmandu/Fix/Bind/hashmap.pm index 9667da9..a15e841 100644 --- a/lib/Catmandu/Fix/Bind/hashmap.pm +++ b/lib/Catmandu/Fix/Bind/hashmap.pm @@ -11,13 +11,13 @@ use Catmandu::Fix::Has; with 'Catmandu::Fix::Bind'; -has exporter => (fix_opt => 1 , default => sub { 'JSON' }); +has exporter => (fix_opt => 1); has store => (fix_opt => 1); has uniq => (fix_opt => 1 , default => sub { 0 }); has count => (fix_opt => 1); has join => (fix_opt => 1); has extra_args => (fix_opt => 'collect'); -has flag => (is => 'rw' , default => sub { 0 }); +has flag => (is => 'rw', default => sub { 0 }); has hash => (is => 'lazy'); sub _build_hash { @@ -33,7 +33,7 @@ sub add_to_hash { $self->hash->{$key}->{$val} = 1; } else { - push @{$self->hash->{$key}} , $val; + push @{$self->hash->{$key}}, $val; } } @@ -83,11 +83,13 @@ sub DESTROY { if ($self->store) { $e = Catmandu->store($self->store, %$args); } - else { + elsif ($self->exporter) { $e = Catmandu->exporter($self->exporter, %$args); + } else { + $e = Catmandu->exporter('JSON', line_delimited => 1); } - my $sorter = $self->count ? + my $sorter = $self->count ? sub { $h->{$b} <=> $h->{$a} } : sub { $a cmp $b }; diff --git a/lib/Catmandu/Importer/JSON.pm b/lib/Catmandu/Importer/JSON.pm index ceaa045..e8623c9 100644 --- a/lib/Catmandu/Importer/JSON.pm +++ b/lib/Catmandu/Importer/JSON.pm @@ -10,21 +10,32 @@ use namespace::clean; with 'Catmandu::Importer'; -has json => (is => 'ro', lazy => 1, builder => '_build_json'); -has multiline => (is => 'ro', default => sub { 0 }); -has array => (is => 'ro', default => sub { 0 }); +has line_delimited => (is => 'ro', default => sub { 0 }); +has json => (is => 'lazy'); sub _build_json { my ($self) = @_; JSON::XS->new->utf8($self->encoding eq ':raw'); } -sub default_encoding { ':raw' } +sub _build_encoding { ':raw' } sub generator { my ($self) = @_; - $self->multiline || $self->array ? sub { + if ($self->line_delimited) { + return sub { + state $json = $self->json; + state $fh = $self->fh; + if (defined(my $line = <$fh>)) { + return $json->decode($line); + } + return; + }; + } + + # switch to slower incremental parser + sub { state $json = $self->json; state $fh = $self->fh; @@ -51,13 +62,6 @@ sub generator { return; - } : sub { - state $json = $self->json; - state $fh = $self->fh; - if (defined(my $line = <$fh>)) { - return $json->decode($line); - } - return; }; } @@ -82,15 +86,14 @@ Catmandu::Importer::JSON - Package that imports JSON data # ... }); -The defaults assume a newline delimited JSON file: + +The parser is quite liberal in the input is accepts. You can use the +C<line_delimited> option to parse newline delimited JSON faster: { "recordno": 1, "name": "Alpha" } { "recordno": 2, "name": "Beta" } { "recordno": 3, "name": "Gamma" } -Use the C<multiline> or C<array> options to parse pretty-printed JSON or JSON -arrays. - =head1 CONFIGURATION =over @@ -115,9 +118,9 @@ An ARRAY of one or more fixes or file scripts to be applied to imported items. =item multiline -=item array +=item line_delimited -Read JSON with line-breaks or a JSON array instead of line-delimited JSON +Read line-delimited JSON with a faster, non-incremental parser. =back diff --git a/t/Catmandu-Cmd-config.t b/t/Catmandu-Cmd-config.t index 7d21816..64cd1a4 100644 --- a/t/Catmandu-Cmd-config.t +++ b/t/Catmandu-Cmd-config.t @@ -20,7 +20,7 @@ my $result = test_app(qq|Catmandu::CLI| => [ qw(config to JSON) ]); my $perl = decode_json($result->stdout); ok $perl, 'got JSON'; -is $perl->{importer}->{default}->{package} , 'YAML' , 'got data'; +is $perl->[0]->{importer}{default}{package} , 'YAML' , 'got data'; is $result->error, undef, 'threw no exceptions' ; is $result->stderr, '', 'nothing sent to sderr' ; @@ -30,4 +30,4 @@ like $result->stdout , qr/"YAML"/ , 'got data'; is $result->error, undef, 'threw no exceptions' ; is $result->stderr, '', 'nothing sent to sderr' ; -done_testing 9; +done_testing; diff --git a/t/Catmandu-Cmd-convert.t b/t/Catmandu-Cmd-convert.t index 08b082d..fc6dc05 100644 --- a/t/Catmandu-Cmd-convert.t +++ b/t/Catmandu-Cmd-convert.t @@ -21,10 +21,10 @@ my $result = test_app(qq|Catmandu::CLI| => [ qw(convert -v YAML --file t/catmand my $perl = decode_json($result->stdout); ok $perl, 'got JSON'; -is $perl->{importer}->{default}->{package} , 'YAML' , 'got data'; -is $result->error, undef, 'threw no exceptions' ; -# Next test can fail on buggy Perl installations -##is $result->stderr, '', 'nothing sent to sderr' ; +is $perl->[0]->{importer}{default}{package}, 'YAML', 'got data'; +is $result->error, undef, 'threw no exceptions'; +# next test can fail on buggy Perl installations +#is $result->stderr, '', 'nothing sent to sderr'; $result = test_app(qq|Catmandu::CLI| => ['convert', '-v', '--start=2' ,'--total=1', 'CSV', '--file', 't/planets.csv', 'to', 'CSV', '--header', '0', '--fields', 'english,latin']); is $result->stdout, "Moon,Luna\n", 'start and limit' ; diff --git a/t/Catmandu-Cmd-data.t b/t/Catmandu-Cmd-data.t index 2d076e7..739eb9b 100644 --- a/t/Catmandu-Cmd-data.t +++ b/t/Catmandu-Cmd-data.t @@ -18,50 +18,57 @@ require_ok $pkg; use Catmandu::CLI; { - my $result = test_app(qq|Catmandu::CLI| => [ - qw(data --from-importer YAML --from-file t/catmandu.yml --into-exporter JSON) - ]); + my $result = test_app(qq|Catmandu::CLI| => [ + qw(data --from-importer YAML --from-file t/catmandu.yml --into-exporter JSON) + ]); - my $perl = decode_json($result->stdout); + my $perl = decode_json($result->stdout); - ok $perl, 'got JSON'; - is $perl->{importer}->{default}->{package} , 'YAML' , 'got data'; - is $result->error, undef, 'threw no exceptions' ; + ok $perl, 'got JSON'; + is $perl->[0]->{importer}{default}{package}, 'YAML', 'got data'; + is $result->error, undef, 'threw no exceptions' ; } { - my $result = test_app(qq|Catmandu::CLI| => [ - qw(data --from-store test --from-bag data --into-exporter JSON --limit 1 --fix t/myfixes.fix) - ]); - - my @lines = split(/\n/,$result->stdout); - - ok @lines == 1 , 'test limit'; - - my $perl = decode_json($lines[0]); - - ok $perl, 'got JSON'; - is $perl->{value} , 'Sol' , 'got data'; - is $perl->{utf8_name} , 'ვეპხის ტყაოსანი შოთა რუსთაველი' , 'got utf8 data'; - is $result->error, undef, 'threw no exceptions' ; - + my $result = test_app(qq|Catmandu::CLI| => [ + qw( + data + --from-store test + --from-bag data + --into-exporter JSON + --into-line-delimited 1 + --limit 1 + --fix t/myfixes.fix + ) + ]); + + my @lines = split(/\n/, $result->stdout); + + ok @lines == 1, 'test limit'; + + my $perl = decode_json($lines[0]); + + ok $perl, 'got JSON'; + is $perl->{value}, 'Sol', 'got data'; + is $perl->{utf8_name}, 'ვეპხის ტყაოსანი შოთა რუსთაველი', 'got utf8 data'; + is $result->error, undef, 'threw no exceptions'; } { - my $result = test_app(qq|Catmandu::CLI| => [ qw(delete test) ]); + my $result = test_app(qq|Catmandu::CLI| => [ qw(delete test) ]); - is $result->stdout, "" , 'got data'; - is $result->error, undef, 'threw no exceptions' ; + is $result->stdout, "" , 'got data'; + is $result->error, undef, 'threw no exceptions'; } { - my $result = test_app(qq|Catmandu::CLI| => [ - qw(data -v --from-importer CSV --from-file t/planets.csv --into-store Hash --into-bag data) - ]); + my $result = test_app(qq|Catmandu::CLI| => [ + qw(data -v --from-importer CSV --from-file t/planets.csv --into-store Hash --into-bag data) + ]); - like $result->stderr, qr/added 4 objects/, 'imported 4 objects' ; - is $result->error, undef, 'threw no exceptions' ; + like $result->stderr, qr/added 4 objects/, 'imported 4 objects'; + is $result->error, undef, 'threw no exceptions'; } -done_testing 14; +done_testing; diff --git a/t/Catmandu-Cmd-export.t b/t/Catmandu-Cmd-export.t index add6780..633ff80 100644 --- a/t/Catmandu-Cmd-export.t +++ b/t/Catmandu-Cmd-export.t @@ -17,9 +17,9 @@ require_ok $pkg; use Catmandu::CLI; -my $result = test_app(qq|Catmandu::CLI| => [ qw(export -v test to JSON --fix t/myfixes.fix --total 1) ]); +my $result = test_app(qq|Catmandu::CLI| => [ qw(export -v test to JSON --line-delimited 1 --fix t/myfixes.fix --total 1) ]); -my @lines = split(/\n/,$result->stdout); +my @lines = split(/\n/, $result->stdout); ok @lines == 1 , 'test total'; @@ -28,9 +28,9 @@ my $perl = decode_json($lines[0]); ok $perl, 'got JSON'; is $perl->{value} , 'Sol' , 'got data'; is $perl->{utf8_name} , 'ვეპხის ტყაოსანი შოთა რუსთაველი' , 'got utf8 data'; -is $result->error, undef, 'threw no exceptions' ; +is $result->error, undef, 'threw no exceptions'; -## Next test can fail on buggy Perl installations -#is $result->stderr, '', 'nothing sent to sderr' ; +# next test can fail on buggy Perl installations +#is $result->stderr, '', 'nothing sent to sderr'; done_testing; diff --git a/t/Catmandu-Exporter-JSON.t b/t/Catmandu-Exporter-JSON.t index cdc5c52..5f0082f 100644 --- a/t/Catmandu-Exporter-JSON.t +++ b/t/Catmandu-Exporter-JSON.t @@ -16,7 +16,7 @@ require_ok $pkg; my $data = [{'a' => 'moose'}, {'a' => 'pony'}, {'a' => 'shrimp'}]; my $file = ""; -my $exporter = $pkg->new(file => \$file); +my $exporter = $pkg->new(file => \$file, line_delimited => 1); isa_ok $exporter, $pkg; @@ -27,8 +27,8 @@ is_deeply $data, [ map { JSON::XS::decode_json($_) } split /[\r\n]+/, $file ]; is($exporter->count, 3, "Count ok"); $file = ""; -Catmandu::Exporter::JSON->new( file => \$file, canonical => 1 ) +Catmandu::Exporter::JSON->new( file => \$file, line_delimited => 1, canonical => 1 ) ->add( { map { chr(ord('z')-$_) => $_ } (0..25) } ); is_deeply [ $file =~ /(\d+)/g ], [ map { "".(25-$_) } (0..25) ], 'canonical'; -done_testing 6; +done_testing; diff --git a/t/Catmandu-Exporter-Multi.t b/t/Catmandu-Exporter-Multi.t index 13047ad..a2a5854 100644 --- a/t/Catmandu-Exporter-Multi.t +++ b/t/Catmandu-Exporter-Multi.t @@ -17,8 +17,8 @@ require_ok $pkg; my $data = [{'a' => 'moose'}, {'a' => 'pony'}, {'a' => 'shrimp'}]; my $file1 = ""; my $file2 = ""; -my $exporter1 = Catmandu::Exporter::JSON->new(file => \$file1); -my $exporter2 = Catmandu::Exporter::JSON->new(file => \$file2); +my $exporter1 = Catmandu::Exporter::JSON->new(file => \$file1, line_delimited => 1); +my $exporter2 = Catmandu::Exporter::JSON->new(file => \$file2, line_delimited => 1); my $exporter = $pkg->new(exporters => [ $exporter1, diff --git a/t/Catmandu-Fix-Bind-hashmap.t b/t/Catmandu-Fix-Bind-hashmap.t index d58d621..4625aa1 100644 --- a/t/Catmandu-Fix-Bind-hashmap.t +++ b/t/Catmandu-Fix-Bind-hashmap.t @@ -40,7 +40,7 @@ is_deeply $fixer->fix({foo => 'bar'}), {foo => 'bar'} , 'testing zero fix functi $fixes =<<EOF; do hashmap() unless exists(foo) - add_field(foo,bar) + add_field(foo,bar) end end EOF @@ -52,7 +52,7 @@ is_deeply $fixer->fix({}), {foo => 'bar'} , 'testing unless'; $fixes =<<EOF; do hashmap() if exists(foo) - add_field(foo2,bar) + add_field(foo2,bar) end end EOF @@ -101,7 +101,7 @@ is_deeply $fixer->fix({foo => 'bar'}), {foo => 'bar', before => 'ok', inside => { my ($stdout, $stderr, $exit) = capture { $fixes =<<EOF; - do hashmap(exporter => CSV, join => ',') + do hashmap(exporter: CSV, join: ',') do identity() copy_field(isbn,key) copy_field(_id,value) @@ -129,7 +129,7 @@ EOF { my ($stdout, $stderr, $exit) = capture { $fixes =<<EOF; - do hashmap(exporter => YAML, uniq:1) + do hashmap(exporter: YAML, uniq: 1) do identity() copy_field(isbn,key) copy_field(_id,value) @@ -165,7 +165,7 @@ EOF { my ($stdout, $stderr, $exit) = capture { $fixes =<<EOF; - do hashmap(exporter => CSV, count: 1) + do hashmap(exporter: CSV, count: 1) do identity() copy_field(isbn,key) copy_field(_id,value) @@ -190,4 +190,4 @@ EOF is $stdout , $exp , 'grouping isbn count'; } -done_testing 13; \ No newline at end of file +done_testing 13; diff --git a/t/Catmandu-Fix-Bind-importer.t b/t/Catmandu-Fix-Bind-importer.t index a3f65a6..a46cc56 100644 --- a/t/Catmandu-Fix-Bind-importer.t +++ b/t/Catmandu-Fix-Bind-importer.t @@ -20,7 +20,7 @@ require_ok $pkg; $fixer->fix({}); }; - is $stdout, qq|{"n":0}\n| , 'fixed ok'; + is $stdout, qq|[{"n":0}]\n| , 'fixed ok'; } { @@ -29,7 +29,7 @@ require_ok $pkg; $fixer->fix({}); }; - is $stdout, qq|| , 'fixed ok'; + is $stdout, qq||, 'fixed ok'; } { @@ -38,7 +38,7 @@ require_ok $pkg; $fixer->fix({}); }; - is $stdout, qq|| , 'fixed ok'; + is $stdout, qq||, 'fixed ok'; } -done_testing 5; \ No newline at end of file +done_testing; diff --git a/t/Catmandu-Importer-JSON.t b/t/Catmandu-Importer-JSON.t index 3fd0bae..9ef84bc 100644 --- a/t/Catmandu-Importer-JSON.t +++ b/t/Catmandu-Importer-JSON.t @@ -28,4 +28,24 @@ isa_ok $importer, $pkg; is_deeply $importer->to_array, $data; -done_testing 4; +$json = <<EOF; +[ + {"name":"Patrick","age":"39"}, + {"name":"Nicolas","age":"34"} +] +EOF + +$importer = $pkg->new(file => \$json); + +is_deeply $importer->to_array, $data; + +$json = <<EOF; + {"name":"Patrick","age":"39"}, + {"name":"Nicolas","age":"34"} +EOF + +$importer = $pkg->new(file => \$json); + +is_deeply $importer->to_array, $data; + +done_testing; diff --git a/t/Catmandu-Interactive.t b/t/Catmandu-Interactive.t index 9da2691..ff67e64 100644 --- a/t/Catmandu-Interactive.t +++ b/t/Catmandu-Interactive.t @@ -14,85 +14,107 @@ BEGIN { require_ok $pkg; { - my $cmd = "\\q\n"; - my $res = ""; - my $in = Catmandu::Util::io \$cmd, mode => 'r'; - my $out = Catmandu::Util::io \$res, mode => 'w'; + my $cmd = "\\q\n"; + my $res = ""; + my $in = Catmandu::Util::io \$cmd, mode => 'r'; + my $out = Catmandu::Util::io \$res, mode => 'w'; - my $app = Catmandu::Interactive->new(in => $in, out => $out, silent => 1); + my $app = Catmandu::Interactive->new(in => $in, out => $out, silent => 1); - $app->run(); + $app->run(); - is $res , "", 'can execute \q'; + is $res , "", 'can execute \q'; - $in->close(); - $out->close(); + $in->close(); + $out->close(); } { - my $cmd = "add_field(hello,world)\n"; - my $res = ""; - my $in = Catmandu::Util::io \$cmd, mode => 'r'; - my $out = Catmandu::Util::io \$res, mode => 'w'; + my $cmd = "add_field(hello,world)\n"; + my $res = ""; + my $in = Catmandu::Util::io \$cmd, mode => 'r'; + my $out = Catmandu::Util::io \$res, mode => 'w'; - my $app = Catmandu::Interactive->new(in => $in, out => $out, silent => 1, exporter => 'JSON'); + my $app = Catmandu::Interactive->new( + in => $in, + out => $out, + silent => 1, + exporter => 'JSON', + exporter_args => {line_delimited => 1}, + ); - $app->run(); + $app->run(); - is $res , "{\"hello\":\"world\"}\n", 'can execute hello world'; + is $res , "{\"hello\":\"world\"}\n", 'can execute hello world'; - $in->close(); - $out->close(); + $in->close(); + $out->close(); } - { - my $cmd = "add_field(hello,world)\nif exists(hello)\nupcase(hello)\nend\n"; - my $res = ""; - my $in = Catmandu::Util::io \$cmd, mode => 'r'; - my $out = Catmandu::Util::io \$res, mode => 'w'; + my $cmd = "add_field(hello,world)\nif exists(hello)\nupcase(hello)\nend\n"; + my $res = ""; + my $in = Catmandu::Util::io \$cmd, mode => 'r'; + my $out = Catmandu::Util::io \$res, mode => 'w'; - - my $app = Catmandu::Interactive->new(in => $in, out => $out, silent => 1, exporter => 'JSON'); + my $app = Catmandu::Interactive->new( + in => $in, + out => $out, + silent => 1, + exporter => 'JSON', + exporter_args => {line_delimited => 1}, + ); - $app->run(); + $app->run(); - is $res , "{\"hello\":\"world\"}\n{\"hello\":\"WORLD\"}\n", 'can execute hello world with continuation'; + is $res , "{\"hello\":\"world\"}\n{\"hello\":\"WORLD\"}\n", 'can execute hello world with continuation'; - $in->close(); - $out->close(); + $in->close(); + $out->close(); } { - my $cmd = "add_field(hello,world)\n\\h\n"; - my $res = ""; - my $in = Catmandu::Util::io \$cmd, mode => 'r'; - my $out = Catmandu::Util::io \$res, mode => 'w'; + my $cmd = "add_field(hello,world)\n\\h\n"; + my $res = ""; + my $in = Catmandu::Util::io \$cmd, mode => 'r'; + my $out = Catmandu::Util::io \$res, mode => 'w'; + + my $app = Catmandu::Interactive->new( + in => $in, + out => $out, + silent => 1, + exporter => 'JSON', + exporter_args => {line_delimited => 1}, + ); - my $app = Catmandu::Interactive->new(in => $in, out => $out, silent => 1, exporter => 'JSON'); + $app->run(); - $app->run(); + is $res , "{\"hello\":\"world\"}\nadd_field(hello,world)\n", 'can execute \h'; - is $res , "{\"hello\":\"world\"}\nadd_field(hello,world)\n", 'can execute \h'; - - $in->close(); - $out->close(); + $in->close(); + $out->close(); } { - my $cmd = "add_field(hello.\$append,world)\n\\r\n"; - my $res = ""; - my $in = Catmandu::Util::io \$cmd, mode => 'r'; - my $out = Catmandu::Util::io \$res, mode => 'w'; + my $cmd = "add_field(hello.\$append,world)\n\\r\n"; + my $res = ""; + my $in = Catmandu::Util::io \$cmd, mode => 'r'; + my $out = Catmandu::Util::io \$res, mode => 'w'; + + my $app = Catmandu::Interactive->new( + in => $in, + out => $out, + silent => 1, + exporter => 'JSON', + exporter_args => {line_delimited => 1}, + ); - my $app = Catmandu::Interactive->new(in => $in, out => $out, silent => 1, exporter => 'JSON'); + $app->run(); - $app->run(); + is $res , "{\"hello\":[\"world\"]}\n{\"hello\":[\"world\",\"world\"]}\n", 'can execute \r'; - is $res , "{\"hello\":[\"world\"]}\n{\"hello\":[\"world\",\"world\"]}\n", 'can execute \r'; - - $in->close(); - $out->close(); + $in->close(); + $out->close(); } -done_testing 7; +done_testing; diff --git a/t/run.fix b/t/run.fix index 6ad72a4..518a15d 100644 --- a/t/run.fix +++ b/t/run.fix @@ -1,2 +1,2 @@ -add_field(hello,world) -add_to_exporter(.,JSON) \ No newline at end of file +add_field(hello, world) +add_to_exporter(., JSON, line_delimited: 1) -- Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-perl/packages/libcatmandu-perl.git _______________________________________________ Pkg-perl-cvs-commits mailing list Pkg-perl-cvs-commits@lists.alioth.debian.org http://lists.alioth.debian.org/cgi-bin/mailman/listinfo/pkg-perl-cvs-commits