1 package SQL::Translator::Utils;
3 # ----------------------------------------------------------------------
4 # $Id: Utils.pm,v 1.1 2003-03-12 14:17:11 dlc Exp $
5 # ----------------------------------------------------------------------
6 # Copyright (C) 2003 darren chamberlain <darren@cpan.org>
8 # This program is free software; you can redistribute it and/or
9 # modify it under the terms of the GNU General Public License as
10 # published by the Free Software Foundation; version 2.
12 # This program is distributed in the hope that it will be useful, but
13 # WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 # General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with this program; if not, write to the Free Software
19 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
21 # -------------------------------------------------------------------
24 use base qw(Exporter);
25 use vars qw($VERSION @EXPORT_OK);
30 @EXPORT_OK = ('debug');
32 # ----------------------------------------------------------------------
35 # Will send debugging messages to STDERR, if the caller's $DEBUG global
38 # This debug() function has a neat feature: Occurances of the strings
39 # PKG, LINE, and SUB in each message will be replaced with elements
42 # debug("PKG: Bad things happened on line LINE!");
46 # [SQL::Translator: Bad things happened on line 643]
48 # If called from Translator.pm, on line 643.
49 # ----------------------------------------------------------------------
51 my ($pkg, $file, $line, $sub) = caller(1);
54 return unless ${"$pkg\::DEBUG"};
62 $x =~ s/\bPKG\b/$pkg/g;
63 $x =~ s/\bLINE\b/$line/g;
64 $x =~ s/\bSUB\b/$sub/g;
65 #warn '[' . $x . "]\n";
66 print STDERR '[' . $x . "]\n";
76 SQL::Translator::Utils - SQL::Translator Utility functions
80 use SQL::Translator::Utils qw(debug);
81 debug("PKG: Bad things happened");
85 C<SQL::Translator::Utils> contains utility functions designed to be
86 used from the other modules within the C<SQL::Translator> modules.
88 No functions are exported by default.
90 =head1 EXPORTED FUNCTIONS
94 C<debug> takes 0 or more messages, which will be sent to STDERR using
95 C<warn>. Occurances of the strings I<PKG>, I<SUB>, and I<LINE>
96 will be replaced by the calling package, subroutine, and line number,
97 respectively, as reported by C<caller(1)>.
99 For example, from within C<foo> in F<SQL/Translator.pm>, at line 666:
101 debug("PKG: Error reading file at SUB/LINE");
105 [SQL::Translator: Error reading file at foo/666]
107 The entire message is enclosed within C<[> and C<]> for visual clarity
108 when STDERR is intermixed with STDOUT.