1 # See Plugin.pod for documentation
\r
2 package re::engine::Plugin;
\r
8 our $VERSION = '0.04_01';
\r
10 XSLoader::load __PACKAGE__, $VERSION;
\r
12 my $RE_ENGINE_PLUGIN = ENGINE();
\r
14 # How many? Used to cheat %^H
\r
17 # Where we store our CODE refs
\r
20 # Generate a key to use in the %^H hash from a string, prefix the
\r
21 # package name like L<pragma> does
\r
22 my $key = sub { __PACKAGE__ . "::" . $_[0] };
\r
26 my ($pkg, %sub) = @_;
\r
29 my @callback = qw(comp exec); #intuit checkstr free dupe);
\r
32 next unless exists $sub{$_};
\r
33 my $cb = delete $sub{$_};
\r
35 unless (ref $cb eq 'CODE') {
\r
37 Carp::croak("'$_' is not CODE");
\r
41 my $id = $callback ++;
\r
43 # Insert into our callback storage,
\r
44 $callback{$_}->{$id} = $cb;
\r
46 # Instert into our cache with a key we can retrive later
\r
47 # knowing the ID in %^H and what callback we're getting
\r
48 $^H{ $key->($_) } = $id;
\r
51 $^H{regcomp} = $RE_ENGINE_PLUGIN;
\r
56 # Delete the regcomp hook
\r
58 if $^H{regcomp} == $RE_ENGINE_PLUGIN;
\r
61 # Minimal function to get CODE for a given key to be called by the
\r
62 # get_H_callback C function.
\r
65 my ($name) = @_; # 'comp', 'exec', ...
\r
67 my $h = (caller(0))[10];
\r
68 my $id = $h->{ $key->($name) };
\r
70 my $cb = defined $id ? $callback{$name}->{$id} : 0;
\r
77 my ($re, %callback) = @_;
\r
79 for my $key (keys %callback) {
\r
80 $key =~ y/a-z/A-Z/; # ASCII uc
\r
81 my $name = '_num_capture_buff_' . $key;
\r
82 $re->$name( $callback{$key} );
\r
88 my ($re, %callback) = @_;
\r
90 for my $key (keys %callback) {
\r
91 $key =~ y/a-z/A-Z/; # ASCII uc
\r
92 my $name = '_named_capture_buff_' . $key;
\r
93 $re->$name( $callback{$key} );
\r