From: Ævar Arnfjörð Bjarmason Date: Thu, 27 Dec 2007 22:14:00 +0000 (+0000) Subject: Importing re-engine-Plugin-0.04.tar.gz X-Git-Tag: v0.04^2 X-Git-Url: http://git.vpit.fr/?p=perl%2Fmodules%2Fre-engine-Plugin.git;a=commitdiff_plain;h=74d4856719cde7c6dc286b0c3e5dc78112d2fbff Importing re-engine-Plugin-0.04.tar.gz --- diff --git a/ChangeLog b/ChangeLog index 13757f9..d288586 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,24 +1,20 @@ -2007-05-29 Ævar Arnfjörð Bjarmason (0.04_01) +2007-12-27 Ævar Arnfjörð Bjarmason (0.04) - * Plugin.xs: Implementation of named buffer callbacks, there is - some debate about whether this patch should go into - blead so I'm making a dev release - * named_capture.patch: The patch to blead that makes this tick + * Plugin.pm: Setting @ISA instead of using base.pm + * Makefile.PL: Now using ExtUtils::MakeMaker instead of Module::Install + * Plugin.(xs|h): Fix up prototypes to match the callbacks in the actual 5.10 release * Plugin.xs: Dumped CODE: in favor of PPCODE:, the former is teh sux * Plugin.xs: Minor cleanups here and there * Plugin.pod: New todo and a developer release notice - * Plugin.h: Named buffer callbacks - * Plugin.pm: Named buffer callbacks + * Plugin.[h|pm]: Named buffer callbacks * t/methods/stash.t: Test return value of $rx->stash({}); * t/methods/str/modify.t: New test for modification of ->str when a reference is used * t/methods/str/types.t: This was testing pattern types, fixed - * t/Example.[t|pm]: Moved to t/usage - * t/named_buff: Tests for named buffer callbacks 2007-05-17 Ævar Arnfjörð Bjarmason (0.03) - + * Plugin.xs: The exec callback would call_sv on a NULL value causing a segfault * Plugin.pod: Use %hash ~~ 'i' instead of $hash{i}, more stylish! @@ -30,5 +26,5 @@ blead itself, too many changes to list 2007-02-18 Ævar Arnfjörð Bjarmason (0.01) - + * Initial release diff --git a/MANIFEST b/MANIFEST index eb36f03..f80fc2c 100644 --- a/MANIFEST +++ b/MANIFEST @@ -1,20 +1,7 @@ ChangeLog -inc/Module/AutoInstall.pm -inc/Module/Install.pm -inc/Module/Install/AutoInstall.pm -inc/Module/Install/Base.pm -inc/Module/Install/Can.pm -inc/Module/Install/Fetch.pm -inc/Module/Install/Include.pm -inc/Module/Install/Makefile.pm -inc/Module/Install/Makefile/Version.pm -inc/Module/Install/Metadata.pm -inc/Module/Install/Win32.pm -inc/Module/Install/WriteAll.pm Makefile.PL MANIFEST This list of files -META.yml -named-capture.patch +MANIFEST.SKIP Plugin.h Plugin.pm Plugin.pod @@ -35,14 +22,6 @@ t/methods/stash.t t/methods/str/modify.t t/methods/str/types.t t/methods/str/undef.t -t/named_buff/CLEAR.t -t/named_buff/DELETE.t -t/named_buff/EXISTS.t -t/named_buff/FETCH.t -t/named_buff/FIRSTKEY.t -t/named_buff/NEXTKEY.t -t/named_buff/SCALAR.t -t/named_buff/STORE.t t/num_buff/FETCH.t t/num_buff/LENGTH.t t/num_buff/STORE.t @@ -50,6 +29,7 @@ t/taint/rx.t t/taint/util.t t/usage/basic.pm t/usage/basic.t -t/usage/import.pm t/usage/import.t +t/usage/import.pm typemap +META.yml Module meta-data (added by MakeMaker) diff --git a/MANIFEST.SKIP b/MANIFEST.SKIP new file mode 100644 index 0000000..4e87d80 --- /dev/null +++ b/MANIFEST.SKIP @@ -0,0 +1,9 @@ +\.bs$ +\.c$ +\.o$ +^\.git +^blib/ +\.old$ +\.bak$ +^pm_to_blib$ +^Makefile$ \ No newline at end of file diff --git a/META.yml b/META.yml index b334027..bf4d097 100644 --- a/META.yml +++ b/META.yml @@ -1,19 +1,13 @@ ---- -abstract: API to write custom regex engines -author: 'Ævar Arnfjörð Bjarmason ' -build_requires: - Test::More: 0 -distribution_type: module -generated_by: Module::Install version 0.65 -license: perl +--- #YAML:1.0 +name: re-engine-Plugin +version: 0.04 +abstract: API to write custom regex engines +license: perl +author: + - Ævar Arnfjörð Bjarmason +generated_by: ExtUtils::MakeMaker version 6.42 +distribution_type: module +requires: meta-spec: - url: http://module-build.sourceforge.net/META-spec-v1.3.html - version: 1.3 -name: re-engine-Plugin -no_index: - directory: - - inc - - t -requires: - perl: 5.9.5 -tests: t/*.t t/*/*.t t/*/*/*.t + url: http://module-build.sourceforge.net/META-spec-v1.3.html + version: 1.3 diff --git a/Makefile.PL b/Makefile.PL index c1224f4..b527708 100644 --- a/Makefile.PL +++ b/Makefile.PL @@ -1,19 +1,13 @@ -use strict; -use inc::Module::Install; - -name 're-engine-Plugin'; - -perl_version '5.009005'; - -author 'Ævar Arnfjörð Bjarmason '; - -abstract_from 'Plugin.pod'; -license_from 'Plugin.pod'; - -# t/ -build_requires 'Test::More' => 0; # 5.007003 - -tests 't/*.t t/*/*.t t/*/*/*.t'; - -auto_install; -WriteAll; +use 5.009005; +use ExtUtils::MakeMaker; + +WriteMakefile( + NAME => 're::engine::Plugin', + AUTHOR => 'Ævar Arnfjörð Bjarmason ', + ABSTRACT_FROM => 'Plugin.pod', + VERSION_FROM => 'Plugin.pm', + LICENSE => 'perl', + test => { + TESTS => 't/*.t t/*/*.t t/*/*/*.t', + }, +); diff --git a/Plugin.h b/Plugin.h index 668aec9..1b18630 100644 --- a/Plugin.h +++ b/Plugin.h @@ -1,4 +1,3 @@ - #define GET_SELF_FROM_PPRIVATE(pprivate) \ re__engine__Plugin self; \ SELF_FROM_PPRIVATE(self,pprivate); @@ -28,22 +27,10 @@ EXTERN_C void Plugin_numbered_buff_STORE(pTHX_ REGEXP * const, const I32, SV const * const); EXTERN_C I32 Plugin_numbered_buff_LENGTH(pTHX_ REGEXP * const, const SV * const, const I32); -EXTERN_C SV * Plugin_named_buff_FETCH(pTHX_ REGEXP * const, SV * const, +EXTERN_C SV * Plugin_named_buff (pTHX_ REGEXP * const, SV * const, + SV * const, const U32); +EXTERN_C SV * Plugin_named_buff_iter (pTHX_ REGEXP * const, const SV * const, const U32); -EXTERN_C void Plugin_named_buff_STORE(pTHX_ REGEXP * const rx, - SV * const key, SV * const value, - const U32 flags); -EXTERN_C void Plugin_named_buff_DELETE(pTHX_ REGEXP * const rx, - SV * const key, const U32 flags); -EXTERN_C void Plugin_named_buff_CLEAR (pTHX_ REGEXP * const rx, const U32 flags); -EXTERN_C bool Plugin_named_buff_EXISTS (pTHX_ REGEXP * const rx, - SV * const key, const U32 flags); -EXTERN_C SV * Plugin_named_buff_FIRSTKEY (pTHX_ REGEXP * const rx, - const U32 flags); -EXTERN_C SV * Plugin_named_buff_NEXTKEY (pTHX_ REGEXP * const rx, - SV * const lastkey, const U32 flags); -EXTERN_C SV * Plugin_named_buff_SCALAR (pTHX_ REGEXP * const rx, - const U32 flags); EXTERN_C SV * Plugin_package(pTHX_ REGEXP * const); #ifdef USE_ITHREADS EXTERN_C void * Plugin_dupe(pTHX_ REGEXP * const, CLONE_PARAMS *); @@ -64,14 +51,8 @@ const regexp_engine engine_plugin = { Plugin_numbered_buff_FETCH, Plugin_numbered_buff_STORE, Plugin_numbered_buff_LENGTH, - Plugin_named_buff_FETCH, - Plugin_named_buff_STORE, - Plugin_named_buff_DELETE, - Plugin_named_buff_CLEAR, - Plugin_named_buff_EXISTS, - Plugin_named_buff_FIRSTKEY, - Plugin_named_buff_NEXTKEY, - Plugin_named_buff_SCALAR, + Plugin_named_buff, + Plugin_named_buff_iter, Plugin_package, #if defined(USE_ITHREADS) Plugin_dupe, @@ -96,18 +77,10 @@ typedef struct replug { * Callbacks */ + SV * cb_free; + /* ->num_captures */ SV * cb_num_capture_buff_FETCH; SV * cb_num_capture_buff_STORE; SV * cb_num_capture_buff_LENGTH; - - /* ->named_captures */ - SV * cb_named_capture_buff_FETCH; - SV * cb_named_capture_buff_STORE; - SV * cb_named_capture_buff_DELETE; - SV * cb_named_capture_buff_CLEAR; - SV * cb_named_capture_buff_EXISTS; - SV * cb_named_capture_buff_FIRSTKEY; - SV * cb_named_capture_buff_NEXTKEY; - SV * cb_named_capture_buff_SCALAR; } *re__engine__Plugin; diff --git a/Plugin.pm b/Plugin.pm index 80fa389..d8fa322 100644 --- a/Plugin.pm +++ b/Plugin.pm @@ -1,11 +1,13 @@ # See Plugin.pod for documentation package re::engine::Plugin; use 5.009005; -use base 'Regexp'; use strict; use XSLoader (); -our $VERSION = '0.04_01'; +our $VERSION = '0.04'; + +# All engines should subclass the core Regexp package +our @ISA = 'Regexp'; XSLoader::load __PACKAGE__, $VERSION; @@ -26,7 +28,7 @@ sub import my ($pkg, %sub) = @_; # Valid callbacks - my @callback = qw(comp exec); #intuit checkstr free dupe); + my @callback = qw(comp exec); for (@callback) { next unless exists $sub{$_}; @@ -83,15 +85,4 @@ sub num_captures } } -sub named_captures -{ - my ($re, %callback) = @_; - - for my $key (keys %callback) { - $key =~ y/a-z/A-Z/; # ASCII uc - my $name = '_named_capture_buff_' . $key; - $re->$name( $callback{$key} ); - } -} - 1; diff --git a/Plugin.pod b/Plugin.pod index 1438f64..3ae9882 100644 --- a/Plugin.pod +++ b/Plugin.pod @@ -2,11 +2,6 @@ re::engine::Plugin - API to write custom regex engines -=head1 NOTICE - -This is a B that requires a patch to blead to work, -the patch can be found in F in this distribution. - =head1 DESCRIPTION As of perl 5.9.5 it's possible to lexically replace perl's built-in @@ -229,10 +224,12 @@ name an example). =head2 named_captures -B: document +B: implement -This is implemented but not documented, see F for usage -examples. +perl internals still needs to be changed to support this but when it's +done it'll allow the binding of C<%+> and C<%-> and support the +L methods FETCH, STORE, DELETE, CLEAR, EXISTS, FIRSTKEY, +NEXTKEY and SCALAR. =head1 Tainting @@ -303,11 +300,6 @@ I =item * -Export constants defined as macros in core relevant to our interests, -e.g. PMf_ stuff and things needed by extflags. - -=item * - Engines implemented with this module don't support C and C, the appropriate parts of the C struct need to be wrapped and documented. diff --git a/Plugin.xs b/Plugin.xs index 6d003d9..5e5452a 100644 --- a/Plugin.xs +++ b/Plugin.xs @@ -67,7 +67,7 @@ Plugin_comp(pTHX_ const SV * const pattern, const U32 flags) rx->extflags = flags; /* Flags for perl to use */ rx->engine = RE_ENGINE_PLUGIN; /* Compile to use this engine */ - /* Precompiled regexp for pp_regcomp to use */ + /* Precompiled pattern for pp_regcomp to use */ rx->prelen = plen; rx->precomp = savepvn(exp, rx->prelen); @@ -216,6 +216,7 @@ Plugin_dupe(pTHX_ const REGEXP * rx, CLONE_PARAMS *param) return rx->pprivate; } + void Plugin_numbered_buff_FETCH(pTHX_ REGEXP * const rx, const I32 paren, SV * const sv) @@ -323,264 +324,17 @@ Plugin_numbered_buff_LENGTH(pTHX_ REGEXP * const rx, const SV * const sv, SV* -Plugin_named_buff_FETCH(pTHX_ REGEXP * const rx, SV * const key, U32 flags) -{ - dSP; - SV * callback; - GET_SELF_FROM_PPRIVATE(rx->pprivate); - - callback = self->cb_named_capture_buff_FETCH; - - if (callback) { - ENTER; - SAVETMPS; - - PUSHMARK(SP); - XPUSHs(rx->pprivate); - XPUSHs(SvREFCNT_inc(key)); - XPUSHs(sv_2mortal(newSViv(flags & 1 ? 1 : 0))); - PUTBACK; - - call_sv(callback, G_SCALAR); - - SPAGAIN; - - SV* ret = POPs; - SvREFCNT_inc(ret); - - PUTBACK; - FREETMPS; - LEAVE; - - return ret; - } else { - return NULL; - } -} - -void -Plugin_named_buff_STORE(pTHX_ REGEXP * const rx, SV * const key, - SV * const value, const U32 flags) -{ - dSP; - SV * callback; - GET_SELF_FROM_PPRIVATE(rx->pprivate); - - callback = self->cb_named_capture_buff_STORE; - - if (callback) { - ENTER; - SAVETMPS; - - PUSHMARK(SP); - XPUSHs(rx->pprivate); - XPUSHs(SvREFCNT_inc(key)); - XPUSHs(SvREFCNT_inc(value)); - XPUSHs(sv_2mortal(newSViv(flags))); - PUTBACK; - - call_sv(callback, G_DISCARD); - - PUTBACK; - FREETMPS; - LEAVE; - } -} - -void -Plugin_named_buff_DELETE(pTHX_ REGEXP * const rx, SV * const key, const U32 flags) -{ - dSP; - SV * callback; - GET_SELF_FROM_PPRIVATE(rx->pprivate); - - callback = self->cb_named_capture_buff_DELETE; - - if (callback) { - ENTER; - SAVETMPS; - - PUSHMARK(SP); - XPUSHs(rx->pprivate); - XPUSHs(SvREFCNT_inc(key)); - XPUSHs(sv_2mortal(newSViv(flags))); - PUTBACK; - - call_sv(callback, G_DISCARD); - - PUTBACK; - FREETMPS; - LEAVE; - } -} - -void -Plugin_named_buff_CLEAR(pTHX_ REGEXP * const rx, const U32 flags) -{ - dSP; - SV * callback; - GET_SELF_FROM_PPRIVATE(rx->pprivate); - - callback = self->cb_named_capture_buff_CLEAR; - - if (callback) { - ENTER; - SAVETMPS; - - PUSHMARK(SP); - XPUSHs(rx->pprivate); - XPUSHs(sv_2mortal(newSViv(flags))); - PUTBACK; - - call_sv(callback, G_DISCARD); - - PUTBACK; - FREETMPS; - LEAVE; - } -} - -bool -Plugin_named_buff_EXISTS(pTHX_ REGEXP * const rx, SV * const key, - const U32 flags) -{ - dSP; - SV * callback; - bool truthiness = FALSE; - GET_SELF_FROM_PPRIVATE(rx->pprivate); - - callback = self->cb_named_capture_buff_EXISTS; - - if (callback) { - ENTER; - SAVETMPS; - - PUSHMARK(SP); - XPUSHs(rx->pprivate); - XPUSHs(SvREFCNT_inc(key)); - XPUSHs(sv_2mortal(newSViv(flags))); - PUTBACK; - - call_sv(callback, G_SCALAR); - - SPAGAIN; - - SV * ret = POPs; - truthiness = SvTRUE(ret); - - PUTBACK; - FREETMPS; - LEAVE; - } - - return truthiness; -} - -SV* -Plugin_named_buff_FIRSTKEY(pTHX_ REGEXP * const rx, const U32 flags) -{ - dSP; - SV * callback; - GET_SELF_FROM_PPRIVATE(rx->pprivate); - - callback = self->cb_named_capture_buff_FIRSTKEY; - - if (callback) { - ENTER; - SAVETMPS; - - PUSHMARK(SP); - XPUSHs(rx->pprivate); - XPUSHs(sv_2mortal(newSViv(flags))); - PUTBACK; - - call_sv(callback, G_SCALAR); - - SPAGAIN; - - SV * ret = POPs; - SvREFCNT_inc(ret); - - PUTBACK; - FREETMPS; - LEAVE; - - return ret; - } else { - return NULL; - } -} - -SV* -Plugin_named_buff_NEXTKEY(pTHX_ REGEXP * const rx, SV * const lastkey, - const U32 flags) +Plugin_named_buff (pTHX_ REGEXP * const rx, SV * const key, SV * const value, + const U32 flags) { - dSP; - SV * callback; - GET_SELF_FROM_PPRIVATE(rx->pprivate); - - callback = self->cb_named_capture_buff_NEXTKEY; - - if (callback) { - ENTER; - SAVETMPS; - - PUSHMARK(SP); - XPUSHs(rx->pprivate); - XPUSHs(SvREFCNT_inc(lastkey)); - XPUSHs(sv_2mortal(newSViv(flags))); - PUTBACK; - - call_sv(callback, G_SCALAR); - - SPAGAIN; - - SV * ret = POPs; - SvREFCNT_inc(ret); - - PUTBACK; - FREETMPS; - LEAVE; - - return ret; - } else { - return NULL; - } + return NULL; } SV* -Plugin_named_buff_SCALAR(pTHX_ REGEXP * const rx, const U32 flags) +Plugin_named_buff_iter (pTHX_ REGEXP * const rx, const SV * const lastkey, + const U32 flags) { - dSP; - SV * callback; - GET_SELF_FROM_PPRIVATE(rx->pprivate); - - callback = self->cb_named_capture_buff_SCALAR; - - if (callback) { - ENTER; - SAVETMPS; - - PUSHMARK(SP); - XPUSHs(rx->pprivate); - XPUSHs(sv_2mortal(newSViv(flags))); - PUTBACK; - - call_sv(callback, G_SCALAR); - - SPAGAIN; - - SV * ret = POPs; - SvREFCNT_inc(ret); - - PUTBACK; - FREETMPS; - LEAVE; - - return ret; - } else { - return NULL; - } + return NULL; } SV* @@ -603,7 +357,7 @@ str(re::engine::Plugin self, ...) PPCODE: XPUSHs(self->str); -void +char* mod(re::engine::Plugin self, ...) PPCODE: /* /i */ @@ -713,70 +467,6 @@ PPCODE: SvREFCNT_inc(self->cb_num_capture_buff_LENGTH); } -void -_named_capture_buff_FETCH(re::engine::Plugin self, ...) -PPCODE: - if (items > 1) { - self->cb_named_capture_buff_FETCH = ST(1); - SvREFCNT_inc(self->cb_named_capture_buff_FETCH); - } - -void -_named_capture_buff_STORE(re::engine::Plugin self, ...) -PPCODE: - if (items > 1) { - self->cb_named_capture_buff_STORE = ST(1); - SvREFCNT_inc(self->cb_named_capture_buff_STORE); - } - -void -_named_capture_buff_DELETE(re::engine::Plugin self, ...) -PPCODE: - if (items > 1) { - self->cb_named_capture_buff_DELETE = ST(1); - SvREFCNT_inc(self->cb_named_capture_buff_DELETE); - } - -void -_named_capture_buff_CLEAR(re::engine::Plugin self, ...) -PPCODE: - if (items > 1) { - self->cb_named_capture_buff_CLEAR = ST(1); - SvREFCNT_inc(self->cb_named_capture_buff_CLEAR); - } - -void -_named_capture_buff_EXISTS(re::engine::Plugin self, ...) -PPCODE: - if (items > 1) { - self->cb_named_capture_buff_EXISTS = ST(1); - SvREFCNT_inc(self->cb_named_capture_buff_EXISTS); - } - -void -_named_capture_buff_FIRSTKEY(re::engine::Plugin self, ...) -PPCODE: - if (items > 1) { - self->cb_named_capture_buff_FIRSTKEY = ST(1); - SvREFCNT_inc(self->cb_named_capture_buff_FIRSTKEY); - } - -void -_named_capture_buff_NEXTKEY(re::engine::Plugin self, ...) -PPCODE: - if (items > 1) { - self->cb_named_capture_buff_NEXTKEY = ST(1); - SvREFCNT_inc(self->cb_named_capture_buff_NEXTKEY); - } - -void -_named_capture_buff_SCALAR(re::engine::Plugin self, ...) -PPCODE: - if (items > 1) { - self->cb_named_capture_buff_SCALAR = ST(1); - SvREFCNT_inc(self->cb_named_capture_buff_SCALAR); - } - void ENGINE() PPCODE: diff --git a/t/methods/stash.t b/t/methods/stash.t index 34895e2..9083263 100644 --- a/t/methods/stash.t +++ b/t/methods/stash.t @@ -21,7 +21,6 @@ use re::engine::Plugin ( my $stash = $re->stash; my $ret = $re->stash( $stash ); ok(!$ret, "stash returns no value on assignment"); - my %h = qw( 0 a 1 o 2 e 3 u ); for (keys %h) { is($h{$_}, $stash->[$_]); diff --git a/t/methods/str/modify.t b/t/methods/str/modify.t index a30d76a..0d4536f 100644 --- a/t/methods/str/modify.t +++ b/t/methods/str/modify.t @@ -14,4 +14,3 @@ my $sv = "ook"; if (\$sv =~ /pattern/) { is($sv, "eek"); } - diff --git a/t/methods/str/types.t b/t/methods/str/types.t index ed45fb1..f5064e9 100644 --- a/t/methods/str/types.t +++ b/t/methods/str/types.t @@ -18,4 +18,3 @@ my $sv; \*STDIN =~ "GLOB"; sub {} =~ "CODE"; bless({} => "main") =~ "main" -