X-Git-Url: http://git.vpit.fr/?p=perl%2Fmodules%2Fre-engine-Plugin.git;a=blobdiff_plain;f=Plugin.pod;h=98633c4fadebf42436e1c8f1643fbb46da846336;hp=ea371cda66b2f691e797ccf251a6967d83a3bfee;hb=HEAD;hpb=1fc6cd8f496c252e5a93fbde4ee8ee02bfc30c17 diff --git a/Plugin.pod b/Plugin.pod index ea371cd..98633c4 100644 --- a/Plugin.pod +++ b/Plugin.pod @@ -4,7 +4,7 @@ re::engine::Plugin - API to write custom regex engines =head1 VERSION -Version 0.09 +Version 0.12 =head1 DESCRIPTION @@ -45,6 +45,7 @@ key-value pairs of names and subroutine references: use re::engine::Plugin ( comp => sub {}, exec => sub {}, + free => sub {}, ); To write a custom engine which imports your functions into the @@ -59,6 +60,7 @@ caller's scope use use the following snippet: re::engine::Plugin->import( comp => \&comp, exec => \&exec, + free => \&free, ); } @@ -67,6 +69,7 @@ caller's scope use use the following snippet: # Implementation of the engine sub comp { ... } sub exec { ... } + sub free { ... } 1; @@ -96,7 +99,7 @@ not be trapped by an C block that the pattern is in, i.e. comp => sub { my $rx = shift; croak "Your pattern is invalid" - unless $rx->pattern ~~ /pony/; + unless $rx->pattern =~ /pony/; } ); @@ -110,15 +113,21 @@ invalid pattern such as C. =head2 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 @@ -129,11 +138,33 @@ successful, and a false one if it wasn't. This callback can also be specified on an individual basis with the L method. +=head2 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 C object associated +with the regexp, and its return value is ignored. + +This callback can also be specified on an individual basis with the +L method. + =head1 METHODS =head2 str - "str" ~~ /pattern/; + "str" =~ /pattern/; # in comp/exec/methods: my $str = $rx->str; @@ -156,7 +187,7 @@ hashrefs, objects, etc. =head2 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 C and the values will be true @@ -213,8 +244,8 @@ Takes a list of key-value pairs of names and subroutines, and replace the callback currently attached to the regular expression for the type given as the key by the code reference passed as the corresponding value. -The only valid key is currently C. See L for more details about -this callback. +The only valid keys are currently C and C. See L and +L for more details about these callbacks. =head2 num_captures @@ -301,7 +332,7 @@ callbacks: my ($re, $paren) = @_; # This is perl's engine doing the match - $str ~~ /(.*)/; + $str =~ /(.*)/; # $1 has been untainted return $1; @@ -457,7 +488,7 @@ Vincent Pit C<< >> Copyright 2007,2008 Evar ArnfjErE 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.