1 # See Plugin.pod for documentation
2 package re::engine::Plugin;
9 # All engines should subclass the core Regexp package
12 XSLoader::load __PACKAGE__, $VERSION;
14 my $RE_ENGINE_PLUGIN = ENGINE();
16 # How many? Used to cheat %^H
19 # Where we store our CODE refs
22 # Generate a key to use in the %^H hash from a string, prefix the
23 # package name like L<pragma> does
24 my $key = sub { __PACKAGE__ . "::" . $_[0] };
31 my @callback = qw(comp exec);
34 next unless exists $sub{$_};
35 my $cb = delete $sub{$_};
37 unless (ref $cb eq 'CODE') {
39 Carp::croak("'$_' is not CODE");
43 my $id = $callback ++;
45 # Insert into our callback storage,
46 $callback{$_}->{$id} = $cb;
48 # Instert into our cache with a key we can retrive later
49 # knowing the ID in %^H and what callback we're getting
50 $^H{ $key->($_) } = $id;
53 $^H{regcomp} = $RE_ENGINE_PLUGIN;
58 # Delete the regcomp hook
60 if $^H{regcomp} == $RE_ENGINE_PLUGIN;
63 # Minimal function to get CODE for a given key to be called by the
64 # get_H_callback C function.
67 my ($name) = @_; # 'comp', 'exec', ...
69 my $h = (caller(0))[10];
70 my $id = $h->{ $key->($name) };
72 my $cb = defined $id ? $callback{$name}->{$id} : 0;
79 my ($re, %callback) = @_;
81 for my $key (keys %callback) {
82 $key =~ y/a-z/A-Z/; # ASCII uc
83 my $name = '_num_capture_buff_' . $key;
84 $re->$name( $callback{$key} );