view release on metacpan or search on metacpan
lib/App/RecordStream/Aggregator.pm view on Meta::CPAN
sub map_squish
{
my ($aggrs, $cookies) = @_;
my $return_record = App::RecordStream::Record->new();
for my $name (keys(%$aggrs))
{
my $aggregator = $aggrs->{$name};
my $value = $aggregator->squish($cookies->{$name});
${$return_record->guess_key_from_spec($name)} = $value;
}
return $return_record;
}
sub typename
{
return "aggregator";
}
lib/App/RecordStream/DomainLanguage/Valuation/KeySpec.pm view on Meta::CPAN
return $this;
}
sub evaluate_record
{
my $this = shift;
my $r = shift;
my $keyspec = $this->{'KEYSPEC'};
return ${$r->guess_key_from_spec($keyspec)};
}
1;
lib/App/RecordStream/Executor.pm view on Meta::CPAN
my ($this, $name, @args) = @_;
return $this->get_code_ref($name)->(@args);
}
sub transform_code {
my $this = shift;
my $code = shift;
while ( $code =~ m/\{\{(.*?)\}\}/ ) {
my $specifier = $1;
my $guessing_code = '${App::RecordStream::KeySpec::find_key($r, qq{\@' . $specifier . '})}';
$code =~ s/\{\{.*?\}\}/$guessing_code/;
}
return $code;
}
sub usage {
return <<USAGE;
CODE SNIPPETS:
__FORMAT_TEXT__
Recs code snippets are perl code, with one exception. There a couple of
lib/App/RecordStream/KeySpec.pm view on Meta::CPAN
use App::RecordStream::KeySpec;
use Data::Dumper;
my $registry = {};
sub find_key {
my ($data, $spec, $no_vivify, $throw_error) = @_;
my $spec_obj = __PACKAGE__->new($spec);
return $spec_obj->guess_key($data, $no_vivify, $throw_error);
}
sub new
{
my $class = shift;
my $spec = shift;
if ( exists $registry->{$spec} ) {
return $registry->{$spec};
}
lib/App/RecordStream/KeySpec.pm view on Meta::CPAN
return $this;
}
sub init
{
my $this = shift;
$this->_parse_key_spec();
}
{
my $guessed_keys = {};
sub _search_string_to_key {
my $key_chain = shift;
my $string = shift;
return $guessed_keys->{join('-', @$key_chain)}->{$string};
}
sub _add_string_key_mapping {
my $key_chain = shift;
my $string = shift;
my $key = shift;
$guessed_keys->{join('-', @$key_chain)}->{$string} = $key;
}
}
sub _guess_key_name_raw {
my ($this, $data, $key_chain, $search_string) = @_;
my $fuzzy = $this->{'FUZZY'};
if ( UNIVERSAL::isa($data, 'ARRAY') ) {
if ( $search_string =~ m/^#(\d+)$/ ) {
return $1;
}
else {
die "Cannot select non-numeric index: $search_string (did you forget to prefix with a '#'?) for array: " . Dumper($data);
lib/App/RecordStream/KeySpec.pm view on Meta::CPAN
$found_key = $search_string;
}
_add_string_key_mapping($key_chain, $search_string, $found_key);
return $found_key
}
sub has_key_spec {
my ($this, $data) = @_;
eval { $this->guess_key($data, 0, 1) };
if ( $@ =~ m/^NoSuchKey/ ) {
return 0;
}
elsif ( $@ ) {
#Rethrow if a different error
die $@;
}
return 1;
}
sub get_key_list_for_spec {
my ($this, $data) = @_;
return $this->_guess_key_recurse(
$data,
[],
1,
0,
1,
@{$this->{'PARSED_KEYS'}},
);
}
sub _parse_key_spec {
lib/App/RecordStream/KeySpec.pm view on Meta::CPAN
push @$keys, $current_key;
}
$this->{'PARSED_KEYS'} = $keys;
$this->{'FUZZY'} = $fuzzy;
}
{
my $keylookup_hash = {};
sub guess_key {
my ($this, $data, $no_vivify, $throw_error) = @_;
my @args = @{$this->{'PARSED_KEYS'}};
$no_vivify ||= 0;
$throw_error ||= 0;
my $args_string = join('-', @args, $no_vivify, $throw_error);
if ( my $code = $keylookup_hash->{$args_string} ) {
return $code->($data);
}
my $keys = $this->_guess_key_recurse(
$data,
[],
$no_vivify,
$throw_error,
1,
@args,
);
my $code = $this->_generate_keylookup_sub($keys, $no_vivify);
$keylookup_hash->{$args_string} = $code;
lib/App/RecordStream/KeySpec.pm view on Meta::CPAN
$code_string .= "return \\($key_accessor)}";
my $sub_ref = eval $code_string;
if ( $@ ) {
warn "Unexpected error in creating key lookup!\n";
die $@;
}
return $sub_ref;
}
sub _guess_key_recurse {
my ($this, $data, $key_chain, $no_vivify, $throw_error,
$return_key_chain, $search_string, @next_strings) = @_;
my $type = ref($data);
if ( $type eq 'SCALAR' || UNIVERSAL::isa(\$data, 'SCALAR') ) {
die "Cannot look for $search_string in scalar: " . Dumper($data);
}
my $key = $this->_guess_key_name_raw($data, $key_chain, $search_string);
my $value;
if ( $type eq 'ARRAY' ) {
$value = \($data->[$key]);
$key = "#$key";
}
else {
if ( $no_vivify && (!exists $data->{$key}) ) {
return $return_key_chain ? [] : '';
lib/App/RecordStream/KeySpec.pm view on Meta::CPAN
}
if ( substr($next_strings[0], 0, 1) eq '#' ) {
$$value = [];
}
else {
$$value = {};
}
}
return $this->_guess_key_recurse(
$$value,
[@$key_chain, $key],
$no_vivify,
$throw_error,
$return_key_chain,
@next_strings,
);
}
return $return_key_chain ? [@$key_chain, $key] : $value;
lib/App/RecordStream/Operation.pm view on Meta::CPAN
croak "Subclass should implement: " . ref($this);
}
sub stream_done {
}
sub push_record {
my ($this, $record) = @_;
if ( $this->{'FILENAME_KEY'} ) {
${$record->guess_key_from_spec($this->{'FILENAME_KEY'})} = get_current_filename();
}
return $this->{'NEXT'}->accept_record($record);
}
sub push_line {
my ($this, $line) = @_;
$this->{'NEXT'}->accept_line($line);
}
lib/App/RecordStream/Operation/annotate.pm view on Meta::CPAN
}
sub accept_record {
my $this = shift;
my $record = shift;
my $specs = $this->{'KEYGROUP'}->get_keyspecs_for_record($record);
my @values;
foreach my $key (sort @$specs) {
my $value = ${$record->guess_key_from_spec($key)};
push @values, $value;
}
# Join keys with the ASCII record separator character (30)
my $synthetic_key = join(chr(30), @values);
if ( exists $this->{'ANNOTATIONS'}->{$synthetic_key} ) {
$this->apply_annotation($synthetic_key, $record);
$this->push_record($record);
return 1;
lib/App/RecordStream/Operation/annotate.pm view on Meta::CPAN
sub apply_annotation {
my $this = shift;
my $annotation_key = shift;
my $record = shift;
my $stores = $this->{'ANNOTATIONS'}->{$annotation_key};
foreach my $keyspec (keys %$stores) {
my $value = $stores->{$keyspec};
${$record->guess_key_from_spec($keyspec)} = $value;
}
}
sub add_help_types {
my $this = shift;
$this->use_help_type('snippet');
$this->use_help_type('keyspecs');
$this->use_help_type('keygroups');
$this->use_help_type('keys');
}
lib/App/RecordStream/Operation/collate/BaseClumperCallback.pm view on Meta::CPAN
# then, the aggregators
%{App::RecordStream::Aggregator::map_squish($this->{'AGGREGATORS'}, $cookie->[2])},
};
my $record = App::RecordStream::Record->new();
for my $key (keys(%$result))
{
my $value = $result->{$key};
${$record->guess_key_from_spec($key)} = $value;
}
$this->{'RECORD_CB'}->($record);
}
}
1;
lib/App/RecordStream/Operation/delta.pm view on Meta::CPAN
}
sub accept_record
{
my $this = shift;
my $record = shift;
my $last_record = $this->{'LAST_RECORD'};
if ( $last_record ) {
foreach my $key (@{$this->{'KEY_GROUPS'}->get_keyspecs($last_record)})
{
if ( ${$record->guess_key_from_spec($key)} and ${$last_record->guess_key_from_spec($key)} )
{
${$last_record->guess_key_from_spec($key)} = ${$record->guess_key_from_spec($key)} - ${$last_record->guess_key_from_spec($key)};
}
else
{
${$last_record->guess_key_from_spec($key)} = undef;
}
}
$this->push_record($last_record);
}
$this->{'LAST_RECORD'} = $record;
return 1;
}
lib/App/RecordStream/Operation/flatten.pm view on Meta::CPAN
sub remove_spec {
my ($this, $record, $spec) = @_;
my $key_list = $record->get_key_list_for_spec($spec);
my $last_key = pop @$key_list;
my $new_spec = join('/', @$key_list);
my $data = $record;
if ($new_spec) {
$data = ${$record->guess_key_from_spec($new_spec, 1)};
}
my $ref_type = ref($data);
if ( ! grep { $_ eq $ref_type } @$INVALID_REF_TYPES ) {
return delete $data->{$last_key};
}
else {
die "Cannot flatten into ref type: '$ref_type', must be a hash! skipping spec $spec!\n";
}
}
lib/App/RecordStream/Operation/flatten.pm view on Meta::CPAN
}
if($depth != 0 && ref($value) eq "HASH") {
for my $key (keys(%$value)) {
$this->split_field($record, $name . $separator . $key, $depth - 1, $value->{$key});
}
return;
}
# either depth is 0 or it wasn't expandable anyway
${$record->guess_key_from_spec($name)} = $value;
}
sub add_help_types {
my $this = shift;
$this->use_help_type('keyspecs');
$this->use_help_type('keygroups');
$this->use_help_type('keys');
}
sub usage {
lib/App/RecordStream/Operation/fromcsv.pm view on Meta::CPAN
push @fields, @$row;
$do_headers = 0;
next;
}
my @values = @$row;
my $record = App::RecordStream::Record->new();
for(my $i = 0; $i < @values; ++$i) {
my $key = $fields[$i] || $i;
${$record->guess_key_from_spec($key)} = $values[$i];
}
$this->push_record($record);
}
# Parsing was a success only if we reached EOF and we got no error. Code
# 2012 is used by Text::CSV_XS for normal EOF condition.
my ($code, $msg, $pos) = $parser->error_diag;
unless ($parser->eof and ($code == 0 or $code == 2012)) {
my ($line, $file) = ($., $this->get_current_filename);
die "fromcsv: parse error: $msg ($code)",
lib/App/RecordStream/Operation/fromjsonarray.pm view on Meta::CPAN
my @arrays = $json->incr_parse($contents);
for my $item (map { @$_ } @arrays) {
$item = App::RecordStream::Record->new($item);
my $record = $item;
if ($has_fields) {
$record = App::RecordStream::Record->new();
for my $field (@$fields) {
$record->set($field, ${$item->guess_key_from_spec($field)});
}
}
$this->push_record($record);
}
}
sub usage {
my ($this) = @_;
lib/App/RecordStream/Operation/frommultire.pm view on Meta::CPAN
my $regex_index = 0;
for my $regex (@{$this->_get_regexes()}) {
my ($string, $fields, $pre_flush, $post_flush) = @$regex;
my $field_prefix = "$regex_index-";
if(my @groups = ($line =~ $string)) {
my $pairs = $this->get_field_value_pairs(\@groups, $fields, $field_prefix);
if(!$this->get_clobber()) {
foreach my $pair ( @$pairs ) {
my ($name, $value) = @$pair;
if(defined ${$this->{'RECORD'}->guess_key_from_spec($name)}) {
$pre_flush = 1;
}
}
}
if($pre_flush) {
$this->flush_record();
}
foreach my $pair ( @$pairs ) {
my ($name, $value) = @$pair;
${$this->{'RECORD'}->guess_key_from_spec($name)} = $value;
}
if($post_flush) {
$this->flush_record();
}
}
++$regex_index;
}
return 1;
lib/App/RecordStream/Operation/fromre.pm view on Meta::CPAN
sub accept_line {
my $this = shift;
my $line = shift;
if(my @groups = ($line =~ $this->get_pattern())) {
my $record = App::RecordStream::Record->new();
my $index = 0;
foreach my $value (@groups) {
${$record->guess_key_from_spec($this->get_field($index))} = $value;
++$index;
}
$this->push_record($record);
}
return 1;
}
sub add_help_types {
lib/App/RecordStream/Operation/fromsplit.pm view on Meta::CPAN
if ($this->{'HEADER'}) {
$this->add_field($_) for @{$this->get_values_for_line($line)};
delete $this->{'HEADER'};
}
else {
my $record = App::RecordStream::Record->new();
my $index = 0;
foreach my $value (@{$this->get_values_for_line($line)}) {
${$record->guess_key_from_spec($this->get_field($index))} = $value;
++$index;
}
$this->push_record($record);
}
return 1;
}
sub get_values_for_line {
lib/App/RecordStream/Operation/generate.pm view on Meta::CPAN
my $pid = open(my $pipe, "-|", $interpolated_command);
if (!$pid) {
warn "# $0 open(..., \"$interpolated_command |\") failed: $!\n";
return 1;
}
my $generator_stream = App::RecordStream::InputStream->new(FH => $pipe);
while(my $generated_record = $generator_stream->get_record()) {
${$generated_record->guess_key_from_spec($this->{'KEYCHAIN'})} = $record->as_hashref();
$this->push_record($generated_record);
}
# App::RecordStream::InputStream closes the file handle for us
return 1;
}
sub add_help_types {
my $this = shift;
$this->use_help_type('keyspecs');
lib/App/RecordStream/Operation/join.pm view on Meta::CPAN
$this->{'DB'} = \%db;
}
sub value_for_key {
my $this = shift;
my $record = shift;
my $key = shift;
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'};
lib/App/RecordStream/Operation/multiplex/BaseClumperCallback.pm view on Meta::CPAN
return $op;
}
sub clumper_callback_push_record {
my $this = shift;
my $op = shift;
my $record = shift;
my $line_key = $this->{'LINE_KEY'};
if(defined($line_key)) {
$op->accept_line(${$record->guess_key_from_spec($line_key)});
}
else {
$op->accept_record($record);
}
}
sub clumper_callback_end {
my $this = shift;
my $op = shift;
$op->finish();
lib/App/RecordStream/Operation/normalizetime.pm view on Meta::CPAN
sub accept_record {
my $this = shift;
my $record = shift;
my $key = $this->{'KEY'};
my $threshold = $this->{'THRESHOLD'};
my $strict = $this->{'STRICT'};
my $sanitized_key = $this->{'SANITIZED_KEY'};
my $prior_normalized_value = $this->{'PRIOR_NORMALIZED_VALUE'};
my $value = ${$record->guess_key_from_spec($key)};
my $time = $value;
if ( ! $this->{'EPOCH'} ) {
$time = UnixDate( ParseDate( $value ), "%s" );
die "I can't understand Key: $key, with value: $value" unless $time;
}
my $normalized_time_cur_period = int( $time / $threshold ) * $threshold;
my $normalized_time_prior_period = $normalized_time_cur_period - $threshold;
lib/App/RecordStream/Operation/stream2table.pm view on Meta::CPAN
die "You must specify a --field option\n" unless defined($field);
$this->{'FIELD'} = $field;
$this->{'REMOVE_FIELD'} = (not ($field =~ m![/@]!));
}
sub accept_record {
my $this = shift;
my $record = shift;
my $key = ${$record->guess_key_from_spec($this->{'FIELD'})};
if ( $this->{'REMOVE_FIELD'} ) {
$record->remove($this->{'FIELD'});
}
$this->{'HASH'}->{$key} ||= [];
push @{$this->{'HASH'}->{$key}}, $record;
return 1;
}
lib/App/RecordStream/Operation/tocsv.pm view on Meta::CPAN
$this->{'KEYS'} = [sort keys %$record];
}
if ( $this->{'HEADERS'} ) {
$this->output_values($this->{'KEYS'});
}
}
my @values;
foreach my $key (@{$this->{'KEYS'}}) {
push @values, ${$record->guess_key_from_spec($key)};
}
$this->output_values(\@values);
return 1;
}
sub output_values {
my $this = shift;
my $values = shift;
lib/App/RecordStream/Operation/todb.pm view on Meta::CPAN
$name = $dbh->quote_identifier($name);
my @keys = keys %$fields;
my $columns_string = join(',', map {$dbh->quote_identifier($_);} @keys);
my $values = '';
foreach my $key (@keys) {
my $value = ${$record->guess_key_from_spec($key)};
$value = '' if !defined($value);
$value = substr($value, 0, 255) if ( ! $fields->{$key} );
$values .= $dbh->quote($value) . ",";
}
chop $values;
my $sql = "INSERT INTO $name ($columns_string) VALUES ($values)";
$this->dbh_do($sql);
}
lib/App/RecordStream/Operation/tognuplot.pm view on Meta::CPAN
sub accept_record {
my ($this, $record) = @_;
if ( $this->{'FIRST_RECORD'} ) {
$this->{'FIRST_RECORD'} = 0;
$this->init_fields($record);
}
my $line = '';
foreach my $key (@{$this->{'FIELDS'}}) {
my $value = ${$record->guess_key_from_spec($key)};
$value = 0 if not defined $value;
$line .= "$value ";
}
chop $line;
if ( $this->{'DUMP_TO_SCREEN'} ) {
$this->push_line($line);
}
else {
my $tempfh = $this->{'TEMPFH'};
lib/App/RecordStream/Operation/tohtml.pm view on Meta::CPAN
$this->print_start($record);
my $fields = $this->{'FIELDS'};
my $row_attributes = $this->{'ROW_ATTRIBUTES'};
my $cell_attributes = $this->{'CELL_ATTRIBUTES'};
$this->push_line(" <tr $row_attributes>");
foreach my $field (@$fields) {
my $value = ${$record->guess_key_from_spec($field)} || '';
$this->push_line(" <td $cell_attributes>$value</td>");
}
$this->push_line(" </tr>");
return 1;
}
sub print_start {
my $this = shift;
lib/App/RecordStream/Operation/topn.pm view on Meta::CPAN
sub accept_record {
my $this = shift;
my $record = shift;
if ( ! $this->{'KEYS'} ) {
$this->init_keys($record);
}
my $current_key_values = "";
foreach my $k ( @{$this->{'KEYS'}} ) {
$current_key_values .= ${$record->guess_key_from_spec( $k )} . $this->{'DELIM'};
}
$this->{'NUM_SEEN'}->{$current_key_values}++;
if( $this->{'NUM_SEEN'}->{$current_key_values} <= $this->{'NUM'} ) {
$this->push_record($record);
}
return 1;
}
lib/App/RecordStream/Operation/toprettyprint.pm view on Meta::CPAN
my $width = length $key;
$this->{'FORMAT_KEY_WIDTH'} = $width
if $width > $this->{'FORMAT_KEY_WIDTH'};
}
$this->{'FORMAT_KEY_WIDTH'} *= -1
if $this->{'ALIGNED'} eq 'left';
}
$this->push_line('-' x 70);
foreach my $key (sort @$specs) {
my $value = ${$record->guess_key_from_spec($key)};
$this->output_value('', $key, $value);
}
return 1;
}
sub _format_key {
my $this = shift;
my $key = shift;
return $key unless $this->{'FORMAT_KEY_WIDTH'};
lib/App/RecordStream/Operation/toptable.pm view on Meta::CPAN
# make sure records matches appropriate pins
my $kickout = 0;
foreach my $pfield (keys(%pins)) {
if($pfield eq "FIELD") {
next;
}
my $v = '';
if ( $record->has_key_spec($pfield) ) {
$v = ${$record->guess_key_from_spec($pfield)};
}
if($pins{$pfield} ne $v) {
$kickout = 1;
last;
}
}
if($kickout) {
next;
}
lib/App/RecordStream/Operation/toptable.pm view on Meta::CPAN
next;
}
my @xv;
for my $xfield (@xfields) {
my $v = "";
if($xfield eq "FIELD") {
$v = $vfield;
}
elsif($record->has_key_spec($xfield)) {
$v = ${$record->guess_key_from_spec($xfield)};
}
push @xv, $v;
}
my @yv;
for my $yfield (@yfields) {
my $v = "";
if($yfield eq "FIELD") {
$v = $vfield;
}
elsif($record->has_key_spec($yfield)) {
$v = ${$record->guess_key_from_spec($yfield)};
}
push @yv, $v;
}
my $v = "";
if($record->has_key_spec($vfield)) {
$v = ${$record->guess_key_from_spec($vfield)};
}
_touch_node_recurse($x_values_tree, @xv);
_touch_node_recurse($y_values_tree, @yv);
push @r2, [\@xv, \@yv, $v];
}
}
# Start constructing the ASCII table
lib/App/RecordStream/Operation/totable.pm view on Meta::CPAN
)
);
}
}
sub format_field
{
my ($this, $field, $thunk) = @_;
my ($r, $lastr) = @$thunk;
my $value = ${$r->guess_key_from_spec($field)};
$value = '' if ( ! defined $value );
if ( ref($value) )
{
$value = App::RecordStream::OutputStream::hashref_string($value);
}
if($this->{'CLEAR'})
{
if($value eq $lastr->{$field})
lib/App/RecordStream/Operation/totable.pm view on Meta::CPAN
}
return $max;
}
sub extract_field {
my $this = shift;
my $record = shift;
my $field = shift;
my $value = ${$record->guess_key_from_spec($field)};
$value = '' if ( ! defined $value );
if ( ref($value) )
{
$value = App::RecordStream::OutputStream::hashref_string($value);
}
return $value;
}
lib/App/RecordStream/Record.pm view on Meta::CPAN
Marshall a record into hash format, returning a reference. The caller may
modify this hash (the changes will not be reflected in the record itself).
=item $cmp = $this->cmp($that, @keys);
Compare this record to another, using comparators derived from @keys (see
get_comparators). Returns -1, 0, or 1 for $this before $that, $this same as
$that, and $this after $that, respectively.
=item $value_ref = $this->guess_key_from_spec($keyspec, $no_vivify = 0, $throw_error = 0)
Get the reference for a key spec. Commonly used like:
${$r->guess_key_from_spec('foo/bar')} eq 'zip'
${$r->guess_key_from_spec('foo/bar')} = 'boo'
(the assign back gets back into the record)
no_vivify and no_error are optional, and control behavior in the absence of the
specified key. throw_error will cause a 'NoSuchKey' exception to be thrown.
See 'man recs' for more info on key specs
=item $boolean = $this->has_key_spec($spec)
lib/App/RecordStream/Record.pm view on Meta::CPAN
my $func = $comparators{$comparator_name};
die "Not a valid comparator: $comparator_name" unless ( $func );
my $comparator = sub {
my ($this, $that) = @_;
my $val = undef;
if ( $all_hack )
{
my $this_value = ${$this->guess_key_from_spec($field)};
my $that_value = ${$that->guess_key_from_spec($field)};
if ( $this_value eq 'ALL' && $that_value ne 'ALL' )
{
$val = 1;
}
if ( $this_value ne 'ALL' && $that_value eq 'ALL' )
{
$val = -1;
}
if ( $this_value eq 'ALL' && $that_value eq 'ALL' )
{
return 0;
}
}
if ( ! defined $val )
{
$val = $func->(${$this->guess_key_from_spec($field)}, ${$that->guess_key_from_spec($field)});
}
if ( $direction eq '-' )
{
return -$val;
}
return $val;
};
lib/App/RecordStream/Record.pm view on Meta::CPAN
my ($this) = @_;
return $this->as_hashref();
}
sub has_key_spec {
my ($this, $spec) = @_;
my $spec_obj = App::RecordStream::KeySpec->new($spec);
return $spec_obj->has_key_spec($this);
}
sub guess_key_from_spec {
return App::RecordStream::KeySpec::find_key(@_);
}
sub get_key_list_for_spec {
my ($this, $spec) = @_;
my $spec_obj = App::RecordStream::KeySpec->new($spec);
return $spec_obj->get_key_list_for_spec($this);
}
lib/App/RecordStream/Record.pm view on Meta::CPAN
}
}
sub get_group_values {
my ($this, $group, $rerun) = @_;
my $specs = $this->get_keys_for_group($group, $rerun);
my $values = [];
foreach my $spec (@$specs) {
push @$values, ${$this->guess_key_from_spec($spec)};
}
return $values;
}
sub cmp
{
my ($this, $that, @keys) = @_;
my $comparators = get_comparators(@keys);
src/fast-recs-collate/lookup3.c view on Meta::CPAN
#include <stdint.h> /* defines uint32_t etc */
#include <sys/param.h> /* attempt to define endianness */
#ifdef linux
# include <endian.h> /* attempt to define endianness */
#endif
#define VALGRIND
/*
* My best guess at if you are big-endian or little-endian. This may
* need adjustment.
*/
#if (defined(__BYTE_ORDER) && defined(__LITTLE_ENDIAN) && \
__BYTE_ORDER == __LITTLE_ENDIAN) || \
(defined(i386) || defined(__i386__) || defined(__i486__) || \
defined(__i586__) || defined(__i686__) || defined(vax) || defined(MIPSEL))
# define HASH_LITTLE_ENDIAN 1
# define HASH_BIG_ENDIAN 0
#elif (defined(__BYTE_ORDER) && defined(__BIG_ENDIAN) && \
__BYTE_ORDER == __BIG_ENDIAN) || \
tests/RecordStream/KeySpec.t view on Meta::CPAN
use Test::More 'no_plan';
use Data::Dumper;
use App::RecordStream::Record;
BEGIN { use_ok("App::RecordStream::KeySpec"); }
{
my $rec = App::RecordStream::Record->new("first_key" => "foo", "second_key" => { "bar" => "biz"}, 0 => "zero");
my $spec = App::RecordStream::KeySpec->new("first_key");
is(${$spec->guess_key($rec)}, "foo", "Exact key spec match");
is(${App::RecordStream::KeySpec::find_key($rec,"first_key")}, "foo", "Exact key spec match");
is(${App::RecordStream::KeySpec::find_key($rec,"does_not_exist")}, undef, "key doesn't exist");
is(${App::RecordStream::KeySpec::find_key($rec,"second_key/bar")}, "biz", "nested hash");
is(${App::RecordStream::KeySpec::find_key($rec,"\@first")}, "foo", "Prefix matching");
is(${App::RecordStream::KeySpec::find_key($rec,"\@cond/ar")}, "biz", "nested substring matching");
is(${App::RecordStream::KeySpec::find_key($rec,"0")}, "zero", "number only first level");
is(${App::RecordStream::KeySpec::find_key($rec,'@0')}, "zero", "number only first level, matching");
}