From: Joseph F. R. <rya...@os...> - 2001-11-14 22:14:33
|
Hi. In response to Jonathan: >You don't need to change the Shebang for IIS - of course you might do if >you are running these with Apache on windows which fakes up the Unix >execvp behaviour but uses the path. Yeah, I was running Apache under windoze (I am on that boot a lot of the time because I am a Starcraft addict ;) >Bloody did! ;-} > >I have tested this code: > >#!/usr/bin/perl -w > >use strict; > >use CGI; >use CGI::Carp qw(fatalsToBrowser set_message); >use vars qw($DEBUGGING); > ># ># $DEBUGGING must be set in a BEGIN block in order to have it be set before ># the program is fully compiled. ># This should almost certainly be set to 0 when the program is 'live' ># > >BEGIN >{ > $DEBUGGING = 0; >} > >BEGIN >{ > my $error_message = sub { > my ($message ) = @_; > print "<h1>It's all gone horribly wrong</h1>"; > print $message if $DEBUGGING; > }; > > set_message($error_message); >} > > >die "Wahay!\n"; Hehe, that wasn't what you sent :) Here is what I got: >use CGI::Carp qw(fatalsToBrowser set_message); >use vars qw($DEBUGGING); >BEGIN >{ >$DEBUGGING = 1; >$error_handler = sub >{ >my ($mesg) = @_; >print "text/html\n\n"; >print "<strong>Something nasty happened</strong>"; >print "Perl said : $message" if $DEBUGGING; >} >set_message($error_handler); >} That has a few syntax errors in it, these two lines most blatently: my ($mesg) = @_; # should be: my $message = shift; since you used $message later on :) print "text/html\n\n"; #forgot Content-type:! iti sn't even needed, however... No worries, at any rate. :) I have a better idea (2 of em actually): 1: ---------- BEGIN { # **** Configuration **** # @from_date = (yyyy,mm,dd,hh,mm,ss); # Which means: (year,month,day,hour,minute,second) @from_date = (2002,9,7,0,0,0); # the default date to find the difference from $delimiter = " "; # what gets printed between output. $DEBUGGING = 1; # set to 1 to turn on debugging mode, 0 to turn it off (recommended) # **** End configuration **** eval ("use CGI::Carp qw(fatalsToBrowser)") if $DEBUGGING; ---------- This would load CGI::Carp only on demand; The user gets a standard 500 error if debugging is turned off, and fatalsToBrowser if not. However, this still suffers from the same problem as before; if there is an error in the config, the standard 500 error gets shoved out. This, however, does not: 2: ---------- use CGI::Carp qw(fatalsToBrowser set_message); BEGIN {set_message(sub{print"[Error in Script Setup Config]"})} BEGIN { # **** Configuration **** # @from_date = (yyyy,mm,dd,hh,mm,ss); # Which means: (year,month,day,hour,minute,second) @from_date = (2002,9,7,0,0,0); # the default date to find the difference from $delimiter = " "; # what gets printed between output. $DEBUGGING = 1; # set to 1 to turn on debugging mode, 0 to turn it off (recommended) # **** End configuration **** set_message(sub{print"[Error]"})if!$DEBUGGING; set_message("")if$DEBUGGING; } ---------- This will not only handle errors in the config section, but allow us to state that the error is specifically in the startup section. However, it suffers from the drawback of not using the standard 500 error. <babble type="mindless">Perhaps we could pipe in the error message from a dummy script through a system call and then... *inane babble continues*</babble> >This code is basically shorthand for a larger nicer error message that is >fit to be presented to the punters - I am waiting for someone who can be >arsed with making nice HTML to do that. Hey, I was primarily a web designer for about 6 years before moving on to grander things. What exact did you have in mind? I'm not half bad, if I do say so myself! >You need to be able to access the CVS - we can discuss working with CVS if >you are unfamiliar with this. Yeah, I haven't the slightest clue what CVS is, other than an overpriced drug store chain. I would be greatful if you were to enlighten me :) In response to Dave: >Note that I've added parens around the lists. This solves the problem >quite well. The script needs some other changes so that it doesn't cause >so many warnings when values aren't initialised, but that's an exercise >for the reader? >So, um, does someone want to make the appropriate changes to the CVS >version and announce a bug fix to Wayne? Yeah, I'll start on that tonight (plus give it a good fixen) after my calc midterm. Speaking of that... I am running a bit late, gotta go :) |