return;
}
+sub callbacks
+{
+ my ($re, %callback) = @_;
+
+ my %map = map { $_ => "_$_" } qw/exec/;
+
+ for my $key (keys %callback) {
+ my $name = $map{$key};
+ next unless defined $name;
+ $re->$name($callback{$key});
+ }
+}
+
sub num_captures
{
my ($re, %callback) = @_;
method. The routine should return a true value if the match was
successful, and a false one if it wasn't.
+This callback can also be specified on an individual basis with the
+L</callbacks> method.
+
=head1 METHODS
=head2 str
The length specified will be used as a a byte length (using
L<SvPV|perlapi/SvPV>), not a character length.
+=head2 callbacks
+
+ # A dumb regexp engine that just tests string equality
+ use re::engine::Plugin comp => sub {
+ my ($re) = @_;
+
+ my $pat = $re->pattern;
+
+ $re->callbacks(
+ exec => sub {
+ my ($re, $str) = @_;
+ return $pat eq $str;
+ },
+ );
+ };
+
+Takes a list of key-value pairs of names and subroutines, and replace the
+callback currently attached to the regular expression for the type given as
+the key by the code reference passed as the corresponding value.
+
+The only valid key is currently C<exec>. See L</exec> for more details about
+this callback.
+
=head2 num_captures
$re->num_captures(
}
}
+void
+_exec(re::engine::Plugin self, ...)
+PPCODE:
+ if (items > 1) {
+ SvREFCNT_dec(self->cb_exec);
+ self->cb_exec = ST(1);
+ SvREFCNT_inc(self->cb_exec);
+ }
+
void
_num_capture_buff_FETCH(re::engine::Plugin self, ...)
PPCODE:
--- /dev/null
+#!perl
+
+use strict;
+use warnings;
+
+use Test::More tests => 4 * 2;
+
+my $count;
+
+use re::engine::Plugin comp => sub {
+ my ($re) = @_;
+
+ my $pat = $re->pattern;
+
+ $re->callbacks(
+ exec => sub {
+ my ($re, $str) = @_;
+
+ ++$count;
+
+ return $str eq $pat;
+ },
+ );
+};
+
+$count = 0;
+
+ok "foo" =~ /foo/;
+is $count, 1;
+ok "fool" !~ /foo/;
+is $count, 2;
+
+my $rx = qr/bar/;
+
+ok "bar" =~ $rx;
+is $count, 3;
+ok "foo" !~ $rx;
+is $count, 4;