>>>>> On Mon, 03 Jul 2000 16:14:47 +0200, Christophe Dehaudt <[EMAIL PROTECTED]> said:Name DSLI Description Info> - contribution planning:
> 1) I already get a module that allows to Debug And Trace some perl
> code with 'programming by contract' principles. I plan to name it:
> 'Devel::Datum'. DLSI mail will follow.Could you add a few words for the archiving gremlins why you believe
Devel::Datum is a good name and how it relates to what the module
does? Thanks!
------------- ---- -------------------------------------------- -----
Devel::Datum cdpf Debugging And Tracing Ultimate Module CDE
Datum stands for 'Debugging And Tracing Ultimate Module'. It is
a
module which offers debugging and tracing facilities. It is based on
'programing by contract' principles. Thus there are some notions of
pre-condition, post-condition and assertion. It also provides the full
tracing of the data flow when entering/exiting into subroutines. That
latter functionalities has been inspired by the Devel::TraceFuncs
module (I cannot use it as is but I have duplicated some parts :( ).
example:
-----------------------------------
: # feed this into perl -*- Mode: perl -*-
'/bin/true' && eval 'exec perl -S $0 "$@"'
if $running_under_some_shell;
use Devel::Datum;
sub my_function {
DFEATURE(my $f);
my ($x, $y) = @_;
DREQUIRE($x > 0, "x must be strictly positive");
my $result = $y / sqrt($x);
DENSURE(($y * $result) >= 0, "result gets the
sign of y");
return DVAL $result;
}
DLOAD_CONFIG("debug.cf");
DFEATURE(my $f);
$x = 3;
$y = 5;
my $a = my_function($x, $y);
DTRACE("the result of f($x, $y) = ", $a);
exit;
-----------------------------------
Running the previous example will lead to the following print:
+-> global [./example:21]
| +-> main::my_function(3, 5) [./example:8]
| | Returning: 2.88675134594813 [./example:16]
| +-< main::my_function(3, 5) [./example:8]
| the result of f(3, 5) = 2.88675134594813
[./example:26]
+-< global [./example:21]
The debugging features might be dynamically customized thanks to a
debug file which records the different flag settings according to the
location of the program. For instance, we can ask for the full debug
in all part of the program except in the routine named "xyx" for which
the debug will be silent.
when defining a debug.cf file like following:
-----------------------------------
flags common {
all(yes);
trace(yes): all;
}
flags silent {
all(no);
}
default common;
routine "my_function" {
use silent;
}
-----------------------------------
(yes, there is a grammar for it, it's based on a byacc emitting Perl
code)
the new run atempt gives:
+-> global [./example:21]
| the result of f(3, 5) = 2.88675134594813
[./example:26]
+-< global [./example:21]
Upon a (post|pre|assert)-condition failure, the default is to immediately
stop the program (it can be changed by configuring flags into config
file).
Here is an example of failure (I have change the x setting to a
negative number in the previous example):
$x = -3;
$y = 5;
my $a = my_function($x, $y);
DTRACE("the result of f($x, $y) = ", $a);
it displays:
+-> global [./example:21]
| +-> main::my_function(-3, 5) [./example:8]
!! | | pre-condition failure: x must be positive (in
./example:11)
| | Dump the stack here
Stop on pre-condition failure
+-< global [./example:21]
| +-< main::my_function(-3, 5) [./example:8]
Additionaly, Devel::Datum uses the Log::Agent module (which would tend
to be the standart log module) to emit its messages. Thus, it
allows
to route the debug traces to different target (screen, file,
syslog...).
I don't think that functionnality is already existing in a so
integrated manner.
I plan to release the first version by late summer 2000.
Any comments are, of course, welcomed.
Christophe Dehaudt