From: Vincent Pit Date: Thu, 5 Nov 2015 01:01:42 +0000 (-0200) Subject: This is 0.11 X-Git-Tag: v0.11^0 X-Git-Url: http://git.vpit.fr/?a=commitdiff_plain;h=c67a1ff2df5beee2390234f358bc4e2aefb361ed;p=perl%2Fmodules%2Fre-engine-Plugin.git This is 0.11 --- diff --git a/Changes b/Changes index 2389f84..887b767 100644 --- a/Changes +++ b/Changes @@ -1,3 +1,12 @@ +0.11 2015-11-05 01:00 UTC - Vincent Pit + + Add : It is now possible to specify a re::engine::Plugin object + destructor by passing the 'free' option either to + re::engine::Plugin->import or to $re->callbacks. + + Chg : A large chunk of boilerplate XS code, which is also used in + other XS modules, has been factored out of the main .xs file + to a collection of .h files in the xsh subdirectory. + + Fix : A couple of memory leaks have been plugged. + 0.10 2014-10-01 23:55 UTC - Vincent Pit + Fix : [RT #92118] : Testing failed with Perl 5.17.5+ The tests have been taught about perls newer than 5.18.0. diff --git a/META.json b/META.json index 8bc21a0..814e173 100644 --- a/META.json +++ b/META.json @@ -1,10 +1,11 @@ { "abstract" : "API to write custom regex engines", "author" : [ + "Ævar Arnfjörð Bjarmason ", "Vincent Pit " ], "dynamic_config" : 1, - "generated_by" : "ExtUtils::MakeMaker version 6.98, CPAN::Meta::Converter version 2.142690", + "generated_by" : "ExtUtils::MakeMaker version 7.1, CPAN::Meta::Converter version 2.150005", "license" : [ "perl_5" ], @@ -52,5 +53,6 @@ "url" : "http://git.profvince.com/?p=perl%2Fmodules%2Fre-engine-Plugin.git" } }, - "version" : "0.10" + "version" : "0.11", + "x_serialization_backend" : "JSON::PP version 2.27300" } diff --git a/META.yml b/META.yml index 16b2991..c853e8d 100644 --- a/META.yml +++ b/META.yml @@ -1,6 +1,7 @@ --- abstract: 'API to write custom regex engines' author: + - 'Ævar Arnfjörð Bjarmason ' - 'Vincent Pit ' build_requires: ExtUtils::MakeMaker: '0' @@ -9,7 +10,7 @@ build_requires: configure_requires: ExtUtils::MakeMaker: '0' dynamic_config: 1 -generated_by: 'ExtUtils::MakeMaker version 6.98, CPAN::Meta::Converter version 2.142690' +generated_by: 'ExtUtils::MakeMaker version 7.1, CPAN::Meta::Converter version 2.150005' license: perl meta-spec: url: http://module-build.sourceforge.net/META-spec-v1.4.html @@ -27,4 +28,5 @@ resources: homepage: http://search.cpan.org/dist/re-engine-Plugin/ license: http://dev.perl.org/licenses/ repository: http://git.profvince.com/?p=perl%2Fmodules%2Fre-engine-Plugin.git -version: '0.10' +version: '0.11' +x_serialization_backend: 'CPAN::Meta::YAML version 0.016' diff --git a/Plugin.pm b/Plugin.pm index ad5e219..cc6d6e7 100644 --- a/Plugin.pm +++ b/Plugin.pm @@ -6,7 +6,7 @@ use strict; our ($VERSION, @ISA); BEGIN { - $VERSION = '0.10'; + $VERSION = '0.11'; # All engines should subclass the core Regexp package @ISA = 'Regexp'; require XSLoader; diff --git a/Plugin.pod b/Plugin.pod index da70e29..04189d2 100644 --- a/Plugin.pod +++ b/Plugin.pod @@ -4,7 +4,7 @@ re::engine::Plugin - API to write custom regex engines =head1 VERSION -Version 0.10 +Version 0.11 =head1 DESCRIPTION diff --git a/README b/README index d6e4138..3f98e99 100644 --- a/README +++ b/README @@ -2,7 +2,7 @@ NAME re::engine::Plugin - API to write custom regex engines VERSION - Version 0.10 + Version 0.11 DESCRIPTION As of perl 5.9.5 it's possible to lexically replace perl's built-in @@ -38,6 +38,7 @@ CALLBACKS use re::engine::Plugin ( comp => sub {}, exec => sub {}, + free => sub {}, ); To write a custom engine which imports your functions into the caller's @@ -52,6 +53,7 @@ CALLBACKS re::engine::Plugin->import( comp => \&comp, exec => \&exec, + free => \&free, ); } @@ -60,6 +62,7 @@ CALLBACKS # Implementation of the engine sub comp { ... } sub exec { ... } + sub free { ... } 1; @@ -87,7 +90,7 @@ CALLBACKS comp => sub { my $rx = shift; croak "Your pattern is invalid" - unless $rx->pattern ~~ /pony/; + unless $rx->pattern =~ /pony/; } ); @@ -100,15 +103,21 @@ CALLBACKS pattern such as "/(/". exec - exec => sub { - my ($rx, $str) = @_; + my $ponies; + use re::engine::Plugin( + exec => sub { + my ($rx, $str) = @_; - # We always like ponies! - return 1 if $str ~~ /pony/; + # We always like ponies! + if ($str =~ /pony/) { + $ponies++; + return 1; + } - # Failed to match - return; - } + # Failed to match + return; + } + ); Called when a regex is being executed, i.e. when it's being matched against something. The scalar being matched against the pattern is @@ -119,9 +128,30 @@ CALLBACKS This callback can also be specified on an individual basis with the "callbacks" method. + free + use re::engine::Plugin( + free => sub { + my ($rx) = @_; + + say 'matched ' ($ponies // 'no') + . ' pon' . ($ponies > 1 ? 'ies' : 'y'); + + return; + } + ); + + Called when the regexp structure is freed by the perl interpreter. Note + that this happens pretty late in the destruction process, but still + before global destruction kicks in. The only argument this callback + receives is the "re::engine::Plugin" object associated with the regexp, + and its return value is ignored. + + This callback can also be specified on an individual basis with the + "callbacks" method. + METHODS str - "str" ~~ /pattern/; + "str" =~ /pattern/; # in comp/exec/methods: my $str = $rx->str; @@ -142,7 +172,7 @@ METHODS mod my %mod = $rx->mod; - say "has /ix" if %mod ~~ 'i' and %mod ~~ 'x'; + say "has /ix" if %mod =~ 'i' and %mod =~ 'x'; A key-value pair list of the modifiers the pattern was compiled with. The keys will zero or more of "imsxp" and the values will be true values @@ -195,8 +225,8 @@ METHODS given as the key by the code reference passed as the corresponding value. - The only valid key is currently "exec". See "exec" for more details - about this callback. + The only valid keys are currently "exec" and "free". See "exec" and + "free" for more details about these callbacks. num_captures $re->num_captures( @@ -274,7 +304,7 @@ TAINTING my ($re, $paren) = @_; # This is perl's engine doing the match - $str ~~ /(.*)/; + $str =~ /(.*)/; # $1 has been untainted return $1; @@ -402,7 +432,7 @@ AUTHORS LICENSE Copyright 2007,2008 Ævar Arnfjörð Bjarmason. - Copyright 2009,2010,2011,2013,2014 Vincent Pit. + Copyright 2009,2010,2011,2013,2014,2015 Vincent Pit. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.