File: Debug.pm

package info (click to toggle)
libtest-unit-perl 0.27-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,312 kB
  • sloc: perl: 4,297; makefile: 5
file content (118 lines) | stat: -rw-r--r-- 1,824 bytes parent folder | download | duplicates (6)
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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
package Test::Unit::Debug;

=head1 NAME

Test::Unit::Debug - framework debugging control

=head1 SYNOPSIS

    package MyRunner;

    use Test::Unit::Debug qw(debug_to_file debug_pkg);

    debug_to_file('foo.log');
    debug_pkg('Test::Unit::TestCase');

=cut

use strict;

use base 'Exporter';
use vars qw(@EXPORT_OK);
@EXPORT_OK = qw(debug debug_to_file
                debug_pkg no_debug_pkg debug_pkgs no_debug_pkgs debugged);

my %DEBUG = ();
my $out = \*STDERR;

=head1 ROUTINES

=head2 debug_to_file($file)

Switch debugging to C<$file>.

=cut

sub debug_to_file {
    my ($file) = @_;
    open(DEBUG, ">$file") or die "Couldn't open $file for writing";
    $out = \*DEBUG;
}

=head2 debug_to_stderr()

Switch debugging to STDERR (this is the default).

=cut

sub debug_to_stderr {
    $out = \*STDERR;
}

sub debug {
    my ($package, $filename, $line) = caller();
    print $out @_ if $DEBUG{$package};
}

=head2 debug_pkg($pkg)

Enable debugging in package C<$pkg>.

=cut

sub debug_pkg {
    $DEBUG{$_[0]} = 1;
}

=head2 debug_pkgs(@pkgs)

Enable debugging in the packages C<@pkgs>.

=cut

sub debug_pkgs {
    $DEBUG{$_} = 1 foreach @_;
}

=head2 debug_pkg($pkg)

Enable debugging in package C<$pkg>.

=cut

sub no_debug_pkg {
    $DEBUG{$_[0]} = 0;
}

=head2 debug_pkgs(@pkgs)

Disable debugging in the packages C<@pkgs>.

=cut

sub no_debug_pkgs {
    $DEBUG{$_} = 0 foreach @_;
}

sub debugged {
    my ($package, $filename, $line) = caller();
    return $DEBUG{$_[0] || $package};
}


=head1 AUTHOR

Copyright (c) 2000-2002, 2005 the PerlUnit Development Team
(see L<Test::Unit> or the F<AUTHORS> file included in this
distribution).

All rights reserved. This program is free software; you can
redistribute it and/or modify it under the same terms as Perl itself.

=head1 SEE ALSO

L<Test::Unit>

=cut

1;