1 # See Plugin.pod for documentation
\r
2 package re::engine::Plugin;
\r
6 use Scalar::Util 'weaken';
\r
9 our $VERSION = '0.01';
\r
11 XSLoader::load __PACKAGE__, $VERSION;
\r
13 my $RE_ENGINE_PLUGIN = get_engine_plugin();
\r
16 # How many? Used to cheat %^H
\r
19 my @callback = qw(comp exec intuit checkstr free dupe);
\r
20 # Where we store our CODE refs
\r
25 my ($pkg, %sub) = @_;
\r
30 next unless exists $sub{$_};
\r
31 my $cb = delete $sub{$_};
\r
33 # Convert "package::sub" to CODE if it isn't CODE already
\r
34 unless (ref $cb eq 'CODE') {
\r
39 # Whine if we don't get a CODE ref or a valid package::sub name
\r
40 croak "'$_' is not CODE and neither is the *{$cb}{CODE} fallback"
\r
41 unless ref $cb eq 'CODE';
\r
44 my $id = $callback ++;
\r
46 # Insert into our callback storage,
\r
47 $callback{$_}->{$id} = $cb;
\r
49 # Weaken it so we don't end up hanging on to something the
\r
50 # caller doesn't care about anymore
\r
51 #weaken($callback{$_}->{$id}); # EEK, too weak!
\r
53 # Instert into our cache with a key we can retrive later
\r
54 # knowing the ID in %^H and what callback we're getting
\r
55 my $key = callback_key($_);
\r
59 $^H{regcomp} = $RE_ENGINE_PLUGIN;
\r
66 # Delete the regcomp hook
\r
67 delete $^H{regcomp} if $^H{regcomp} == $RE_ENGINE_PLUGIN;
\r
74 sprintf "rep_%s", $name;
\r
77 # Minimal function to be called from the XS
\r
80 my ($name) = @_; # 'comp', 'exec', ...
\r
82 my $key = callback_key($name);
\r
83 my $h = (caller(0))[10];
\r
84 my $id = $h->{$key};
\r
86 my $cb = defined $id ? $callback{$name}->{$id} : 0;
\r