On Wednesday, Nov 5, 2003, at 11:55 US/Pacific, Shaun Fryer wrote: [..]
What I hoped to have happen is that if a particular sub returns
empty, undef, or void, I will have it trigger the following sub.
What I'm unsure of, is how to get the die_msg/<STDERR> to pass
to Die_Mail().
[..]
Return_Something() || Die_Mail($mail_prog,$admin_email,'???');

sub Die_Mail {
    $mail_prog  = shift || return;
    $admin_email= shift || return;
    $die_msg    = shift || return; # maybe a ref, but basics 1st
    open(OUT,"|$mail_prog") || return;
    print OUT "From: '$0' <[EMAIL PROTECTED]>\n",
              "To: $admin_email\n",
              "Subject: A CGI DIED!\n\n",
              $die_msg;
    close(OUT);
    User_HTML_Warning(); # print a default error page for users
    return true;
}
[..]

first off my complements on your Die_Mail() function, allow
me to get Fruffy if I may if it needs to have three scalars
you might want to think about the prototype solution

        sub Die_Mail($$$) {
        ....
        }

this way it will hurl a furball about wrong argument count
at compile time and should oblige you, others, to remember
to pass the three scalars, hence avoid the need for the

shift || return

approach and would allow you to do the simpler, IMMHO,

my ($mail_prog, $admin_email, $die_msg) = @_ ;

at which point I would do the User_HTML_Warning()
prior to returning if the open of the program failed.
You do have an obligation to send something back to
the web-browser, even if you can not send email to
the admin_kabal about the 'problem'.

Ob_fruffy: there are those who believe that all functions/methods
should be in lower case letters. Feel duely ob_fruffed.

That having been said, IF you are trying to trap the
'die' in the Return_Something() then you will want to
stuff the process IN an eval with a sig handler something like:

        ....
        our ($page,$h) ;
        our $wrapper_flag = 0;
        our $bytes_read = 0;

        eval {
                local $SIG{'__DIE__'} = sub { $wrapper_flag = 1;} ;
                ($bytes_read, $page, $h ) =
                        get_from_server($host_port, $uri, $q);
        };

        return({ runtime_error =>
                        "Problems connecting to $host_port got status: $@" }
           ) if ( $wrapper_flag );
                ....

No reason to make that $SIG{'__DIE__'} 'function' massive,
harry, or complex. I opted for an autonomous function, and
as you will notice it merely sets a flag which we check AFTER
the eval. The "die message" is in the $@ perl variable.

if as you origianlly were concerned you got back an of
the standard 'responses' 'empty', undef, whatEver, that
would of course be in one of the 'variables'. In my
case I was returning

        a. $bytes_read - an int count
        b. $page - the reference to the 'page of information'
        c. $h - the 'http header stuff' - since that's from a 'hey,
                let us use HTTP as our session layer to call other
                services from other web-browsers' chunk of code

This way I can also check things like what the 'status' was
returned from the remote web server, yadayadayada...

Your Mileage May Vary, void where prohibited by law,
may cause lab rats in cancer research facilities.

ciao
drieux

---


-- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]



Reply via email to