in reply to RE: Automatic CODE tags
in thread Automatic CODE tags
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.
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.
A simple test would be something like:
(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.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; } } }
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.
|
---|
Replies are listed 'Best First'. | |
---|---|
RE: RE:(2) Automatic CODE tags
by Corion (Patriarch) on Jun 20, 2000 at 20:12 UTC | |
by swiftone (Curate) on Jun 20, 2000 at 20:16 UTC | |
by Corion (Patriarch) on Jun 21, 2000 at 20:01 UTC | |
by Shendal (Hermit) on Jun 21, 2000 at 20:21 UTC | |
by swiftone (Curate) on Jun 21, 2000 at 20:40 UTC | |
by Ozymandias (Hermit) on Jun 21, 2000 at 20:45 UTC | |
| |
by Corion (Patriarch) on Jun 22, 2000 at 01:39 UTC |
In Section
Perl Monks Discussion