1 # See Plugin.pod for documentation
2 package re::engine::Plugin;
10 # All engines should subclass the core Regexp package
13 XSLoader::load(__PACKAGE__, $VERSION);
16 my $RE_ENGINE_PLUGIN = ENGINE();
18 # How many? Used to cheat %^H
21 # Where we store our CODE refs
24 # Generate a key to use in the %^H hash from a string, prefix the
25 # package name like L<pragma> does
26 my $key = sub { __PACKAGE__ . "::" . $_[0] };
33 my @callback = qw(comp exec);
36 next unless exists $sub{$_};
37 my $cb = delete $sub{$_};
39 unless (ref $cb eq 'CODE') {
41 Carp::croak("'$_' is not CODE");
45 my $id = $callback ++;
47 # Insert into our callback storage,
48 $callback{$_}->{$id} = $cb;
50 # Instert into our cache with a key we can retrive later
51 # knowing the ID in %^H and what callback we're getting
52 $^H{ $key->($_) } = $id;
55 $^H{regcomp} = $RE_ENGINE_PLUGIN;
60 # Delete the regcomp hook
62 if $^H{regcomp} == $RE_ENGINE_PLUGIN;
65 # Minimal function to get CODE for a given key to be called by the
66 # get_H_callback C function.
69 my ($name) = @_; # 'comp', 'exec', ...
71 my $h = (caller(0))[10];
72 my $id = $h->{ $key->($name) };
74 my $cb = defined $id ? $callback{$name}->{$id} : 0;
81 my ($re, %callback) = @_;
83 for my $key (keys %callback) {
84 $key =~ y/a-z/A-Z/; # ASCII uc
85 my $name = '_num_capture_buff_' . $key;
86 $re->$name( $callback{$key} );