From 1c27279d6b968388ffd1e153a5ef74ba8567ca80 Mon Sep 17 00:00:00 2001 From: Graham Knop Date: Fri, 5 Feb 2010 18:06:31 -0600 Subject: [PATCH] optimized macro parser for perl 5.10 --- docs/changelog/7.x.x.txt | 1 + lib/WebGUI/Macro.pm | 63 ++++++++++++++++++++++++++++------------ 2 files changed, 46 insertions(+), 18 deletions(-) diff --git a/docs/changelog/7.x.x.txt b/docs/changelog/7.x.x.txt index 77a86b116..1a21206b4 100644 --- a/docs/changelog/7.x.x.txt +++ b/docs/changelog/7.x.x.txt @@ -1,4 +1,5 @@ 7.9.0 + - added: Optimized macro parser for perl 5.10 7.8.13 - fixed #11418: confusing typ-o in gotcha diff --git a/lib/WebGUI/Macro.pm b/lib/WebGUI/Macro.pm index be83d07bf..22f65b676 100644 --- a/lib/WebGUI/Macro.pm +++ b/lib/WebGUI/Macro.pm @@ -42,25 +42,52 @@ These functions are available from this package: =cut #------------------------------------------------------------------- -my $parenthesis; -$parenthesis = qr{ - \( # Start with '(', - (?: # Followed by - (?>\\[()]) # Escaped parenthesis - | # or - (?>[^()]) # Non-parenthesis - | # or - (??{ $parenthesis }) # a balanced parenthesis block - )* # zero or more times - \) # Ending with ')' -}x; +my $macro_re; +BEGIN { + if ( eval { require 5.010 } ) { + $macro_re = eval <<'END_REGEX'; + qr{ + ( # capture #1 - entire macro call + \^ # start with carat + ([-a-zA-Z0-9_@#/*]{1,64}) # capture #2 - macro name + ( # capture #3 - parenthesis + \( # start with open parenthesis + (?: # followed by + (?> [^()] ) # non-parenthesis + | # or + (?>\\[()]) # Escaped parenthesis + | # or + (?3) # a balanced parenthesis block (recursive) + )* # zero or more times + \) # ending with closing parenthesis + )? + ; # End with a semicolon. + ) + }msx; +END_REGEX + } + else { + my $parenthesis; + $parenthesis = qr{ + \( # Start with '(', + (?: # Followed by + (?>\\[()]) # Escaped parenthesis + | # or + (?>[^()]) # Non-parenthesis + | # or + (??{ $parenthesis }) # a balanced parenthesis block + )* # zero or more times + \) # Ending with ')' + }x; -my $macro_re = qr{ - (\^ # Start with carat - ([-a-zA-Z0-9_@#/*]{1,64}) # And one or more non-macro characters -tagged- - ((??{ $parenthesis })?) # a balanced parenthesis block - ;) # End with a semicolon. -}msx; + $macro_re = qr{ + (\^ # Start with carat + ([-a-zA-Z0-9_@#/*]{1,64}) # And one or more non-macro characters -tagged- + ((??{ $parenthesis })?) # a balanced parenthesis block + ;) # End with a semicolon. + }msx; + } +} =head2 filter ( html )