]> git.vpit.fr Git - perl/modules/re-engine-Plugin.git/blob - Plugin.pm
Store the exec callback into the private object
[perl/modules/re-engine-Plugin.git] / Plugin.pm
1 # See Plugin.pod for documentation
2 package re::engine::Plugin;
3 use 5.009005;
4 use strict;
5
6 our ($VERSION, @ISA);
7
8 BEGIN {
9  $VERSION = '0.07';
10  # All engines should subclass the core Regexp package
11  @ISA = 'Regexp';
12  require XSLoader;
13  XSLoader::load(__PACKAGE__, $VERSION);
14 }
15
16 my $RE_ENGINE_PLUGIN = ENGINE();
17
18 sub import
19 {
20     my ($pkg, %sub) = @_;
21
22     # Valid callbacks
23     my @callback = qw(comp exec);
24
25     for (@callback) {
26         next unless exists $sub{$_};
27         my $cb = $sub{$_};
28
29         unless (ref $cb eq 'CODE') {
30             require Carp;
31             Carp::croak("'$_' is not CODE");
32         }
33     }
34
35     $^H |= 0x020000;
36
37     $^H{+(__PACKAGE__)} = _tag(@sub{@callback});
38     $^H{regcomp}        = $RE_ENGINE_PLUGIN;
39
40     return;
41 }
42
43 sub unimport
44 {
45     # Delete the regcomp hook
46     delete $^H{regcomp}
47         if $^H{regcomp} == $RE_ENGINE_PLUGIN;
48
49     delete $^H{+(__PACKAGE__)};
50
51     return;
52 }
53
54 sub num_captures
55 {
56     my ($re, %callback) = @_;
57
58     for my $key (keys %callback) {
59         $key =~ y/a-z/A-Z/; # ASCII uc
60         my $name = '_num_capture_buff_' . $key;
61         $re->$name( $callback{$key} );
62     }
63 }
64
65 1;