X-Git-Url: http://git.vpit.fr/?a=blobdiff_plain;f=Plugin.pm;h=ef2dbaea34c38939567c31373fb19bd94c5659ef;hb=47afe57f6afc7b312d1da725bb38f99ae70b157a;hp=b703a0005e9bcc9dd3e5fcf4282c742062f3e387;hpb=de28b8b2f575972f4c8ccb7f037db6f3b38860cf;p=perl%2Fmodules%2Fre-engine-Plugin.git diff --git a/Plugin.pm b/Plugin.pm index b703a00..ef2dbae 100644 --- a/Plugin.pm +++ b/Plugin.pm @@ -2,27 +2,19 @@ package re::engine::Plugin; use 5.009005; use strict; -use XSLoader (); -our $VERSION = '0.07'; +our ($VERSION, @ISA); -# All engines should subclass the core Regexp package -our @ISA = 'Regexp'; - -XSLoader::load __PACKAGE__, $VERSION; +BEGIN { + $VERSION = '0.07'; + # All engines should subclass the core Regexp package + @ISA = 'Regexp'; + require XSLoader; + XSLoader::load(__PACKAGE__, $VERSION); +} my $RE_ENGINE_PLUGIN = ENGINE(); -# How many? Used to cheat %^H -my $callback = 1; - -# Where we store our CODE refs -my %callback; - -# Generate a key to use in the %^H hash from a string, prefix the -# package name like L does -my $key = sub { __PACKAGE__ . "::" . $_[0] }; - sub import { my ($pkg, %sub) = @_; @@ -32,25 +24,20 @@ sub import for (@callback) { next unless exists $sub{$_}; - my $cb = delete $sub{$_}; + my $cb = $sub{$_}; unless (ref $cb eq 'CODE') { require Carp; Carp::croak("'$_' is not CODE"); } + } - # Get an ID to use - my $id = $callback ++; - - # Insert into our callback storage, - $callback{$_}->{$id} = $cb; + $^H |= 0x020000; - # Instert into our cache with a key we can retrive later - # knowing the ID in %^H and what callback we're getting - $^H{ $key->($_) } = $id; - } + $^H{+(__PACKAGE__)} = _tag(@sub{@callback}); + $^H{regcomp} = $RE_ENGINE_PLUGIN; - $^H{regcomp} = $RE_ENGINE_PLUGIN; + return; } sub unimport @@ -58,20 +45,10 @@ sub unimport # Delete the regcomp hook delete $^H{regcomp} if $^H{regcomp} == $RE_ENGINE_PLUGIN; -} - -# Minimal function to get CODE for a given key to be called by the -# get_H_callback C function. -sub _get_callback -{ - my ($name) = @_; # 'comp', 'exec', ... - - my $h = (caller(0))[10]; - my $id = $h->{ $key->($name) }; - my $cb = defined $id ? $callback{$name}->{$id} : 0; + delete $^H{+(__PACKAGE__)}; - return $cb; + return; } sub num_captures