App-RecordStream

 view release on metacpan or  search on metacpan

doc/recs-grep.pod  view on Meta::CPAN

       --help-all       Output all help for this script
       --help           This help screen
       --help-keyspecs  Help on keyspecs, a way to index deeply and with regexes
       --help-snippet   Help on code snippets
 
 Examples:
    Filter to records with field 'name' equal to 'John'
       recs-grep '$r->{name} eq "John"'
    Find fields without ppid = 3456
       recs-grep -v '{{ppid}} == 3456'
    Filter to records with all methods equal to 'PUT'
       recs-grep -MList::MoreUtils=all 'all { $_ eq 'PUT' } @{$r->{methods}}'
 
 Help from: --help-keyspecs:
   KEY SPECS
    A key spec is short way of specifying a field with prefixes or regular
    expressions, it may also be nested into hashes and arrays. Use a '/' to nest
    into a hash and a '#NUM' to index into an array (i.e. #2)
 
    An example is in order, take a record like this:
 
      {"biz":["a","b","c"],"foo":{"bar 1":1},"zap":"blah1"}

lib/App/RecordStream/InputStream.pm  view on Meta::CPAN

  }

  return $next->get_record();
}

sub get_filename {
  my $this = shift;

  if ( ! $this->is_done() ) {
    return $this->get_file() if ( $this->get_file() );
    return 'STRING_INPUT' if ( $this->get_string() );
    return 'STREAM_INPUT' if ( $this->get_fh() );
    return 'UNKNOWN';
  }
  elsif ( $this->get_next() ) {
    return $this->get_next()->get_filename();
  }

}

sub get_next {
  my $this = shift;

lib/App/RecordStream/Operation/grep.pm  view on Meta::CPAN

      while(my $record = shift @{$this->{'ACCUMULATOR'}}) {
        $this->push_record($record);
      }
    }

    $this->push_record($record);
    $pushed_record = 1;
    $this->{'SEEN_RECORD'} = 1;

    if ( $this->{AFTER} > 0 ) {
      $this->{'FORCED_OUTPUT'} = $this->{'AFTER'};
    }
  }
  elsif ( $this->{'BEFORE'} > 0 ) {
    push @{$this->{'ACCUMULATOR'}}, $record;

    if ( (scalar @{$this->{'ACCUMULATOR'}}) > $this->{'BEFORE'} ) {
      shift @{$this->{'ACCUMULATOR'}};
    }
  }

  if ( $this->{'FORCED_OUTPUT'} && (! $pushed_record) )  {
    $this->push_record($record);
    $this->{'FORCED_OUTPUT'}--;
  }

  return 1;
}

sub stream_done {
  my $this = shift;
  $this->_set_exit_value(1) unless ( $this->{'SEEN_RECORD'} );
}

lib/App/RecordStream/Operation/grep.pm  view on Meta::CPAN

   __FORMAT_TEXT__

Arguments:
$args_string

Examples:
   Filter to records with field 'name' equal to 'John'
      recs-grep '\$r->{name} eq "John"'
   Find fields without ppid = 3456
      recs-grep -v '{{ppid}} == 3456'
   Filter to records with all methods equal to 'PUT'
      recs-grep -MList::MoreUtils=all 'all { \$_ eq 'PUT' } \@{\$r->{methods}}'
USAGE
}

1;

lib/App/RecordStream/Operation/join.pm  view on Meta::CPAN

    or die "You must provide inputkey\n";

  my $dbkey = shift @$args
    or die "You must provide dbkey\n";

  my $dbfile = shift @$args
    or die "You must provide dbfile\n";

  $this->{'ACCUMULATE_RIGHT'} = $accumulate_right;
  $this->{'DB_KEY'}           = $dbkey;
  $this->{'INPUT_KEY'}        = $inputkey;
  $this->{'KEEP_LEFT'}        = $left || $outer;
  $this->{'KEEP_RIGHT'}       = $right || $outer;


  if ( $operation ) {
    $this->{'OPERATION'} = App::RecordStream::Executor->transform_code($operation);
  }

  $this->create_db($dbfile, $dbkey);

lib/App/RecordStream/Operation/join.pm  view on Meta::CPAN


  return join "\x1E", # ASCII record separator (RS)
          map { ${$record->guess_key_from_spec($_, 0)} }
        split /,/, $key;
}

sub accept_record {
  my $this   = shift;
  my $record = shift;

  my $value = $this->value_for_key($record, $this->{'INPUT_KEY'});

  my $db = $this->{'DB'};

  if(my $db_records = $db->{$value}) {
    foreach my $db_record (@$db_records) {
      if ($this->{'ACCUMULATE_RIGHT'}) {
        if ($this->{'OPERATION'}) {
          $this->run_expression($db_record, $record);
        }
        else {

lib/App/RecordStream/Operation/toprettyprint.pm  view on Meta::CPAN

  };

  $this->parse_options($args, $spec);

  if ( ! $key_groups->has_any_group() ) {
    $key_groups->add_groups('!.!returnrefs');
  }

  $this->{'LIMIT'}         = $limit;
  $this->{'KEY_GROUPS'}    = $key_groups;
  $this->{'NESTED_OUTPUT'} = not $do_not_nest;
  $this->{'ALIGNED'}       = $aligned =~ /^l(eft)?$/i ? 'left' : 'right'
    if defined $aligned;
};

sub accept_record {
  my $this   = shift;
  my $record = shift;

  my $limit = $this->{'LIMIT'};
  if ( defined($limit) ) {

lib/App/RecordStream/Operation/toprettyprint.pm  view on Meta::CPAN

}

sub output_value {
  my $this   = shift;
  my $prefix = shift;
  my $key    = shift;
  my $value  = shift;

  $key = $this->_format_key($key);

  if ( (ref($value) eq 'HASH') &&  $this->{'NESTED_OUTPUT'} ) {
    if ( scalar keys %$value > 0 ) {
      $this->push_line($prefix . "$key = HASH:");
      $this->output_hash($prefix . '   ', $value);
    }
    else {
      $this->push_line($prefix . "$key = EMPTY HASH");
    }
  }
  elsif ( ref($value) eq 'ARRAY' ) {
    if ( scalar @$value > 0 ) {

lib/App/RecordStream/Operation/toptable.pm  view on Meta::CPAN


  $this->{'XGROUP'} = $xgroup;
  $this->{'YGROUP'} = $ygroup;
  $this->{'VGROUP'} = $vgroup;

  $this->{'PINS_HASH'}       = \%pins;
  $this->{'SORTS'}           = \%sorts;
  $this->{'SORT_ALL_TO_END'} = $all_at_end;
  $this->{'HEADERS'}         = $headers;
  $this->{'DO_VFIELDS'}      = $do_vfields;
  $this->{'OUTPUT_RECORDS'}  = $output_records;
}

sub stream_done {
  my $this = shift;

  my %pins       = %{$this->{'PINS_HASH'}};
  my $headers    = $this->{'HEADERS'};
  my $do_vfields = $this->{'DO_VFIELDS'};

  my $xgroup     = $this->{'XGROUP'};

lib/App/RecordStream/Operation/toptable.pm  view on Meta::CPAN

  # we dump the tree out into all possible x value tuples (saved in
  # @x_value_list) and tag each node in the tree with the index in
  # @x_values_list so we can look it up later
  my @x_values_list;
  $this->_dump_node_recurse($x_values_tree, \@x_values_list, [@xfields], []);

  my @y_values_list;
  $this->_dump_node_recurse($y_values_tree, \@y_values_list, [@yfields], []);

  # Collected the data, if we're only outputing records, stop here.
  if ( $this->{'OUTPUT_RECORDS'} ) {
    $this->output_records(\@xfields, \@yfields, \@r2, \@x_values_list, \@y_values_list);
    return;
  }


  my $width_offset  = scalar @yfields;
  my $height_offset = scalar @xfields;

  if ( $headers ) {
    $width_offset  += 1;

lib/App/RecordStream/Operation/xform.pm  view on Meta::CPAN

  my $executor = $this->create_executor($expression, $post_snippet, $pre_snippet);

  $this->{'BEFORE'}   = $before;
  $this->{'AFTER'}    = $after;
  $this->{'EXECUTOR'} = $executor;

  $this->{'XFORM_REF'} = $executor->get_code_ref('xform');

  $this->{'BEFORE_ARRAY'}   = [];
  $this->{'AFTER_ARRAY'}    = [];
  $this->{'SPOOLED_INPUT'}  = [];
  $this->{'SPOOLED_OUTPUT'} = [];

  $executor->execute_method('pre_xform');
  $this->handle_spools();
}

sub create_executor {
  my $this         = shift;
  my $snippet      = shift;
  my $post_snippet = shift || '';
  my $pre_snippet  = shift || '';

lib/App/RecordStream/Operation/xform.pm  view on Meta::CPAN


  $executor->set_executor_method('push_output', sub {
      $this->push_output(@_);
    });

  return $executor;
}

sub push_input {
  my $this = shift;
  push @{$this->{'SPOOLED_INPUT'}}, @_;
}

sub push_output {
  my $this = shift;
  $this->{'SUPPRESS_R'} = 1;
  push @{$this->{'SPOOLED_OUTPUT'}}, @_;
}

sub accept_record {
  my $this   = shift;
  my $record = shift;

  my $before = $this->{'BEFORE'};
  my $after  = $this->{'AFTER'};

  if ( $before == 0 && $after == 0 ) {

lib/App/RecordStream/Operation/xform.pm  view on Meta::CPAN

    else {
      $this->push_record($value);
    }
  }

  return $this->handle_spools();
}

sub has_spooled_data {
  my $this = shift;
  return (scalar @{$this->{'SPOOLED_INPUT'}} > 0) || (scalar @{$this->{'SPOOLED_OUTPUT'}} > 0);
}

sub handle_spools {
  my $this = shift;

  $this->{'SUPPRESS_R'} = 0;

  while ( @{$this->{'SPOOLED_OUTPUT'}} ) {
    my $new_record = shift @{$this->{'SPOOLED_OUTPUT'}};
    if ( ref($new_record) eq 'HASH' ) {
      $new_record = App::RecordStream::Record->new($new_record);
    }

    $this->push_record($new_record);
  }

  while ( @{$this->{'SPOOLED_INPUT'}} ) {
    my $new_record = shift @{$this->{'SPOOLED_INPUT'}};
    if ( ref($new_record) eq 'HASH' ) {
      $new_record = App::RecordStream::Record->new($new_record);
    }

    if (! $this->accept_record($new_record) ) {
      #we've requested a stop, clear the input and return 0
      $this->{'SPOOLED_INPUT'} = [];
      return 0;
    }
  }

  return 1;
}

sub run_xform_with_record {
  my $this   = shift;
  my $record = shift;

lib/App/RecordStream/Test/OperationHelper.pm  view on Meta::CPAN

      }
    }
  }
}

sub new {
  my $class = shift;
  my %args  = @_;

  my $this = {
    INPUT     => create_stream($args{'input'}),
    OUTPUT    => create_stream($args{'output'}),
    OPERATION => $args{'operation'},
    KEEPER    => $args{'keeper'},
  };

  bless $this, $class;

  return $this;
}

sub create_stream {

lib/App/RecordStream/Test/OperationHelper.pm  view on Meta::CPAN

  }

  return App::RecordStream::InputStream->new(STRING => $input);
}

sub matches {
  my $this = shift;
  my $name = shift || 'unnamed';

  my $op     = $this->{'OPERATION'};
  my $input  = $this->{'INPUT'};

  if ( $op->wants_input() && $input ) {
    if ( ref($input) eq 'ARRAY' ) {
      my ($t, @v) = @$input;
      if ( $t eq 'LINES' ) {
        for my $l (@v) {
          if ( ! $op->accept_line($l) ) {
            last;
          }
        }

lib/App/RecordStream/Test/OperationHelper.pm  view on Meta::CPAN

      App::RecordStream::Operation::set_current_filename($input->get_filename());
      while ( my $r = $input->get_record() ) {
        if ( ! $op->accept_record($r) ) {
          last;
        }
      }
    }
  }
  $op->finish();

  my $output  = $this->{'OUTPUT'};
  my $results = $this->{'KEEPER'}->get_records();
  my $i = 0;

  #ok(0, "DIE");
  my @output_records;
  if ( $output ) {
    while ( my $record = $output->get_record() ) {
      push @output_records, $record;
    }
  }

logos/logo-small.svg  view on Meta::CPAN

         rdf:about=""><dc:format>image/svg+xml</dc:format><dc:type
           rdf:resource="http://purl.org/dc/dcmitype/StillImage" /></cc:Work></rdf:RDF></metadata><defs
     id="defs6" /><g
     transform="matrix(1.25,0,0,-1.25,0,562.8)"
     id="g10"><g
       transform="scale(0.1,0.1)"
       id="g12"><g
         transform="scale(4682.4,4502.4)"
         id="g14"><image
           id="image16"
           xlink:href="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAB58AAAdUCAYAAABwqM6aAAAABHNCSVQICAgIfAhkiAAAIABJREFUeJzs3enPZOeZ3/fvfZZan61XNimqKQ01oqCZ0YwRDGADiT0IkEQvjMR5GwTJ3+A/YBIBCeIEhpEJECAGnCAxEscxJh54RjOGI2k00mijdlGkhhqKokh2k713P2stZ7nvv...
           transform="matrix(1,0,0,-1,0,1)"
           preserveAspectRatio="none"
           height="1"
           width="1" /></g></g></g></svg>

logos/logo.svg  view on Meta::CPAN

         rdf:about=""><dc:format>image/svg+xml</dc:format><dc:type
           rdf:resource="http://purl.org/dc/dcmitype/StillImage" /></cc:Work></rdf:RDF></metadata><defs
     id="defs6" /><g
     transform="matrix(1.25,0,0,-1.25,0,562.8)"
     id="g10"><g
       transform="scale(0.1,0.1)"
       id="g12"><g
         transform="scale(4682.4,4502.4)"
         id="g14"><image
           id="image16"
           xlink:href="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAB58AAAdUCAYAAABwqM6aAAAABHNCSVQICAgIfAhkiAAAIABJREFUeJzs3enPZOeZ3/fvfZZan61XNimqKQ01oqCZ0YwRDGADiT0IkEQvjMR5GwTJ3+A/YBIBCeIEhpEJECAGnCAxEscxJh54RjOGI2k00mijdlGkhhqKokh2k713P2stZ7nvv...
           transform="matrix(1,0,0,-1,0,1)"
           preserveAspectRatio="none"
           height="1"
           width="1" /></g></g></g></svg>

tests/RecordStream/Executor.t  view on Meta::CPAN

     },
   };

   my $executor6 = App::RecordStream::Executor->new($args);
   is($executor6->execute_method('assign_input', $rec, 'bar'), 'bar', "Test named input");
   is($executor6->execute_method('assign_input', $rec2, 'foo'), 'foo', "Test named input2");
 }

 use App::RecordStream::Test::OperationHelper;

 my $output = <<OUTPUT;
{"line":1,"foo":1,"zap":"blah1","fn":"tests/files/testFile2"}
{"line":2,"foo":2,"zap":"blah2","fn":"tests/files/testFile2"}
{"line":3,"foo":3,"zap":"blah3","fn":"tests/files/testFile2"}
{"line":4,"value":"10.0.0.101","foo":"bar","element":"address","fn":"tests/files/testFile3"}
{"line":5,"value":"10.0.1.101","foo":"bar3","element":"address","fn":"tests/files/testFile3"}
{"line":6,"value":"10.0.0.102","foo":"bar3","element":"address2","fn":"tests/files/testFile3"}
{"line":7,"value":"10.0.0.103","foo":"bar","element":"address2","fn":"tests/files/testFile3"}
{"line":8,"value":"10.0.1.103","foo":"bar","element":"address2","fn":"tests/files/testFile3"}
OUTPUT

# Probably shouldn't use xform here, but I need a full context to test
# $filename and line substition
 use App::RecordStream::Operation::xform;
 App::RecordStream::Test::OperationHelper->do_match(
   'xform',
   ['{{fn}} = $filename; {{line}} = $line;', 'tests/files/testFile2', 'tests/files/testFile3'],
   '',
   $output
 );

my $input = <<INPUT;
{"a":12,"b":1}
{"a":345,"b":2}
INPUT
$output = <<OUTPUT;
{"a":12,"b":1,"reduced":12,"sum":13}
{"a":345,"b":2,"reduced":690,"sum":347}
OUTPUT
# -M with import list
App::RecordStream::Test::OperationHelper->do_match(
    'xform',
    ['-MList::Util=reduce,sum', '{{reduced}} = reduce { $a * $b } values %$r; {{sum}} = sum @{$r}{qw(a b)};'],
    $input,
    $output
);

# -m with imports is same as -M
App::RecordStream::Test::OperationHelper->do_match(
    'xform',
    ['-mList::Util=reduce,sum', '{{reduced}} = reduce { $a * $b } values %$r; {{sum}} = sum @{$r}{qw(a b)};'],
    $input,
    $output
);

# -M with default exports
$output = <<OUTPUT;
{"a":"\$VAR1 = 12;"}
{"a":"\$VAR1 = 345;"}
OUTPUT
App::RecordStream::Test::OperationHelper->do_match(
    'xform',
    ['-MData::Dumper', '{{a}} = Dumper({{a}}); chomp {{a}}; delete $r->{b};'],
    $input,
    $output
);

# -m shouldn't import default exports
$output = <<OUTPUT;
{"a":"\$VAR1 = 12;","ok":"1"}
{"a":"\$VAR1 = 345;","ok":"1"}
OUTPUT
App::RecordStream::Test::OperationHelper->do_match(
    'xform',
    ['-mData::Dumper', '{{a}} = Data::Dumper::Dumper({{a}}); chomp {{a}}; delete $r->{b}; {{ok}} = not __PACKAGE__->can("Dumper");'],
    $input,
    $output
);

tests/RecordStream/FilenameKey.t  view on Meta::CPAN


use Test::More 'no_plan';
use Data::Dumper;

BEGIN { use_ok("App::RecordStream::Operation::xform"); }
BEGIN { use_ok("App::RecordStream::Operation::fromcsv"); }

use App::RecordStream::Record;
use App::RecordStream::Test::OperationHelper;

my $output = <<OUTPUT;
{"foo":1,"zap":"blah1","fn":"tests/files/testFile2"}
{"foo":2,"zap":"blah2","fn":"tests/files/testFile2"}
{"foo":3,"zap":"blah3","fn":"tests/files/testFile2"}
{"value":"10.0.0.101","foo":"bar","element":"address","fn":"tests/files/testFile3"}
{"value":"10.0.1.101","foo":"bar3","element":"address","fn":"tests/files/testFile3"}
{"value":"10.0.0.102","foo":"bar3","element":"address2","fn":"tests/files/testFile3"}
{"value":"10.0.0.103","foo":"bar","element":"address2","fn":"tests/files/testFile3"}
{"value":"10.0.1.103","foo":"bar","element":"address2","fn":"tests/files/testFile3"}
OUTPUT

# Probably shouldn't use xform here... unclear what to use
use App::RecordStream::Operation::xform;
App::RecordStream::Test::OperationHelper->do_match(
  'xform',
  ['$foo=""', 'tests/files/testFile2', 'tests/files/testFile3', '--filename-key', 'fn'],
  '',
  $output,
);

SKIP: {
  skip "Text::CSV_PP doesn't currently handle embedded newlines + allow_loose_quotes (i.e. recs-fromcsv without --strict option)" => 1
    unless $INC{'Text/CSV_XS.pm'};

  $output = <<OUTPUT;
{"1":"two","0":"one","2":"three","fn":"tests/files/data.csv"}
{"1":"bar","0":"foo","2":"baz","fn":"tests/files/data.csv"}
{"1":"bar loo","0":"foo\\nloo","2":"baz","fn":"tests/files/data.csv"}
{"1":"two","0":"one","2":"three","fn":"tests/files/data2.csv"}
{"1":"bar","0":"foo","2":"baz","fn":"tests/files/data2.csv"}
{"1":"bar loo","0":"foo\\nloo","2":"baz","fn":"tests/files/data2.csv"}
OUTPUT

  use App::RecordStream::Operation::xform;
  App::RecordStream::Test::OperationHelper->do_match(
    'fromcsv',
    ['tests/files/data.csv', 'tests/files/data2.csv', '--filename-key', 'fn'],
    '',
    $output,
  );
}

tests/RecordStream/Operation/annotate.t  view on Meta::CPAN

use strict;
use warnings;
use Test::More;
use App::RecordStream::Test::OperationHelper;

BEGIN { use_ok( 'App::RecordStream::Operation::annotate' ) };

my $input = <<INPUT;
{"zip":["baz"],"foo":{"bar":1},"priority":0,"count":4,"state":"sleep","sum_rss":471040}
{"zip":["baz"],"foo":{"bar":1},"priority":19,"count":1,"state":"sleep","sum_rss":0}
{"zip":["baz"],"foo":{"bar":1},"priority":0,"count":5,"state":"ALL","sum_rss":5255168}
{"zip":["baz"],"foo":{"bar":1},"priority":0,"count":1,"state":"run","sum_rss":4784128}
{"zip":["baz"],"foo":{"bar":1},"priority":19,"count":3,"state":"ALL","sum_rss":8757248}
{"zip":["baz"],"foo":{"bar":1},"priority":19,"count":2,"state":"run","sum_rss":8757248}
INPUT

my $output;

$output = <<OUTPUT;
{"zap":"bar","zip":["baz"],"foo":{"bar":1},"priority":0,"count":4,"state":"sleep","sum_rss":471040}
{"zap":"bar","zip":["baz"],"foo":{"bar":1},"priority":19,"count":1,"state":"sleep","sum_rss":0}
{"zap":"bar","zip":["baz"],"foo":{"bar":1},"priority":0,"count":5,"state":"ALL","sum_rss":5255168}
{"zap":"bar","zip":["baz"],"foo":{"bar":1},"priority":0,"count":1,"state":"run","sum_rss":4784128}
{"zap":"bar","zip":["baz"],"foo":{"bar":1},"priority":19,"count":3,"state":"ALL","sum_rss":8757248}
{"zap":"bar","zip":["baz"],"foo":{"bar":1},"priority":19,"count":2,"state":"run","sum_rss":8757248}
OUTPUT

App::RecordStream::Test::OperationHelper->do_match(
  'annotate',
  [qw(--keys priority), '{{zap}} = bar'],
  $input,
  $output
);

$output = <<OUTPUT;
{"zip":["baz","bar","biz"],"foo":{"bar":1},"priority":0,"count":4,"state":"sleep","sum_rss":471040}
{"zip":["baz","bar","biz"],"foo":{"bar":1},"priority":19,"count":1,"state":"sleep","sum_rss":0}
{"zip":["baz","bar","biz"],"foo":{"bar":1},"priority":0,"count":5,"state":"ALL","sum_rss":5255168}
{"zip":["baz","bar","biz"],"foo":{"bar":1},"priority":0,"count":1,"state":"run","sum_rss":4784128}
{"zip":["baz","bar","biz"],"foo":{"bar":1},"priority":19,"count":3,"state":"ALL","sum_rss":8757248}
{"zip":["baz","bar","biz"],"foo":{"bar":1},"priority":19,"count":2,"state":"run","sum_rss":8757248}
OUTPUT

App::RecordStream::Test::OperationHelper->do_match(
  'annotate',
  [qw(--keys priority), 'push @{ {{zip}} }, qw(bar biz)'],
  $input,
  $output
);

$output = <<OUTPUT;
{"zip":["bar"],"foo":{"bar":1},"priority":0,"count":4,"state":"sleep","sum_rss":471040}
{"zip":["bar"],"foo":{"bar":1},"priority":19,"count":1,"state":"sleep","sum_rss":0}
{"zip":["bar"],"foo":{"bar":1},"priority":0,"count":5,"state":"ALL","sum_rss":5255168}
{"zip":["bar"],"foo":{"bar":1},"priority":0,"count":1,"state":"run","sum_rss":4784128}
{"zip":["bar"],"foo":{"bar":1},"priority":19,"count":3,"state":"ALL","sum_rss":8757248}
{"zip":["bar"],"foo":{"bar":1},"priority":19,"count":2,"state":"run","sum_rss":8757248}
OUTPUT

App::RecordStream::Test::OperationHelper->do_match(
  'annotate',
  [qw(--keys priority), '{{zip/#0}} = "bar"'],
  $input,
  $output
);

$output = <<OUTPUT;
{"zip":["baz"],"foo":{"bar":1,"biz":"bar"},"priority":0,"count":4,"state":"sleep","sum_rss":471040}
{"zip":["baz"],"foo":{"bar":1,"biz":"bar"},"priority":19,"count":1,"state":"sleep","sum_rss":0}
{"zip":["baz"],"foo":{"bar":1,"biz":"bar"},"priority":0,"count":5,"state":"ALL","sum_rss":5255168}
{"zip":["baz"],"foo":{"bar":1,"biz":"bar"},"priority":0,"count":1,"state":"run","sum_rss":4784128}
{"zip":["baz"],"foo":{"bar":1,"biz":"bar"},"priority":19,"count":3,"state":"ALL","sum_rss":8757248}
{"zip":["baz"],"foo":{"bar":1,"biz":"bar"},"priority":19,"count":2,"state":"run","sum_rss":8757248}
OUTPUT

App::RecordStream::Test::OperationHelper->new(
  'annotate',
  [qw(--keys priority), '{{foo/biz}} = "bar"'],
  $input,
  $output
);

# Test for GH #70:
#   $ recs xform '42' <<<'{"foo":13}'

tests/RecordStream/Operation/chain.t  view on Meta::CPAN


$op->finish();

is(join('', map { "$_\n" } @{$keeper->get_lines()}), $solution, "Output matches expectation");

# I'm not sure how to best test this, other than going at it... The forking makes it very complicated to test this in memory.
my $bin_dir = $ENV{'BASE_TEST_DIR'} . '/../bin';
my $base_dir = $ENV{'BASE_TEST_DIR'} . '/..';
open(my $outputfh, '-|', "$secure_perl_path $bin_dir/recs-chain  recs-xform '\$r->rename(\"foo\", \"zoo\");' $test_file \\| recs-sort --key zoo=-n \\| grep 3  \\| recs-totable");

my $expected = <<OUTPUT;
zoo
---
3  
OUTPUT


$/ = undef;
my $results = <$outputfh>;
is_deeply($results, $expected, "Complex chain matched output");

my $solution2 = <<SOLUTION2;
zoo
---
11 

tests/RecordStream/Operation/fromapache.t  view on Meta::CPAN

use Test::More;
use App::RecordStream::Test::OperationHelper 'fromapache';
use App::RecordStream::Test::Tester;

my $tester = App::RecordStream::Test::Tester->new('fromapache');

my $input;
my $output;

# combined
$input = <<INPUT;
192.168.0.1 - - [07/Feb/2011:10:59:59 +0900] "GET /x/i.cgi/net/0000/ HTTP/1.1" 200 9891 "-" "DoCoMo/2.0 P03B(c500;TB;W24H16)"
INPUT
$output = <<OUTPUT;
{"request":"GET /x/i.cgi/net/0000/ HTTP/1.1","bytes":"9891","proto":"HTTP/1.1","timezone":"+0900","status":"200","time":"10:59:59","date":"07/Feb/2011","rhost":"192.168.0.1","path":"/x/i.cgi/net/0000/","datetime":"07/Feb/2011:10:59:59 +0900","logname...
OUTPUT
$tester->test_input(['--fast'], $input, $output);

# combined with woothee
SKIP: {
    skip "Missing Woothee Modules!" unless eval { require Woothee };

    $output = <<OUTPUT;
{"request":"GET /x/i.cgi/net/0000/ HTTP/1.1","bytes":"9891","proto":"HTTP/1.1","timezone":"+0900","status":"200","time":"10:59:59","date":"07/Feb/2011","rhost":"192.168.0.1","path":"/x/i.cgi/net/0000/","datetime":"07/Feb/2011:10:59:59 +0900","logname...
OUTPUT
    # Woothee 1.0.0 added the os_version field; remove it for previous versions
    $output =~ s/,"os_version":"UNKNOWN"// if $Woothee::VERSION =~ /^0[.]/;
    $tester->test_input(['--fast', '--woothee'], $input, $output);
}

# common
$input = <<'INPUT';
123.160.48.6 - - [22/Mar/2014:03:12:29 +0900] "GET /?a=\"b\" HTTP/1.1" 200 739 "-" "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; .NET CLR 1.1.4322; .NET CLR 2.0.50727; .NET CLR 3.0.04506.648; .NET CLR 3.5.21022; InfoPath.1; .NET CLR 3.0.4506.21...
INPUT
$output = <<'OUTPUT';
{"request":"GET /?a=\\\"b\\\" HTTP/1.1","proto":"HTTP/1.1","bytes":"739","timezone":"+0900","date":"22/Mar/2014","time":"03:12:29","status":"200","rhost":"123.160.48.6","path":"/?a=\\\"b\\\"","datetime":"22/Mar/2014:03:12:29 +0900","logname":"-","age...
OUTPUT

# options spec
$tester->test_input([], $input, $output);
$tester->test_input(['--fast'], $input, $output);
$tester->test_input(['--fast=1'], $input, $output);
$tester->test_input(['--fast', '1'], $input, $output);
$tester->test_input(['--fast', '--verbose'], $input, $output);
$tester->test_input(['--fast', '--strict=0'], $input, $output);

$output = <<'OUTPUT';
{"request":"GET /?a=\"b\" HTTP/1.1","proto":"HTTP/1.1","bytes":"739","timezone":"+0900","time":"03:12:29","date":"22/Mar/2014","status":"200","rhost":"123.160.48.6","path":"/?a=\"b\"","datetime":"22/Mar/2014:03:12:29 +0900","logname":"-","agent":"Moz...
OUTPUT

$tester->test_input(['--strict'], $input, $output);
$tester->test_input(['--strict=1'], $input, $output);
$tester->test_input(['--strict', '1'], $input, $output);
$tester->test_input(['--fast=0', '--strict'], $input, $output);

eval {
  $tester->test_input(['--fast', '--strict'], $input, $output);
};
like $@, qr/^only one option from 'strict' or 'fast' required/;

# input is vhost. parser mode is vhost. output is vhost.
$input = <<INPUT;
example.com 192.168.0.1 - - [07/Feb/2011:10:59:59 +0900] "GET /x/i.cgi/net/0000/ HTTP/1.1" 200 9891
INPUT
$output = <<OUTPUT;
{"request":"GET /x/i.cgi/net/0000/ HTTP/1.1","bytes":"9891","proto":"HTTP/1.1","timezone":"+0900","status":"200","date":"07/Feb/2011","time":"10:59:59","rhost":"192.168.0.1","path":"/x/i.cgi/net/0000/","datetime":"07/Feb/2011:10:59:59 +0900","logname...
OUTPUT
$tester->test_input(['--strict', '["vhost_common"]'], $input, $output);

# input is vhost. parser mode is not vhost. output is nothing.
$input = <<INPUT;
example.com 192.168.0.1 - - [07/Feb/2011:10:59:59 +0900] "GET /x/i.cgi/net/0000/ HTTP/1.1" 200 9891
INPUT
$output = <<OUTPUT;
OUTPUT
$tester->test_input(['--strict', '["common"]'], $input, $output);

eval {
  $tester->test_input(['--strict', '["common"'], $input, $output);
};
like $@, qr/^eval of option strict failed\. syntax error at/;

eval {
  $tester->test_input(['--fast', '["common"'], $input, $output);
};

tests/RecordStream/Operation/fromatomfeed.t  view on Meta::CPAN

use Test::More;
use App::RecordStream::Test::OperationHelper 'fromatomfeed';
use App::RecordStream::Test::Tester;

my $output1 = <<OUTPUT;
{"dc:creator":"author1","updated":"2007-06-06T07:00:00Z","id":"http://localhost/entry1","author":{"name":"author1"},"title":"Entry 1"}
OUTPUT

my $output2 = <<OUTPUT;
{"dc:creator":"author1","updated":"2007-06-06T07:00:00Z","id":"http://localhost/entry1","author":{"name":"author1"},"title":"Entry 1"}
{"dc:creator":"author2","updated":"2007-06-06T07:00:00Z","id":"http://localhost/entry2","author":{"name":"author2"},"title":"Entry 2"}
OUTPUT

my $output3 = <<OUTPUT;
{"dc:creator":"author1","updated":"2007-06-06T07:00:00Z","id":"http://localhost/entry1","author":{"name":"author1"},"title":"Entry 1"}
{"dc:creator":"author2","updated":"2007-06-06T07:00:00Z","id":"http://localhost/entry2","author":{"name":"author2"},"title":"Entry 2"}
{"dc:creator":"author3","updated":"2007-06-06T07:00:00Z","id":"http://localhost/entry1","author":{"name":"author3"},"title":"Entry 3"}
OUTPUT

my $output4 = <<OUTPUT;
{"dc:creator":"author1","updated":"2007-06-06T07:00:00Z","id":"http://localhost/entry1","author":{"name":"author1"},"title":"Entry 1"}
{"dc:creator":"author2","updated":"2007-06-06T07:00:00Z","id":"http://localhost/entry2","author":{"name":"author2"},"title":"Entry 2"}
{"dc:creator":"author3","updated":"2007-06-06T07:00:00Z","id":"http://localhost/entry1","author":{"name":"author3"},"title":"Entry 3"}
{"dc:creator":"author4","updated":"2007-06-06T07:00:00Z","id":"http://localhost/entry4","author":{"name":"author4"},"title":"Entry 4"}
OUTPUT

my $tester = App::RecordStream::Test::Tester->new('fromatomfeed');
$tester->no_input_test([                            'file:tests/files/testFeed1'], $output4);
$tester->no_input_test([              '--nofollow', 'file:tests/files/testFeed1'], $output2);
$tester->no_input_test(['--max', '1',               'file:tests/files/testFeed1'], $output1);
$tester->no_input_test(['--max', '1', '--nofollow', 'file:tests/files/testFeed1'], $output1);
$tester->no_input_test(['--max', '2',               'file:tests/files/testFeed1'], $output2);
$tester->no_input_test(['--max', '3',               'file:tests/files/testFeed1'], $output3);
$tester->no_input_test(['--max', '3', '--nofollow', 'file:tests/files/testFeed1'], $output2);

tests/RecordStream/Operation/fromcsv.t  view on Meta::CPAN

use App::RecordStream::Test::Tester;

BEGIN { use_ok( 'App::RecordStream::Operation::fromcsv' ) };

my $tester = App::RecordStream::Test::Tester->new('fromcsv');

my $input;
my $output;
my $error;

$input = <<INPUT;
foo,bar,baz
"foo loo","bar loo", baz
INPUT
$output = <<OUTPUT;
{"1":"bar","0":"foo","2":"baz"}
{"1":"bar loo","0":"foo loo","2":"baz"}
OUTPUT
$tester->test_stdin([], $input, $output);

$input = <<INPUT;
foo,bar,baz
"foo loo","bar loo", baz
INPUT
$output = <<OUTPUT;
{"1":"bar","0":"foo","2":"baz"}
{"1":"bar loo","0":"foo loo","2":" baz"}
OUTPUT
$tester->test_stdin(['--strict'], $input, $output);

$input = <<INPUT;
one,two,three
foo,bar,baz
"foo loo","bar loo", baz
INPUT
$output = <<OUTPUT;
{"two":"bar","one":"foo","three":"baz"}
{"two":"bar loo","one":"foo loo","three":"baz"}
OUTPUT
$tester->test_stdin(['--header'], $input, $output);

$input = <<INPUT;
foo,bar,baz
"foo loo","bar loo", baz
INPUT
$output = <<OUTPUT;
{"zip":["foo", "bar", "baz"]}
{"zip":["foo loo","bar loo","baz"]}
OUTPUT
$tester->test_stdin(['--key', 'zip/#0,zip/#1,zip/#2'], $input, $output);

SKIP: {
  skip "Text::CSV_PP doesn't currently handle embedded newlines + allow_loose_quotes (i.e. recs-fromcsv without --strict option)" => 1
    unless $INC{'Text/CSV_XS.pm'};

  $input = <<INPUT;
foo,bar,baz
"foo
loo","bar loo", baz
INPUT
  $output = <<OUTPUT;
{"zip":["foo", "bar", "baz"]}
{"zip":["foo\\nloo","bar loo","baz"]}
OUTPUT
  $tester->test_stdin(['--key', 'zip/#0,zip/#1,zip/#2'], $input, $output);
}

$input = <<INPUT;
foo;bar;baz
"foo loo";"bar loo"; baz
INPUT
$output = <<OUTPUT;
{"1":"bar","0":"foo","2":"baz"}
{"1":"bar loo","0":"foo loo","2":"baz"}
OUTPUT
$tester->test_stdin(['--delim', ';'], $input, $output);

$output = <<OUTPUT;
{"static":42,"foo":"bar","baz":"bat"}
{"static":42,"red":"green","yellow":"blue"}
OUTPUT

App::RecordStream::Test::OperationHelper->do_match(
  'fromcsv',
  ['--header', '--key', 'static', 'tests/files/data3.csv', 'tests/files/data4.csv'],
  '',
  $output,
);

# Test that we error on parse fail in middle of file
$input = <<INPUT;
foo "bar" bat
baz
INPUT

ok !eval {
  $tester->test_stdin(['--strict'], $input, ''); 1;
  1;
}, "Parsing bad input makes operation fail";
$error = $@;
like $error, qr/^fromcsv: parse error:/, "Parsing bad input produces error";
like $error, qr/position \d, line 1, file NONE/, "Error contains position info"; # Text::CSV backends differ in ability to report character position

# Test that we error on parse fail on last line
$input = <<INPUT;
baz
foo "bar" bat
INPUT

ok !eval {
  $tester->test_stdin(['--strict'], $input, ''); 1;
  1;
}, "Parsing bad input makes operation fail";
$error = $@;
like $error, qr/^fromcsv: parse error:/, "Parsing bad input produces error";
like $error, qr/position \d, line 2, file NONE/, "Error contains position info"; # Text::CSV backends differ in ability to report character position

# Custom escape character
$input = <<INPUT;
"foo \\"bar\\" bat"
INPUT

$output = <<OUTPUT;
{"0":"foo \\"bar\\" bat"}
OUTPUT

$tester->test_stdin(['--strict', '--escape', '\\'], $input, $output);

done_testing;

tests/RecordStream/Operation/fromjsonarray.t  view on Meta::CPAN


use App::RecordStream::Test::Tester;

BEGIN { use_ok( 'App::RecordStream::Operation::fromjsonarray' ) };

my $tester = App::RecordStream::Test::Tester->new('fromjsonarray');

my ($input1, $input2);
my $output;

$input1 = <<'INPUT';
[{"a": 1, "foo": "bar"},{"b": 2, "a": 2},{"c": 3},{"b": 4}]
INPUT

$input2 = <<'INPUT';
[
  {
    "a": 1,
    "foo": "bar"
  },
  {"b": 2, "a": 2},
  {"c": 3},
  {"b": 4}
]
INPUT

$output = <<'OUTPUT';
{"a":1,"foo":"bar"}
{"a":2,"b":2}
{"c":3}
{"b":4}
OUTPUT
$tester->test_stdin([], $input1, $output);
$tester->test_stdin([], $input2, $output);

$output = <<'OUTPUT';
{"a":1}
{"a":2}
{"a":null}
{"a":null}
OUTPUT
$tester->test_stdin(['--key', 'a'], $input1, $output);

$output = <<'OUTPUT';
{"a":1,"b":null}
{"a":2,"b":2}
{"a":null,"b":null}
{"a":null,"b":4}
OUTPUT
$tester->test_stdin(['--key', 'a,b'], $input1, $output);

$input1 = <<'INPUT';
[{"a": [1, 2], "b": {"foo": "bar1", "baz": "biz1"}, "c": 0},
{"a": [3, 4], "b": {"foo": "bar2", "baz": "biz2"}, "c": 2},
{"c": 4, "a": ["foo", "baz"]},
{"d": 4}]
INPUT

$output = <<'OUTPUT';
{"a/#1":2,"b/foo":"bar1"}
{"a/#1":4,"b/foo":"bar2"}
{"a/#1":"baz","b/foo":null}
{"a/#1":null,"b/foo":null}
OUTPUT
$tester->test_stdin(['--key', 'a/#1', '--key', 'b/foo'], $input1, $output);

tests/RecordStream/Operation/fromkv.t  view on Meta::CPAN

use Test::More qw(no_plan);
use App::RecordStream::Test::Tester;

BEGIN { use_ok( 'App::RecordStream::Operation::fromkv' ) };

my $input;
my $output;

my $tester = App::RecordStream::Test::Tester->new('fromkv');

$input = <<INPUT;

a=1
b=2
c=3
%
d=4
e=5
f=6
%
INPUT

$output = <<OUTPUT;
{"c":"3","a":"1","b":"2"}
{"d":"4","e":"5","f":"6"}
OUTPUT

$tester->test_input(['--kv-delim', '=', '--record-delim', "%\n"], $input, $output);

$input = <<INPUT;
a=1|b=2|c=3%
d=4|e=5|f=6%
INPUT

$output = <<OUTPUT;
{"c":"3","a":"1","b":"2"}
{"d":"4","e":"5","f":"6"}
OUTPUT

$tester->test_input(['--kv-delim', '=', '--entry-delim', '|', '--record-delim', "%\n"], $input, $output);

$input = <<INPUT;
a=1|b=2|c=3\%d=4|e=5|f=6
INPUT

$output = <<OUTPUT;
{"c":"3","a":"1","b":"2"}
{"d":"4","e":"5","f":"6"}
OUTPUT

$tester->test_input(['--kv-delim', '=', '--entry-delim', '|', '--record-delim', "%"], $input, $output);

tests/RecordStream/Operation/frommultire.t  view on Meta::CPAN

use Test::More qw(no_plan);
use App::RecordStream::Test::Tester;

BEGIN { use_ok( 'App::RecordStream::Operation::frommultire' ) };

my $input;
my $output;

my $tester = App::RecordStream::Test::Tester->new('frommultire');

$input = <<INPUT;
Team: Recs
Location: 521 S Weller
Name: Keith Amling
Name: Benjamin Bernard
Team: Futurama
Location: Omicron Persei 8
Name: Matt Groening
Name: David Cohen
INPUT
$output = <<OUTPUT;
{"fname":"Keith","lname":"Amling"}
{"fname":"Benjamin","lname":"Bernard"}
{"fname":"Matt","lname":"Groening"}
{"fname":"David","lname":"Cohen"}
OUTPUT
$tester->test_input(['--re', 'fname,lname=^Name: (.*) (.*)$'], $input, $output);

$input2 = <<INPUT;
Team: Recs
Location: 521 S Weller
Name: Keith Amling
Team: Futurama
Location: Omicron Persei 8
Name: Matt Groening
INPUT
$output = <<OUTPUT;
{"Team":"Recs","Location":"521 S Weller","Name":"Keith Amling"}
{"Team":"Futurama","Location":"Omicron Persei 8","Name":"Matt Groening"}
OUTPUT
$tester->test_input(['--re', '$1=(.*): (.*)'], $input2, $output);

$input2 = <<INPUT;
foo,bar=biz,zap ZOO
foo,bar=ready,run ZAP
INPUT
$output = <<OUTPUT;
{"foo":"biz","bar":"zap","0-2":"ZOO"}
{"foo":"ready","bar":"run","0-2":"ZAP"}
OUTPUT
$tester->test_input(['--re', '$1,$2=(.*),(.*)=(.*),(.*) ([A-Z]*)'], $input2, $output);

$output = <<OUTPUT;
{"team":"Recs","loc":"521 S Weller","fname":"Keith","lname":"Amling"}
{"team":"Recs","loc":"521 S Weller","fname":"Benjamin","lname":"Bernard"}
{"team":"Futurama","loc":"Omicron Persei 8","fname":"Matt","lname":"Groening"}
{"team":"Futurama","loc":"Omicron Persei 8","fname":"David","lname":"Cohen"}
OUTPUT
$tester->test_input(['--re', 'team=^Team: (.*)$', '--re', 'loc=^Location: (.*)$', '--post', 'fname,lname=^Name: (.*) (.*)$', '--clobber', '--keep-all'], $input, $output);

$output = <<OUTPUT;
{"team":"Recs","loc":"521 S Weller","fname":"Keith","lname":"Amling"}
{"team":"Recs","fname":"Benjamin","lname":"Bernard"}
{"team":"Futurama","loc":"Omicron Persei 8","fname":"Matt","lname":"Groening"}
{"team":"Futurama","fname":"David","lname":"Cohen"}
OUTPUT
$tester->test_input(['--re', 'team=^Team: (.*)$', '--re', 'loc=^Location: (.*)$', '--post', 'fname,lname=^Name: (.*) (.*)$', '--clobber', '--keep', 'team'], $input, $output);

$input = <<INPUT;
A:A1 A2
B:B1 B2 B3
INPUT
$output = <<OUTPUT;
{"a1":"A1","0-1":"A2","1-0":"B1","1-1":"B2","1-2":"B3"}
OUTPUT
$tester->test_input(['--re', 'a1=^A:([^ ]*) ([^ ]*)$', '--re', '^B:([^ ]*) ([^ ]*) ([^ ]*)$'], $input, $output);

tests/RecordStream/Operation/fromre.t  view on Meta::CPAN

use Test::More qw(no_plan);
use App::RecordStream::Test::Tester;

BEGIN { use_ok( 'App::RecordStream::Operation::fromre' ) };

my $input;
my $output;

my $tester = App::RecordStream::Test::Tester->new('fromre');

$input = <<INPUT;
Team: Recs
Location: 521 S Weller
Name: Keith Amling
Name: Benjamin Bernard
Team: Futurama
Location: Omicron Persei 8
Name: Matt Groening
Name: David Cohen
INPUT
$output = <<OUTPUT;
{"fname":"Keith","lname":"Amling"}
{"fname":"Benjamin","lname":"Bernard"}
{"fname":"Matt","lname":"Groening"}
{"fname":"David","lname":"Cohen"}
OUTPUT
$tester->test_input(['-f', 'fname,lname', '^Name: (.*) (.*)$'], $input, $output);
$input = <<INPUT;
A:A1 A2 A3
INPUT
$output = <<OUTPUT;
{"a1":"A1","1":"A2","2":"A3"}
OUTPUT
$tester->test_input(['-f', 'a1', '^A:([^ ]*) ([^ ]*) ([^ ]*)$'], $input, $output);
$output = <<OUTPUT;
{"0":"A1","1":"A2","2":"A3"}
OUTPUT
$tester->test_input(['^A:([^ ]*) ([^ ]*) ([^ ]*)$'], $input, $output);

tests/RecordStream/Operation/fromsplit.t  view on Meta::CPAN

use Test::More qw(no_plan);
use App::RecordStream::Test::Tester;

BEGIN { use_ok( 'App::RecordStream::Operation::fromsplit' ) };

my $input;
my $output;

my $tester = App::RecordStream::Test::Tester->new('fromsplit');

$output = <<OUTPUT;
{"f1":"A1","1":"A2,2","2":"A3"}
{"f1":"B1","1":"B2","2":"B3,B4","3":"B5"}
OUTPUT

$tester->no_input_test(['-f', 'f1', '-d', ' ', 'tests/files/splitfile'], $output);

$output = <<OUTPUT;
{"0":"A1 A2","1":"2 A3"}
{"0":"B1 B2 B3","1":"B4 B5"}
OUTPUT

$tester->no_input_test([qw(tests/files/splitfile)], $output);

$output = <<OUTPUT;
{"A1 A2":"B1 B2 B3","2 A3":"B4 B5"}
OUTPUT

$tester->no_input_test(['--header', qw(tests/files/splitfile)], $output);

$input = <<INPUT;
foo bar  baz
foo bar biz
INPUT
$output = <<OUTPUT;
{"1":"bar","0":"foo","2":"","3":"baz"}
{"1":"bar","0":"foo","2":"biz"}
OUTPUT
$tester->test_input(['--strict', '--delim', ' '], $input, $output);

$output = <<OUTPUT;
{"1":"bar","0":"foo","2":"baz"}
{"1":"bar","0":"foo","2":"biz"}
OUTPUT
$tester->test_input(['--delim', '\s+'], $input, $output);

tests/RecordStream/Operation/fromxferlog.t  view on Meta::CPAN

    import Test::More qw(no_plan);
    use_ok( 'App::RecordStream::Operation::fromxferlog' );
  }
};

my $tester = App::RecordStream::Test::Tester->new('fromxferlog');

my $input;
my $output;

$input = <<INPUT;
Mon Oct  1 17:09:23 2001 0 127.0.0.1 2611 FILENAME a _ o r tmbranno ftp 0 * c
Mon Oct  1 17:09:27 2001 0 127.0.0.1 22   NAMEFILE a _ o r tmbranno ftp 0 * c
Mon Oct  1 17:09:27 2001 0 127.0.0.1 22   file with spaces in it.zip a _ o r tmbranno ftp 0 * c
Mon Oct  1 17:09:31 2001 0 127.0.0.1 7276 p1774034_11i_zhs.zip a _ o r tmbranno ftp 0 * c
INPUT
$output = <<OUTPUT;
{"file_size":"2611","remote_host":"127.0.0.1","month":"Oct","current_time":"17:09:23","special_action_flag":"_","day_name":"Mon","direction":"o","service_name":"ftp","day":"1","access_mode":"r","completion_status":"c","authenticated_user_id":"*","tra...
{"file_size":"22","remote_host":"127.0.0.1","month":"Oct","current_time":"17:09:27","special_action_flag":"_","day_name":"Mon","direction":"o","service_name":"ftp","day":"1","access_mode":"r","completion_status":"c","authenticated_user_id":"*","trans...
{"file_size":"22","remote_host":"127.0.0.1","month":"Oct","current_time":"17:09:27","special_action_flag":"_","day_name":"Mon","direction":"o","service_name":"ftp","day":"1","completion_status":"c","access_mode":"r","authenticated_user_id":"*","trans...
{"file_size":"7276","remote_host":"127.0.0.1","month":"Oct","current_time":"17:09:31","special_action_flag":"_","day_name":"Mon","direction":"o","service_name":"ftp","day":"1","access_mode":"r","completion_status":"c","authenticated_user_id":"*","tra...
OUTPUT
$tester->test_input([], $input, $output);

tests/RecordStream/Operation/generate.t  view on Meta::CPAN

use Test::More qw(no_plan);
use App::RecordStream::Test::Tester;

BEGIN { use_ok( 'App::RecordStream::Operation::generate' ) };

my $input;
my $output;

my $tester = App::RecordStream::Test::Tester->new('generate');

$input = <<INPUT;
{"title":"ernie"}
{"title":"bert"}
INPUT

$output = <<OUTPUT;
{"backpointer":{"title":"ernie"},"title2":"ernie"}
{"backpointer":{"title":"bert"},"title2":"bert"}
OUTPUT

$tester->test_input([qw(--keychain backpointer), q("echo '{\"title2\":\"$r->{title}\"}'")], $input, $output);

$output = <<OUTPUT;
{"title":"ernie"}
{"backpointer":{"title":"ernie"},"title2":"ernie"}
{"title":"bert"}
{"backpointer":{"title":"bert"},"title2":"bert"}
OUTPUT

$tester->test_input([qw(--passthrough --keychain backpointer), q("echo '{\"title2\":\"$r->{title}\"}'")], $input, $output);

tests/RecordStream/Operation/tognuplot.t  view on Meta::CPAN

1
1
2
1
1
1
2
75
58
set terminal png
set output 'TEMP_TEST_OUTPUT.png'
set title 'ct'
set style data linespoints
plot 'screen' using 1 title "ct" 
Wrote graph file: TEMP_TEST_OUTPUT.png
SOLUTION

App::RecordStream::Test::OperationHelper->test_output(
  'tognuplot',
  ['--dump-to-screen', '--key', 'ct', '--lines', '--file', 'TEMP_TEST_OUTPUT.png'],
  $stream,
  $solution,
);

unlink 'TEMP_TEST_OUTPUT.png'

tests/RecordStream/Operation/tojsonarray.t  view on Meta::CPAN

use strict;
use warnings;

use Test::More;
use App::RecordStream::Test::OperationHelper;
use App::RecordStream::Operation::tojsonarray;

my ($input, $output);

# Basic
$input = <<'INPUT';
{"a":1,"foo":"bar"}
{"a":2,"b":2}
{"c":3}
{"b":4}
INPUT

$output = <<'OUTPUT';
[{"a":1,"foo":"bar"}
,{"a":2,"b":2}
,{"c":3}
,{"b":4}
]
OUTPUT

App::RecordStream::Test::OperationHelper->test_output('tojsonarray', [], $input, $output);


# Empty
$input  = "";
$output = "[]\n";
App::RecordStream::Test::OperationHelper->test_output('tojsonarray', [], $input, $output);


tests/RecordStream/Operation/toptable.t  view on Meta::CPAN

{"priority":"10","uid":"root","ct":1}
{"priority":"10","uid":"ALL","ct":1}
{"priority":"21","uid":"rtkit","ct":1}
{"priority":"21","uid":"ALL","ct":1}
{"priority":"9","uid":"bernard","ct":1}
{"priority":"9","uid":"ALL","ct":1}
{"priority":"30","uid":"bernard","ct":2}
{"priority":"30","uid":"ALL","ct":2}
RECORDS

my $unsorted_output = <<OUTPUT;
+--------+---+----+---+----------+------+-----+------+------+-------+-----+
|        |uid|root|ALL|messagebus|syslog|avahi|daemon|colord|bernard|rtkit|
+--------+---+----+---+----------+------+-----+------+------+-------+-----+
|priority|   |    |   |          |      |     |      |      |       |     |
+--------+---+----+---+----------+------+-----+------+------+-------+-----+
|20      |   |47  |120|1         |1     |2    |1     |1     |67     |     |
+--------+---+----+---+----------+------+-----+------+------+-------+-----+
|ALL     |   |63  |140|1         |1     |2    |1     |1     |70     |1    |
+--------+---+----+---+----------+------+-----+------+------+-------+-----+
|-100    |   |1   |1  |          |      |     |      |      |       |     |

tests/RecordStream/Operation/toptable.t  view on Meta::CPAN

|39      |   |1   |1  |          |      |     |      |      |       |     |
+--------+---+----+---+----------+------+-----+------+------+-------+-----+
|10      |   |1   |1  |          |      |     |      |      |       |     |
+--------+---+----+---+----------+------+-----+------+------+-------+-----+
|21      |   |    |1  |          |      |     |      |      |       |1    |
+--------+---+----+---+----------+------+-----+------+------+-------+-----+
|9       |   |    |1  |          |      |     |      |      |1      |     |
+--------+---+----+---+----------+------+-----+------+------+-------+-----+
|30      |   |    |2  |          |      |     |      |      |2      |     |
+--------+---+----+---+----------+------+-----+------+------+-------+-----+
OUTPUT

# Test input order
App::RecordStream::Test::OperationHelper->test_output(
  'toptable',
  ['--x', 'uid', '--y', 'priority'],
  $sort_stream,
  $unsorted_output,
);

my $sorted_output = <<OUTPUT;
+--------+---+-----+-------+------+------+----------+----+-----+------+---+
|        |uid|avahi|bernard|colord|daemon|messagebus|root|rtkit|syslog|ALL|
+--------+---+-----+-------+------+------+----------+----+-----+------+---+
|priority|   |     |       |      |      |          |    |     |      |   |
+--------+---+-----+-------+------+------+----------+----+-----+------+---+
|-100    |   |     |       |      |      |          |1   |     |      |1  |
+--------+---+-----+-------+------+------+----------+----+-----+------+---+
|0       |   |     |       |      |      |          |12  |     |      |12 |
+--------+---+-----+-------+------+------+----------+----+-----+------+---+
|10      |   |     |       |      |      |          |1   |     |      |1  |

tests/RecordStream/Operation/toptable.t  view on Meta::CPAN

|25      |   |     |       |      |      |          |1   |     |      |1  |
+--------+---+-----+-------+------+------+----------+----+-----+------+---+
|30      |   |     |2      |      |      |          |    |     |      |2  |
+--------+---+-----+-------+------+------+----------+----+-----+------+---+
|39      |   |     |       |      |      |          |1   |     |      |1  |
+--------+---+-----+-------+------+------+----------+----+-----+------+---+
|9       |   |     |1      |      |      |          |    |     |      |1  |
+--------+---+-----+-------+------+------+----------+----+-----+------+---+
|ALL     |   |2    |70     |1     |1     |1         |63  |1    |1     |140|
+--------+---+-----+-------+------+------+----------+----+-----+------+---+
OUTPUT

# Test sort-to-end
App::RecordStream::Test::OperationHelper->test_output(
  'toptable',
  ['--x', 'uid', '--y', 'priority', '--sa'],
  $sort_stream,
  $sorted_output,
);

tests/RecordStream/Operation/xform.t  view on Meta::CPAN

use strict;
use warnings;
use Test::More;
use App::RecordStream::Test::OperationHelper;

BEGIN { use_ok( 'App::RecordStream::Operation::xform' ) };

my $input = <<INPUT;
{"a":"a1,a2","b":"b1"}
{"a":"a3,a4,a5","b":"b2"}
INPUT

my $output;

$output = <<OUTPUT;
{"a":"a0","b":"b1"}
{"a":"a0","b":"b2"}
OUTPUT
App::RecordStream::Test::OperationHelper->do_match(
    'xform',
    ['$r->{a} = "a0";'],
    $input,
    $output
);

$output = <<OUTPUT;
{"a":"a0","b":"b1"}
{"a":"a0","b":"b2"}
OUTPUT
App::RecordStream::Test::OperationHelper->do_match(
    'xform',
    ['$r->{a} = "a0"; [{}]'],
    $input,
    $output
);

$output = <<OUTPUT;
{}
{}
OUTPUT
App::RecordStream::Test::OperationHelper->do_match(
    'xform',
    ['$r->{a} = "a0"; $r = [{}]'],
    $input,
    $output
);

$output = <<OUTPUT;
{"a":"a1","b":"b1"}
{"a":"a2","b":"b1"}
{"a":"a3","b":"b2"}
{"a":"a4","b":"b2"}
{"a":"a5","b":"b2"}
OUTPUT
App::RecordStream::Test::OperationHelper->do_match(
    'xform',
    ['-e', '$r = [map { {%$r, "a" => $_} } split(/,/, delete($r->{"a"}))]; 1;'],
    $input,
    $output
);

$output = <<OUTPUT;
{"a":"a1,a2","b":"b1","foo":"bar"}
{"a":"a3,a4,a5","b":"b2","foo":"bar"}
OUTPUT
App::RecordStream::Test::OperationHelper->do_match(
    'xform',
    ['-E', 'tests/files/executorCode'],
    $input,
    $output
);

$output = <<OUTPUT;
{"a":"a1,a2","b":"b1","reduced":12}
{"a":"a3,a4,a5","b":"b2","reduced":690}
OUTPUT
App::RecordStream::Test::OperationHelper->do_match(
    'xform',
    ['-MList::Util=reduce', '{{reduced}} = reduce { $a * $b } map { (my $tmp = $_) =~ s/\D//g; $tmp } values %$r'],
    $input,
    $output
);

$output = <<OUTPUT;
{"a":"a1,a2","b":"b1","before":null}
{"a":"a3,a4,a5","b":"b2", "before":"b1"}
OUTPUT
App::RecordStream::Test::OperationHelper->do_match(
    'xform',
    ['-B', 1, '{{before}} = $B->[0]->{"b"}'],
    $input,
    $output
);

$output = <<OUTPUT;
{"a":"a1,a2","b":"b1","after":"b2"}
{"a":"a3,a4,a5","b":"b2", "after":null}
OUTPUT
App::RecordStream::Test::OperationHelper->do_match(
    'xform',
    ['-A', 1, '{{after}} = $A->[0]->{"b"}'],
    $input,
    $output
);

$input = <<INPUT;
{"a":"a1","b":"b1"}
{"a":"a2","b":"b1"}
{"a":"a3","b":"b2"}
{"a":"a4","b":"b2"}
{"a":"a5","b":"b2"}
INPUT

$output = <<OUTPUT;
{"after":"a2","a":"a1","b":"b1","before":null}
{"after":"a3","a":"a2","b":"b1","before":"a1"}
{"after":"a4","a":"a3","b":"b2","before":"a2"}
{"after":"a5","a":"a4","b":"b2","before":"a3"}
{"after":null,"a":"a5","b":"b2","before":"a4"}
OUTPUT
App::RecordStream::Test::OperationHelper->do_match(
    'xform',
    ['-C', 1, '{{after}} = $A->[0]->{"a"}; {{before}} = $B->[0]->{"a"}'],
    $input,
    $output
);


$input = <<INPUT;
{"a":"a1","b":"b1"}
{"a":"a2","b":"b1"}
INPUT

$output = <<OUTPUT;
{"foo":"bar"}
{"a":"a1c","b":"b1"}
{"a":"a2c","b":"b1"}
OUTPUT
App::RecordStream::Test::OperationHelper->do_match(
    'xform',
    ['--pre', 'push_output({foo=>"bar"})', '{{a}} .= "c"'],
    $input,
    $output
  );

  $output = <<OUTPUT;
{"a":"a1c","b":"b1"}
{"a":"a2c","b":"b1"}
{"foo":"bar"}
OUTPUT
  App::RecordStream::Test::OperationHelper->do_match(
    'xform',
    ['--post', 'push_output({foo=>"bar"})', '{{a}} .= "c"'],
    $input,
    $output
  );

  $output = <<OUTPUT;
{"a":"a1c","b":"b1"}
{"a":"a2c","b":"b1"}
{"foo":"bar","a":"c"}
OUTPUT
  App::RecordStream::Test::OperationHelper->do_match(
    'xform',
    ['--post', 'push_input({foo=>"bar"})', '{{a}} .= "c"'],
    $input,
    $output
  );

  $output = <<OUTPUT;
{"a":"a1","b":"b1","foo":"zipper"}
{"a":"a2","b":"b1","foo":"zipper"}
OUTPUT
  App::RecordStream::Test::OperationHelper->do_match(
    'xform',
    ['--pre', '$foo = "zipper"', '{{foo}} .= $foo'],
    $input,
    $output
  );

  $output = <<OUTPUT;
{"a":"a2","b":"b1","foo":"zipper"}
OUTPUT
  App::RecordStream::Test::OperationHelper->do_match(
    'xform',
    ['if(!$later){push_output();$later=1}; {{foo}} = "zipper"'],
    $input,
    $output
  );

  $output = <<OUTPUT;
{"foo":"bar","a":"c"}
OUTPUT
  App::RecordStream::Test::OperationHelper->do_match(
    'xform',
    ['--post', 'push_input({foo=>"bar"})', '{{a}} = "c"'],
    '',
    $output
  );

  $output = <<OUTPUT;
{"foo":"bar","a":"c"}
OUTPUT
  App::RecordStream::Test::OperationHelper->do_match(
    'xform',
    ['--pre', 'push_input({foo=>"bar"})', '{{a}} = "c"'],
    '',
    $output
  );

# Test for GH #70:
#   $ recs xform '42' <<<'{"foo":13}'
#   {"foo":13}



( run in 0.530 second using v1.01-cache-2.11-cpan-4e96b696675 )