On Thursday, Jul 24, 2003, at 21:46 US/Pacific, Camilo Gonzalez wrote: [..]
Okay, this is a beginner's list. What the hell is MVC? How do you hash an algorithm?
Great Questions!
MVC - Model,View,Controller
it is a design pattern, a way of 'looking at' the problem and understanding which parts belong where.
<http://www.google.com/search?hl=en&ie=ISO-8859- 1&q=Model%2CView%2CController&btnG=Google+Search>
specifically you might start with <http://st-www.cs.uiuc.edu/users/smarch/st-docs/mvc.html> Which while a discussion dating back to the original copyrighted date of 1987, and specifically aimed at the 'smalltalk-80' - SHOULD be reviewed in any case in which you have a 'presentation layer' - the view, that deals with the graphical stuff, a controller that deals with 'input' from the 'mouse,keyboard,etc' and a 'model' that is 'changed' in in it's behavior and/or content by the controller.
In theory 'HTML' was suppose to give us this 'common' presentation layer, and 'cgi code' would give us a common approach as to how we do the 'controller' foo.... but all too often we all collectively zone out on 'what exactly is the Model' that we are mangalating.
Too many of us have victimized ourselves by trying to wedgie it all into one thing, rather than respecting the 'differences' and so come back to the 'original solution' and find it hard to clean up what we messed up in the first place in the race to 'get the product out the door'.
So a core part of why we keep bringing it back up in groups like this is to point people in the general direction of that 'solution' - and to remind them to step back and review the basics from time to time.
As for hashing and algorithms, the idea is to remind folks that there IS more than one 'hashing algorithm', and all of that cool 'comp sci' stuff - about how to handle things like 'hashing collision' - but that while that 'intellectually coool stuff' is 'cool' at a purely pedantic level, in the cold of the middle of the night, it remains simpler to just get ANY hashing algorithm into play - and perl has done a reasonably good enough solution for most cases...
One of my pet FAVORITE tricks to use is a 'callForm' key - where I hide the next in sequence value as a 'hidden input' and then use that in the code to know which function/method to call:
if( defined($request) && $request =~ m/^POST|GET|HEAD$/) { my $queryString = ($request eq 'POST' )? <STDIN> : $ENV{'QUERY_STRING'}; my $qs = unpack_qstring_w_dupes($queryString); my $formAction = { stop => \&doDaemon, start => \&doDaemon, showOptions => \&showOptions, hqConfigd => \&showOptions }; my $callForm = $qs->{callForm} || ''; $page = ( $callForm && defined($formAction->{$callForm}) ) ? $formAction->{$callForm}->($qs) : BogusBody( $qs, "HqConfigd_Horror", "You Should Not See This" ); }
being a basic form of the solution. the kicker trick is that $formAction, which is a hash of functions references that I will ultimately call with
$formAction->{$callForm}->($qs)
Think of it as a mini 'OO' trick without the constructor.
Remember that in perl an "OO" thingie is merely a blessed reference, that returns a reference to a stack of methods and perchance some internal data stuff.
Most folks use 'hashes' solely as 'associative arrays' unlike the usual 'array' where one 'indexes' into it with an 'integer value' - a hash allows one to 'index' into the 'associative array' with a 'key value' which need not be an 'integer value' - and one leaves it up to the 'hashing algorithm' to sort out where the 'value' is for the 'key'. In this case rather than having say a 'string', we return a reference that is the 'address' of some 'function/method'...
Where this can get 'totally psycho' is out at the edge where it is faster, cheaper, and simpler to it in the form: if( defined($request) && $request =~ m/^POST|GET|HEAD$/) { my $queryString = ($request eq 'POST' )?<STDIN>:$ENV{'QUERY_STRING'};
my $query = unpack_query_string($queryString);
my $action = Wetware::Hq::URL_DB::db_get_actions(); $page = ( defined($query->{verb}) && exists( $action->{$query->{verb}})) ? $action->{$query->{verb}}->($query) : Wetware::Hq::URL_DB::Maint::check_maintenance($query); }
In this case, rather than implement the 'traditional' model of a 'perl blessed object' - as if it were 'OO' i just expressly call out a function that returns a hash of references to functions, check first to see if the one I want is there, else I invoke an alternative function that is fully qualified, that itself checks another hash of references to functions...
And since you asked, the above IS the core of the db_mgr.cgi from the piece:
Remember that:
libex: 57:] GET -S -e "http://db_host/HqDb/db_mgr.cgi?verb=get_both" ; echo ""
GET http://db_host/HqDb/db_mgr.cgi?verb=get_both --> 200 OK
Connection: close
Date: Wed, 23 Jul 2003 18:33:23 GMT
Server: Apache/2.0.45 (Unix)
Content-Length: 105
Content-Type: text/plain; charset=ISO-8859-1
Client-Date: Wed, 23 Jul 2003 18:33:23 GMT
Client-Response-Num: 1
jMan=jeeves&store2=vladimir&store3=vladimir&new_style=vladimir&vMan=vla dimir&store1=libex&store4=vladimir
libex: 58:]
conforms to the CGI spec, BUT is not returning anything that is in 'html'...
In this case I decided that I really did not need to be all that 'dynamic dispatching through a blessed reference' and figured, hey, maintaining this will be so much simpler if I simply separate the basic set of db_get_actions() from the check_maintenance() set of actions, so that I can manage the two in separate modules. The former 'class' deals with the 'do some DB query stuff' while the later deals with the traditional DB maintenance questions about how to do Import the DB, Export the DB, Compact the DB, and FSCK the DB. This way the exposed 'cgi code' that gets called is, well, just there - while the underlying DataBaseFoo is abstracted behind perl modules in this case without having to transit through the 'blessed reference'.
I bascially trust Perl's Hashing Algorithm that much.
HTH.
ciao drieux
---
Trust me, if you watch it go through the Perl Debugger you too would have faith in all of the lines of code it does not have to execute...
-- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]