The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Array::Stream::Transactional::Matcher - Perl extension for finding content in arrays

SYNOPSIS

  use Array::Stream::Transactional::Matcher qw(mkrule);
  use Array::Stream::Transactional;
  my $stream = Array::Stream::Transactional->new([1,5,3,2,5,2,4,1,1,2,3,2,2]);
  my $rule = mkrule(Flow::sequence => mkrule(Value::eq => 2), mkrule(Value::gt => 2));
  my $matcher = Array::Stream::Transactional::Matcher->new(rules => [$rule]);
  my @matches = $matcher->match($stream);
  for(@matches) {
    print "Found match at $_->{start} to $_->{end}\n";
  }

DESCRIPTION

Array::Stream::Transactional::Matcher allowes you to search an array for content based on arbitrary complex rules.

CONSTRUCTOR

new ( %options )

This is the constructor for a matcher. Options are passed as keyword value pairs. Recognized options are:

rules => ARRAYREF

Patterns we are looking for. Each element must either be a Array::Stream::Transactional::Matcher::Rule subclass or an ARRAY reference where the first element is an Array::Stream::Transactional::Matcher::Rule subclass and the second element is a CODE reference that is called when a match is found. If no custom handler is supplied, it'll try to use the handler supplied by call or an empty subroutine if that wasn't found either.

call => CODEREF

A subroutine reference that is called when a match is made.

METHODS

match ( $STREAM )

Iterates over the Array::Stream::Transactional object $STREAM and tries to match each item with the set of rules that are defined. If a rule matches, it continues with the next item in the stream.

The return value is an array of hashes containing the keys rule which is a reference to the rule that matches, start is the offset within the stream that the match where found and end is the offset whinit the stream where the matching rule ended.

If a handler is supplied a handler or a default handler is supplied it is passed the matching rule, the start offset and end offset.

rules ()

Returns an ARRAY reference containing the rules that are defined.

EXPORT

None by default.

mkrule ( CLASS => @ARGS )

Shortcut for calling new on Array::Stream::Transactional::Matcher::CLASS.

SEE ALSO

Rules implementing logical operators such as and, or, xor, not are described in Array::Stream::Transactional::Matcher::Logical

Rules implementing value tests such as eq, ne, lt and so forth are described in Array::Stream::Transactional::Matcher::Value

Rules implementing flow os rules such as sequence, repetitions, optionals, switches are described in Array::Stream::Transactional::Matcher::Flow

A short description on how to write custom rules is available in Array::Stream::Transactional::Rule

AUTHOR

Claes Jacobsson, claesjac@cpan.org

COPYRIGHT AND LICENSE

Copyright 2004 by Claes Jacobsson

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.