It occurs to me that there is another way to attack this problem, because, well, as you say in your blogs.perl.org post, you don't want the app to die after several hours just because some unknown value has slipped in.
My idea is to imitate the taint approach. In the place where data is generated (i.e., DBI) it is flagged as maybe_unknown, then when it is used in other parts of the program the app will croak unless the flag had been removed with some check as is_unknown.
Also, this feature should be easyly disabled, so that it can be used in development but turned off in production environments.
For instance:
sub data_generator {
return maybe_unknown(@real_data); # attach maybe_unknown flag
}
sub data_processor {
for my $data (@_) {
if ($data =~ /foo/) { # in development this line croaks
# because $data may be unknown.
# Note that it will croak even when $data
# is not actually 'unknown'!
...
}
unless (is_unknown($data)) { # clears the maybe_unknown flag
if ($data =~ /foo/) { # does not croak because the maybe_unknown
# flag has already been removed from $data
...
}
}
}
sub main {
data_processor(data_generator);
}
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|