Home Page   the Perl Page   Programming and Computer Reviews   and Thailand Comments

Snatch Subroutines & Modules

snatch    dtd    XML examples    GUI   



Common useful routines, like Commify and the XML to HTML coversion sub, sxml2html
sxml2html came from need. The combination of HTML, XML and Perl code mushed together on a web page demands a little effort present properly. I drop an item from an XML file into this and it pretty prints it, escapes everything and does some coloring. Makes describing items much easier.

This module is for operating system independent code, do note that Snatch is intended to be OS independent, so don't put Win32 code here.


GUI, and Win32, centric code.
guiTitle sets the window title.
FindWindowByTitle returns the handle of a window with a particular title.
synch aligns the active window and the console box. At present his puts the console beneath a GUI window of the same width. Some code to keep them both on top is available.

Snatch Sub

Internal routines.


Set various $sys variables.
Fill the @links list with files to run.
Can be passed a hash, a list, or a scalar to set variables
processes @ARGV, if not then $ENV{snatch}
command line args of the form gui=GT1.pl show up as $sys{'gui'}='GT1.pl'
returns $sys{'link'}=[@l];


Optionally takes a scalar, a or a list, or something that can be split and turned into a list. The thing passed is placed on the top of the @$sys{'link'} list of things to do and will be run next.
Usually however this is called without parameters, The top link is shifted into $sys{'file'}. Resturns $sys{'file'} or undef.


Pushes a splitable string from the link method
<method>link job1.xml job2.xml job3.xml</method> onto the end of the links list.
Returns $sys{'file'}.


addMethods takes a method name and a bit of code and adds it to the %Methods hash.
So if you do:
my $Sub=sub {print "testMethods (method)\n";};
Then you can do:
<name>test adding Methods</name> <method>testMethods</method> <sub>print STDERR "testMethods (sub)\n"; undef;
</sub> <item>
The method code executes before the sub code.


These are not UNIX alarms


This processes interval, when, time, (and alarm of course).
simplest is just to alarm 30 where a bare number of seconds is indicated, but time accepts +2m, +30s, +3M just like in CGI.pm (because I stole their routine :-).
<method>alarm link doLater.xml</method> sets up to run that link later.
Anything in sub is run at the proper time.


1. Pop the top alarm off the list and put the list back
2. Set a new $sys{'alarmtime'}
3. If an interval is specified add a new alarm.
4. If when is specified check first for the keyword "online" and run any conditional code if that succeeds. So you can say:
    <when>online { return $ThingsToDo; }</when>
Just return true to continue.

5. Call addLink if a link is defined.
6. Run the sub, if any.

online is a hardwired socket call to my ISPs satellite uplink, so its fairly fast for me. You might want to change that in SnatchUtil.pm. Actually seeing if you can connect is still the best way to prove connectedness. If I can get the registry calls working this will get a change to peeking at bytes transferred as an alternative.