=head1 NAME re::engine::Plugin - Pure-Perl regular expression engine plugin interface =head1 SYNOPSIS use feature ':5.10'; use re::engine::Plugin ( comp => sub { my ($re) = @_; # A re::engine::Plugin object # return value ignored }, exec => sub { my ($re, $str) = @_; # We always like ponies! return 1 if $str eq 'pony'; return; } ); "pony" =~ /yummie/; =head1 DESCRIPTION As of perl 5.9.5 it's possible lexically replace perl's built-in regular expression engine (see L). This module provides glue for writing such a wrapper in Perl instead of the provided C/XS interface. B: This module is a development release that does not work with any version of perl other than the current (as of February 2007) I. The provided interface is not a complete wrapper around the native interface (yet!) but the parts that are left can be implemented with additional methods so the completed API shouldn't have any major changes. =head1 METHODS =head2 import Takes a list of key-value pairs with the only mandatory pair being L and its callback routine. Both subroutine references and the string name of a subroutine (e.g. C<"main::exec">) can be specified. The real CODE ref is currently looked up in the symbol table in the latter case. =over 4 =item comp An optional sub to be called when a pattern is being compiled, note that a single pattern may be compiled more than once by perl. The subroutine will be called with a regexp object (see L). The regexp object will be stored internally along with the pattern and provided as the first argument for the other callback routines (think of it as C<$self>). If your regex implementation needs to validate its pattern this is the right place to B on an invalid one (but see L). The return value of this subroutine is discarded. =item exec Called when a given pattern is being executed, the first argument is the regexp object and the second is the string being matched. The routine should return true if the pattern matched and false if it didn't. =item intuit TODO: implement =item checkstr TODO: implement =item free TODO: implement =item dupe TODO: implement =item numbered_buff_get TODO: implement =item named_buff_get TODO: implement =back =head2 flags L =head1 TODO =over =item * Provide an API for named (C<$+{name}>) and unnamed (C<$1, $2, ...>) match variables, allow specifying both offsets into the pattern and any given scalar. =item * Find some neat example for the L, suggestions welcome. =back =head1 BUGS Please report any bugs that aren't already listed at L to L =over 1 =item Calling C or anything that uses it (such as C) in the L callback routines will not be trapped by an C block that the pattern is in, i.e. use Carp qw(croak); use re::engine::Plugin( comp => sub { my $re = shift; croak "Your pattern is invalid" unless $re->pattern =~ /pony/; } ); # Ignores the eval block eval { /you die in C, you die for real/ }; Simply put this happens because the real subroutine call happens indirectly and not in the scope of the C block. =back =head1 Regexp object The regexp object is passed around as the first argument to all the callback routines, it supports the following method calls (with more to come!). =over =item pattern Returns the pattern this regexp was compiled with. =item flags Returns a string of flags the pattern was compiled with. (e.g. C<"xs">). The flags are not guarenteed to be in any particular order, so don't depend on the current one. =item stash Returns or sets a user-defined stash that's passed around with the pattern, this is useful for passing around an arbitary scalar between callback routines, example: use re::engine::Plugin ( comp => sub { $_[0]->stash( [ 1 .. 5 ] ) }, comp => sub { $_[0]->stash }, # Get [ 1 .. 5] ); =item minlen The minimum length a given string must be to match the pattern, set this to an integer in B and perl will not call your B routine unless the string being matched as at least that long. Returns the currently set length if not called with any arguments or C if no length has been set. =back =head1 SEE ALSO L =head1 THANKS Yves explaining why I made the regexp engine a sad panda. =head1 AUTHOR Evar ArnfjErE Bjarmason =head1 LICENSE This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. Copyright 2007 Evar ArnfjErE Bjarmason. =cut