I think that a very simple code-detection could already be sufficient. If the post contains something, which remotely resembles Perl code, and it dosenīt
contain a single CODE tag, then wrap the whole post in CODE tags.
A simple test would be something like:
if(Code-catcher-not-disabled){
foreach(@line-of_post){
if m?\</CODE\>?i{
{ last; }
eval { $_ }; #Actually something to do with Safe module
if not $@ {
$codify=1;
}
}
}
(Requires clean up, and has many efficency improvements that can be made, but you get the idea. Basically if there is a line (or we could set a tolerance level...say, 4 lines?) of code that will eval, it's likely perl code. THis would also catch someone who remembered the CODE tag, but not the closing tag.
Note: This should be done in a sandbox, such as the Safe module, but I haven't toyed with that enough to include it in this pseudocode.
Another option is to use one of the Perl Parsers out there to check syntax, but that involves more overhead. eval already does all the checking, and properly buried in a Safe, it shouldn't affect the exterior code at all.