Log in |
Using a Script (Perl)Note: This is currently unfinished. A Script (Perl) has been designed to look and feel very similar to a python script. Basically you can write Perl directly TTW and call it like any other object. Important Note
Example 1: self Arguments: self Click "edit" to save the code and "Try it" to run. If when clicking the "edit" button you get the message: "Global symbol "$self" requires explicit package name at test line 3.", this means you did not enter self as an argument in the box. When you click "Try it" you will note that you get a message: "self: Provided by Zope's ZPublisher internally ". This is roughly the methods container (thats why this listing includes the method). Click execute to run, you should then get a listing of the objects in your directory. Notes:
Example 2: subs, passing arguments Arguments: self You can happily define subs within a Script, such as "sub search". Here we also pass through a reference to an array containing the objects we want to list. Urlify
Example 3: something useful Arguments: data Code:my $urls = '(http|telnet|gopher|file|wais|ftp|mailto)'; my $ltrs = '\w'; my $gunk = '/#~:.?+=&%@!\-'; my $punc = '.:?\-'; my $any = "${ltrs}${gunk}${punc}"; $data =~ s{ \b # start at word boundary ( # begin $1 { $urls : # need resource and a colon [$any] +? # followed by on or more # of any valid character, but # be conservative and take only # what you need to.... ) # end $1 } (?= # look-ahead non-consumptive assertion [$punc]* # either 0 or more punctuation [^$any] # followed by a non-url char | # or else $ # then end of the string ) }{$1}igox; return $data; When you run it, give data a value containing a URL eg: activestate is at http://www.activestate.com. The regex urlify's the code. Passing arguments There are several ways to do it that defer from a more traditional DTML style. Firstly an internal perl is running in strict mode so you must declare your variables with a my, except for ones you are passing, place the variables you are passing in the arguments section. For example in the above example it is looking for data as an argument this can be passed in the following ways: http://www.foo.com/urlify?data=sampletext <dtml-var "urlify('this is the text')"> <dtml-var "urlify(data)"> # where data is in the REQUEST from a POST or other action. |