#!/usr/local/bin/perl # (c) 2003 Internet WorkShop use RCategories; use Mysql; use CGI qw(:cgi-lib); use CommandWeb; use AbUtils.pm; use AbStructures.pm; $debug = 1; # Top level Abra program; please keep this file clean and as high-level as possible... # we are fundamentally a user interface program, even though sometimes input may come # in the form of a file being modified that another script is watching for us # We may output live results to web, command-line or email; and may also rewrite sets of # static files # First check, how are we being run &GetEnvironment; # Now get the user inputs, whatever form they may take &GetInputs; # Look for shortcuts ; we would like to be fast &CacheShortcut && exit(1); # Not cached, we need to do work: # From the userid, the inputs & cookies, we should be able to determine our context &DetermineContext; # Once we have our context - and not before - we can try to make sense of our input &ParseInputs; # Now we can try to do what the user is asking for &ExecuteCommands; # How are we outputting the results? May depend both on environment and results themselves &DetermineOutputMethods; # Now create the output &CreateOutputs; 1; # Environment: are we running as a cgi, a mailhandler, on the command line, or from cron? # # User # # State/cookie variables: # Current_Category # Current_Item # Current_Preferences sub GetEnvironment { } # Inputs: web hash, text to parse for commands, single command, or list of modified files to check # %in # $inputtext # $inputcmd sub GetInputs { } # Cache: if this is just a request for output, and we have done it before, use the cached copy sub CacheShortcut { # is this just a simple output request? # do we have it cached? # if so, return it and exit } # Context: things we need to know in order to parse the inputs & execute the commands # user preferences from the database # active category - whether from the user default, or the current category in the environment # active item - # load rules - default commands, filters to apply sub DetermineContext { } # Parse: what is the user telling us to do # # a lot of meat goes on here, as we translate words into specific categories/items by db lookup # may apply filters # generate 'todo' list, both from user's actual commands and triggers in the database # # really this is three completely separate routines depending on the type of input sub ParseInputs { } # Execute: Most common commands are Add and Find; we default to Add on an email and Find on a web request sub ExecuteCommands { # foreach todo entry # execute command # add to list of outputs # handle errors } # OutputMethods: we might return a web page, send one or more emails, write one or more files # We need to look up the output methods from each item/category that was modified in the database sub DetermineOutputMethods { # for each modified entry or command result # lookup methods by user # add to list } # Output: now we create the actual outputs sub CreateOutput { # for each output on our list # apply template to data (check cache again?) # send output (by web, email, stdout, or file) or append to/insert into larger output file # assembly required? (create/postprocess one long web page or report from all outputs) # apply template to summary files # send output } # we're done...