From: Ævar Arnfjörð Bjarmason Date: Tue, 19 Aug 2008 14:01:00 +0000 (+0000) Subject: Importing re-engine-Plugin-0.05.tar.gz X-Git-Tag: v0.05^2 X-Git-Url: http://git.vpit.fr/?a=commitdiff_plain;h=7fb1e66881f572d36b7c22624b7f09672170b990;p=perl%2Fmodules%2Fre-engine-Plugin.git Importing re-engine-Plugin-0.05.tar.gz --- diff --git a/ChangeLog b/ChangeLog index d288586..d21dd78 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2008-08-19 Ævar Arnfjörð Bjarmason (0.05) + + * Plugin.pm: dos2unix + * Plugin.xs: RT#31635: Be compatable with threaded perls + 2007-12-27 Ævar Arnfjörð Bjarmason (0.04) * Plugin.pm: Setting @ISA instead of using base.pm diff --git a/META.yml b/META.yml index bf4d097..ac404b8 100644 --- a/META.yml +++ b/META.yml @@ -1,6 +1,6 @@ --- #YAML:1.0 name: re-engine-Plugin -version: 0.04 +version: 0.05 abstract: API to write custom regex engines license: perl author: diff --git a/Plugin.pm b/Plugin.pm index d8fa322..5b84612 100644 --- a/Plugin.pm +++ b/Plugin.pm @@ -1,88 +1,88 @@ -# See Plugin.pod for documentation -package re::engine::Plugin; -use 5.009005; -use strict; -use XSLoader (); - -our $VERSION = '0.04'; - -# All engines should subclass the core Regexp package -our @ISA = 'Regexp'; - -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) = @_; - - # Valid callbacks - my @callback = qw(comp exec); - - for (@callback) { - next unless exists $sub{$_}; - my $cb = delete $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; - - # 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{regcomp} = $RE_ENGINE_PLUGIN; -} - -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; - - return $cb; -} - -sub num_captures -{ - my ($re, %callback) = @_; - - for my $key (keys %callback) { - $key =~ y/a-z/A-Z/; # ASCII uc - my $name = '_num_capture_buff_' . $key; - $re->$name( $callback{$key} ); - } -} - -1; +# See Plugin.pod for documentation +package re::engine::Plugin; +use 5.009005; +use strict; +use XSLoader (); + +our $VERSION = '0.05'; + +# All engines should subclass the core Regexp package +our @ISA = 'Regexp'; + +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) = @_; + + # Valid callbacks + my @callback = qw(comp exec); + + for (@callback) { + next unless exists $sub{$_}; + my $cb = delete $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; + + # 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{regcomp} = $RE_ENGINE_PLUGIN; +} + +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; + + return $cb; +} + +sub num_captures +{ + my ($re, %callback) = @_; + + for my $key (keys %callback) { + $key =~ y/a-z/A-Z/; # ASCII uc + my $name = '_num_capture_buff_' . $key; + $re->$name( $callback{$key} ); + } +} + +1; diff --git a/Plugin.pod b/Plugin.pod index 3ae9882..76e8b3a 100644 --- a/Plugin.pod +++ b/Plugin.pod @@ -397,7 +397,7 @@ Evar ArnfjErE Bjarmason =head1 LICENSE -Copyright 2007 Evar ArnfjErE Bjarmason. +Copyright 2007-2008 Evar ArnfjErE Bjarmason. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. diff --git a/Plugin.xs b/Plugin.xs index 5e5452a..32b2eae 100644 --- a/Plugin.xs +++ b/Plugin.xs @@ -212,7 +212,7 @@ Plugin_free(pTHX_ REGEXP * const rx) void * Plugin_dupe(pTHX_ const REGEXP * rx, CLONE_PARAMS *param) { - Perl_croak("dupe not supported yet"); + Perl_croak(aTHX_ "dupe not supported yet"); return rx->pprivate; }