File: Debug.pm

package info (click to toggle)
libalzabo-perl 0.87-1
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 1,124 kB
  • ctags: 771
  • sloc: perl: 14,590; makefile: 46
file content (104 lines) | stat: -rw-r--r-- 2,053 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
package Alzabo::Debug;

use strict;

BEGIN
{
    my %constants =
        ( SQL => 0,
          TRACE => 0,
          METHODMAKER => 0,
          REVERSE_ENGINEER => 0,
        );

    if ( $ENV{ALZABO_DEBUG} )
    {
        my %debug = map { uc $_ => 1 } split /\|/, $ENV{ALZABO_DEBUG};

        if ( $debug{ALL} )
        {
            @constants{ keys %constants } = (1) x keys %constants;
        }
        else
        {
            foreach ( grep { exists $constants{$_} } keys %debug )
            {
                $constants{$_} = $debug{$_} ? 1 : 0;
            }
        }
    }

    while ( my ($k, $v) = each %constants )
    {
        eval "use constant $k => $v";
        die $@ if $@;
    }
}


1;

__END__

=head1 NAME

Alzabo::Debug - Creates constants used to turn on debugging

=head1 SYNOPSIS

  export ALZABO_DEBUG='SQL|TRACE'

  ... load and run code using Alzabo ...

  export ALZABO_DEBUG=METHODMAKER

  ... load and run code using Alzabo ...

=head1 DESCRIPTION

This module creates constants used by other modules in order to
determine what debugging output should be generated.

The interface is currently experimental.

=head1 USAGE

Currently, the only way to turn on debugging is by setting the
C<ALZABO_DEBUG> environment variable.  This variable can contain
various flags, each separated by a pipe char (|).  Each flag turns on
different types of debugging output.

These flags B<must be set before Alzabo is loaded>, as debugging is
turned on or off through the use of constants.

The current flags are:

=over 4

=item * SQL

Generated SQL and its associated bound variables.

=item * TRACE

A stack trace will be generated any time SQL is generated.

=item * METHODMAKER

The C<Alzabo::MethodMaker> module will generate verbose output
describing the methods it is creating.

=item * REVERSE_ENGINEER

The modules involved in reverse-engineering will generate output
describing what it finds during reverse-engineering.

=item * ALL

Turn on all flags.

=back

For now, all debugging output is sent to C<STDERR>.

=cut