ad1 SYNPOSIS
A set of programs for creating, manipulating, and outputing a stream of
Records, or JSON hashes. Inspired by Monad.
=head1 DESCRIPTION
The recs system consists of 3 basic sets of scri
cripts is JSON hashes separated by new
lines. If you wish to write your own recs script in your own language, just
get a JSON parser and you should be good to go. The recs scripts use
JSON::Syck, a
ordStream::Operation::fromjsonarray;
our $VERSION = "4.0.25";
use strict;
use warnings;
use base qw(App::RecordStream::Operation);
use App::RecordStream::Record;
use JSON::MaybeXS;
sub init {
$this->{'EXTRA_ARGS'} = $args;
$this->{'FIELDS'} = \@fields;
$this->{'JSON'} = JSON->new();
}
sub wants_input {
return 0;
}
sub stream_done {
my ($this) = @_;
my
is, $fh) = @_;
my $json = $this->{'JSON'};
my $fields = $this->{'FIELDS'};
my $has_fields = scalar @$fields;
my $contents = do { local $/; <$fh> };
my @arrays = $json->incr_parse($content
char json_bc[] =
"\102\103\107\110\001\020\000\000\020\000\000\000\023\004\211\214\001\124\250\210"
"\010\100\105\106\001\102\144\204\034\040\104\210\314\004\201\042\043\200\311\231"
"\040\140\144\00
austed
=back
=cut
our $VERSION = "3.4";
use strict;
use warnings;
use IO::String;
use JSON qw(decode_json);
use App::RecordStream::Record;
require App::RecordStream::Operation;
my $ONE_OF = [qw
->call_next_record();
}
# Direct bless done in the name of performance
my $record = decode_json($line);
bless $record, 'App::RecordStream::Record';
return $record;
}
sub call_next_record
' => [ 'fing', 'fang', 'foom' ],
}
);
my $json = '{"foo":"bar","zoo":{"blah":"biz","far":["fing","fang","foom"]}}';
my $handle = IO::String->new($json);
ok(my $stream = App::RecordStream::InputS
Stream::InputStream->new(STRING => $json), "String Initialize");
is_deeply($string_stream->get_record(), $hash, 'String Basic Input');
my $multiple = "$json\n$json\n";
ok(my $multiple_stream = App::
pp::RecordStream::OptionalRequire::optional_use(qw(JSON decode_json));
is($loaded, 1, 'Test external module with extra args');
my $hash = decode_json('{"foo": "bar"}');
is($hash->{'foo'}, 'bar', "Tes
head1 NAME
recs-fromps
=head1 recs-fromps --help-all
Usage: recs-fromps <args>
Prints out JSON records converted from the process table.
--keys <fields> Fields to output. Ma
onsible for knowing the conversion from in-memory
records to record stream wire format (currently JSON).
=head1 SYNOPSIS
use App::RecordStream::OutputStream;
my $string = App::RecordStream:
warnings;
use JSON;
my $json = JSON::XS->new();
$json->allow_nonref(1);
$json->allow_blessed(1);
$json->convert_blessed(1);
sub hashref_string {
my $record = shift;
return $json->encode($recor
art.
Recs, or RecordStream is a collection of scripts that facilitates the parsing
of files into JSON records and the transformation of those records. Many common
UNIX programs like grep, sort, and u
eral
the tools fall into three categories: those that produce JSON records, those
that operate on JSON records, and those that convert JSON records into output.
A typical use of recs will consist of o
nd one of the third type. To begin using recs, you'll have to
decide on how to get your data into JSON. There are several scripts available
to do this, one of the most powerful of which is recs-frommu
using GD::Graph.
Args:
--key|-k|--key <keyspec> Specify keys that correlate to keys in JSON data
--option|-o option=val Specify custom command for GD::Graph
--label-x <val>
$this) = @_;
return %$this;
}
sub as_hashref
{
my ($this) = @_;
return {%$this};
}
sub TO_JSON {
my ($this) = @_;
return $this->as_hashref();
}
sub has_key_spec {
my ($this, $spec) = @_
shift;
my $options = [
['key|-k|--key <keyspec>', 'Specify keys that correlate to keys in JSON data'],
['option|-o option=val', 'Specify custom command for GD::Graph'],
['label-x <val>
ct;
use warnings;
use base qw(App::RecordStream::Operation);
use MongoDB;
use Data::Dumper;
use JSON::PP;
sub init {
my $this = shift;
my $args = shift;
my ($host, $user, $pass, $db_name, $q
ssword'} = $pass if defined $pass;
# This will come closer to allowing mongo-hq style json
my $json = JSON::PP->new()
->allow_barekey() # Allow {navItem:[]} instead of {'navItem':[]}
->al
ME'} = $db_name;
$this->{'COLLECTION'} = $collection;
$this->{'QUERY'} = $json->decode($query);
}
sub wants_input {
return 0;
}
sub stream_done {
my $this = shift;
my
art.
Recs, or RecordStream is a collection of scripts that facilitates the parsing
of files into JSON records and the transformation of those records. Many common
UNIX programs like grep, sort, and u
eral
the tools fall into three categories: those that produce JSON records, those
that operate on JSON records, and those that convert JSON records into output.
A typical use of recs will consist of o
nd one of the third type. To begin using recs, you'll have to
decide on how to get your data into JSON. There are several scripts available
to do this, one of the most powerful of which is recs-frommu
use strict;
use warnings;
use utf8;
package App::RecordStream::Operation::tojsonarray;
use base qw(App::RecordStream::Operation);
sub init {
my $this = shift;
my $args = shift;
$this->parse_op
return <<USAGE;
Usage: recs tojsonarray [files]
__FORMAT_TEXT__
This command outputs the record stream as a single JSON array. It
complements the fromjsonarray command.
__FORMAT_TEXT__
Examples
# Save the record stream to a file suitable for loading by any JSON parser
... | recs tojsonarray > recs.json
USAGE
}
1;
use strict;
use warnings;
use Test::More;
use File::Basename 'basename';
use JSON::MaybeXS 'decode_json';
use IPC::Open2;
my ($recs) = grep { -e } map { "$_/recs" }
"$ENV{BASE_TEST_DIR}/..", $ENV{D
st loading of both Text::CSV_PP and JSON::PP
is_deeply decode_json(fatpack_ok('fromcsv', { stdin => 'foo,bar,baz' })), { 0 => "foo", 1 => "bar", 2 => "baz" }, 'json matches';
# test operation discove
or (BaseRegistry) discovery
is fatpack_ok('collate -a count', { stdin => '{}' }), '{"count":1}', 'json matches';
# test running of external scripts, with standalone path and -- delimiter
my $script =
val {
require MongoDB;
require JSON::PP;
};
if ( $@ ) {
require Test::More;
import Test::More skip_all => 'Missing modules! (MongoDB or JSON::PP)!';
}
else {
require Test:
=head1 NAME
recs-fromjsonarray
=head1 recs-fromjsonarray --help-all
Usage: recs-fromjsonarray <args> [<files>]
Import JSON objects from within a JSON array.
Arguments:
--key|k <keys>
s_string($options);
return <<USAGE;
Usage: recs-fromps <args>
__FORMAT_TEXT__
Prints out JSON records converted from the process table.
__FORMAT_TEXT__
$args_string
Default fields:
__
package App::RecordStream::Stream::Base;
use JSON qw(decode_json);
use App::RecordStream::Record;
use App::RecordStream::OutputStream;
sub new
{
my $class = shift;
my $this =
{
};
bless
$line);
}
sub accept_line
{
my $this = shift;
my $line = shift;
my $record = App::RecordStream::Record->new(decode_json($line));
return $this->accept_record($record);
}
sub finish
{
}
1;