428 lines
		
	
	
		
			9.6 KiB
		
	
	
	
		
			HTML
		
	
	
	
	
	
			
		
		
	
	
			428 lines
		
	
	
		
			9.6 KiB
		
	
	
	
		
			HTML
		
	
	
	
	
	
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
 | 
						|
<html xmlns="http://www.w3.org/1999/xhtml">
 | 
						|
<head>
 | 
						|
<title>GT::Base - Common base module to be inherited by all classes.</title>
 | 
						|
<link rev="made" href="mailto:root@penguin.office.gossamer-threads.com" />
 | 
						|
 | 
						|
<style type="text/css">
 | 
						|
/* $MVD$:fontset("Untitled Font Set 1","ARIEL","HELVETICA","HELV","SANSERIF") */
 | 
						|
/* $MVD$:fontset("Arial","Arial") */
 | 
						|
/* $MVD$:fontset("Arial Black","Arial Black") */
 | 
						|
/* $MVD$:fontset("Algerian","Algerian") */
 | 
						|
 | 
						|
 | 
						|
body {
 | 
						|
    background-color: white;
 | 
						|
    font-family: Verdana, Arial, sans-serif;
 | 
						|
    font-size: small;
 | 
						|
    color: black;
 | 
						|
}
 | 
						|
 | 
						|
 | 
						|
p {
 | 
						|
    background-color : white;
 | 
						|
    font-family : Verdana, Arial, sans-serif;
 | 
						|
    font-size : small;
 | 
						|
    color : black;
 | 
						|
}
 | 
						|
 | 
						|
 | 
						|
h1 {
 | 
						|
    font-family : Verdana, Arial, sans-serif;
 | 
						|
    font-weight : bold;
 | 
						|
    font-size : medium;
 | 
						|
    background-color : white;
 | 
						|
    color : maroon;
 | 
						|
}
 | 
						|
 | 
						|
 | 
						|
h2 {
 | 
						|
    font-family : Verdana, Arial, sans-serif;
 | 
						|
    font-size : medium;
 | 
						|
    font-weight : bold;
 | 
						|
    color : blue;
 | 
						|
    background-color : white;
 | 
						|
}
 | 
						|
 | 
						|
 | 
						|
h3 {
 | 
						|
    font-family : Verdana, Arial, sans-serif;
 | 
						|
    font-weight : bold;
 | 
						|
    font-size : medium;
 | 
						|
    color : black;
 | 
						|
    background-color : white;
 | 
						|
}
 | 
						|
 | 
						|
 | 
						|
h4 {
 | 
						|
    font-family : Verdana, Arial, sans-serif;
 | 
						|
    font-weight : bold;
 | 
						|
    font-size : small;
 | 
						|
    color : maroon;
 | 
						|
    background-color : white;
 | 
						|
}
 | 
						|
 | 
						|
 | 
						|
h5 {
 | 
						|
    font-family : Verdana, Arial, sans-serif;
 | 
						|
    font-weight : bold;
 | 
						|
    font-size : small;
 | 
						|
    color : blue;
 | 
						|
    background-color : white;
 | 
						|
}
 | 
						|
 | 
						|
 | 
						|
h6 {
 | 
						|
    font-family : Verdana, Arial, sans-serif;
 | 
						|
    font-weight : bold;
 | 
						|
    font-size : small;
 | 
						|
    color : black;
 | 
						|
    background-color : white;
 | 
						|
}
 | 
						|
 | 
						|
 | 
						|
ul {
 | 
						|
    font-family : Verdana, Arial, sans-serif;
 | 
						|
    font-size : small;
 | 
						|
    color : black;
 | 
						|
}
 | 
						|
 | 
						|
 | 
						|
ol {
 | 
						|
    font-family : Verdana, Arial, sans-serif;
 | 
						|
    font-size : small;
 | 
						|
    color : black;
 | 
						|
}
 | 
						|
 | 
						|
 | 
						|
dl {
 | 
						|
    font-family : Verdana, Arial, sans-serif;
 | 
						|
    font-size : small;
 | 
						|
    color : black;
 | 
						|
}
 | 
						|
 | 
						|
 | 
						|
li {
 | 
						|
    font-family : Verdana, Arial, sans-serif;
 | 
						|
    font-size : small;
 | 
						|
    color : black;
 | 
						|
}
 | 
						|
 | 
						|
 | 
						|
th {
 | 
						|
    font-family : Verdana, Arial, sans-serif;
 | 
						|
    font-size : small;
 | 
						|
    color : black;
 | 
						|
}
 | 
						|
 | 
						|
 | 
						|
td {
 | 
						|
    font-family : Verdana, Arial, sans-serif;
 | 
						|
    font-size : small;
 | 
						|
    color : black;
 | 
						|
}
 | 
						|
 | 
						|
 | 
						|
dl {
 | 
						|
    font-family : Verdana, Arial, sans-serif;
 | 
						|
    font-size : small;
 | 
						|
    color : black;
 | 
						|
}
 | 
						|
 | 
						|
 | 
						|
dd {
 | 
						|
    font-family : Verdana, Arial, sans-serif;
 | 
						|
    font-size : small;
 | 
						|
    color : black;
 | 
						|
}
 | 
						|
 | 
						|
 | 
						|
dt {
 | 
						|
    font-family : Verdana, Arial, sans-serif;
 | 
						|
    font-size : small;
 | 
						|
    color : black;
 | 
						|
}
 | 
						|
 | 
						|
 | 
						|
code {
 | 
						|
    font-family : Courier;
 | 
						|
    font-size : small;
 | 
						|
    color : black;
 | 
						|
}
 | 
						|
 | 
						|
 | 
						|
pre {
 | 
						|
    font-family : Courier;
 | 
						|
    font-size : small;
 | 
						|
    color : black;
 | 
						|
}
 | 
						|
 | 
						|
.mvd-H1 {
 | 
						|
    font-family : Verdana, Arial, sans-serif;
 | 
						|
    font-weight : bold;
 | 
						|
    font-size : 14.0pt;
 | 
						|
    background-color : transparent;
 | 
						|
    background-image : none;
 | 
						|
    color : maroon;
 | 
						|
}
 | 
						|
 | 
						|
 | 
						|
.mvd-H2 {
 | 
						|
    font-family : Verdana, Arial, sans-serif;
 | 
						|
    font-size : 12.0pt;
 | 
						|
    color : blue;
 | 
						|
}
 | 
						|
 | 
						|
 | 
						|
p.indent {
 | 
						|
    font-family : "Verdana, Arial, sans-serif";
 | 
						|
    list-style-type : circle;
 | 
						|
    list-style-position : inside;
 | 
						|
    color : black;
 | 
						|
    margin-left : 16.0pt;
 | 
						|
}
 | 
						|
 | 
						|
 | 
						|
.mvd-P-indent {
 | 
						|
    font-family : Verdana, Arial, sans-serif;
 | 
						|
    list-style-type : circle;
 | 
						|
    list-style-position : inside;
 | 
						|
    color : black;
 | 
						|
    margin-left : 16.0pt;
 | 
						|
}
 | 
						|
 | 
						|
 | 
						|
pre.programlisting {
 | 
						|
    font-size : 9.0pt;
 | 
						|
    list-style-type : disc;
 | 
						|
    margin-left : 16.0pt;
 | 
						|
    margin-top : -14.0pt;
 | 
						|
}
 | 
						|
 | 
						|
 | 
						|
.mvd-PRE-programlisting {
 | 
						|
    font-size : 9.0pt;
 | 
						|
    list-style-type : disc;
 | 
						|
    margin-left : 16.0pt;
 | 
						|
    margin-top : -14.0pt;
 | 
						|
}
 | 
						|
 | 
						|
 | 
						|
.mvd-PRE {
 | 
						|
    font-size : 9.0pt;
 | 
						|
}
 | 
						|
 | 
						|
 | 
						|
p.note {
 | 
						|
    margin-left : 28.0pt;
 | 
						|
}
 | 
						|
 | 
						|
 | 
						|
.mvd-P-note {
 | 
						|
    margin-left : 28.0pt;
 | 
						|
}
 | 
						|
 | 
						|
 | 
						|
.mvd-H4 {
 | 
						|
    font-family : Verdana, Arial, sans-serif;
 | 
						|
    font-weight : normal;
 | 
						|
    font-size : 9.0pt;
 | 
						|
    color : black;
 | 
						|
    margin-left : 6.0pt;
 | 
						|
    margin-top : -14.0pt;
 | 
						|
}
 | 
						|
 | 
						|
 | 
						|
.mvd-P {
 | 
						|
    font-family : Verdana, Arial, sans-serif;
 | 
						|
    font-size : 10.0pt;
 | 
						|
    color : black;
 | 
						|
}
 | 
						|
 | 
						|
.mvd-BODY {
 | 
						|
    font-family : Verdana, Arial, sans-serif;
 | 
						|
    background-color : white;
 | 
						|
}
 | 
						|
 | 
						|
 | 
						|
p.indentnobullet {
 | 
						|
    font-family : Verdana, Arial, sans-serif;
 | 
						|
    list-style-type : none;
 | 
						|
}
 | 
						|
 | 
						|
 | 
						|
.mvd-P-indentnobullet {
 | 
						|
    font-family : Verdana, Arial, sans-serif;
 | 
						|
    list-style-type : none;
 | 
						|
}
 | 
						|
</style>
 | 
						|
 | 
						|
 | 
						|
</head>
 | 
						|
 | 
						|
<body style="background-color: white">
 | 
						|
 | 
						|
<p><a name="__index__"></a></p>
 | 
						|
<!-- INDEX BEGIN -->
 | 
						|
 | 
						|
<ul>
 | 
						|
 | 
						|
	<li><a href="#name">NAME</a></li>
 | 
						|
	<li><a href="#synopsis">SYNOPSIS</a></li>
 | 
						|
	<li><a href="#description">DESCRIPTION</a></li>
 | 
						|
	<ul>
 | 
						|
 | 
						|
		<li><a href="#debugging">Debugging</a></li>
 | 
						|
		<li><a href="#error_handling">Error Handling</a></li>
 | 
						|
		<li><a href="#error_trapping">Error Trapping</a></li>
 | 
						|
		<li><a href="#stack_trace">Stack Trace</a></li>
 | 
						|
		<li><a href="#accessor_methods">Accessor Methods</a></li>
 | 
						|
		<li><a href="#parameter_parsing">Parameter Parsing</a></li>
 | 
						|
	</ul>
 | 
						|
 | 
						|
	<li><a href="#copyright">COPYRIGHT</a></li>
 | 
						|
	<li><a href="#version">VERSION</a></li>
 | 
						|
</ul>
 | 
						|
<!-- INDEX END -->
 | 
						|
 | 
						|
<hr />
 | 
						|
<p>
 | 
						|
</p>
 | 
						|
<h1><a name="name">NAME</a></h1>
 | 
						|
<p>GT::Base - Common base module to be inherited by all classes.</p>
 | 
						|
<p>
 | 
						|
</p>
 | 
						|
<hr />
 | 
						|
<h1><a name="synopsis">SYNOPSIS</a></h1>
 | 
						|
<pre>
 | 
						|
    use GT::Base;
 | 
						|
    use vars qw/@ISA $ATTRIBS $ERRORS/
 | 
						|
    @ISA     = qw/GT::Base/;
 | 
						|
    $ATTRIBS = {
 | 
						|
        accessor  => default,
 | 
						|
        accessor2 => default,
 | 
						|
    };
 | 
						|
    $ERRORS = {
 | 
						|
        BADARGS => "Invalid argument: %s passed to subroutine: %s",
 | 
						|
    };</pre>
 | 
						|
<p>
 | 
						|
</p>
 | 
						|
<hr />
 | 
						|
<h1><a name="description">DESCRIPTION</a></h1>
 | 
						|
<p>GT::Base is a base class that is used to provide common error handling,
 | 
						|
debugging, creators and accessor methods.</p>
 | 
						|
<p>To use GT::Base, simply make your module inherit from GT::Base. That
 | 
						|
will provide the following functionality:</p>
 | 
						|
<p>
 | 
						|
</p>
 | 
						|
<h2><a name="debugging">Debugging</a></h2>
 | 
						|
<p>Two new methods are available for debugging:</p>
 | 
						|
<pre>
 | 
						|
    $self->debug($msg, [DEBUG_LEVEL]);</pre>
 | 
						|
<p>This will send a $msg to STDERR if the current debug level is greater
 | 
						|
then the debug level passed in (defaults to 1).</p>
 | 
						|
<pre>
 | 
						|
    $self->debug_level(DEBUG_LEVEL);
 | 
						|
    Class->debug_level(DEBUG_LEVEL);</pre>
 | 
						|
<p>You can call <code>debug_level()</code> to set or get the debug level. It can
 | 
						|
be set per object by calling it as an object method, or class wide
 | 
						|
which will initilize all new objects with that debug level (only if
 | 
						|
using the built in creator).</p>
 | 
						|
<p>The debugging uses a package variable:</p>
 | 
						|
<pre>
 | 
						|
    $Class::DEBUG = 0;</pre>
 | 
						|
<p>and assumes it exists.</p>
 | 
						|
<p>
 | 
						|
</p>
 | 
						|
<h2><a name="error_handling">Error Handling</a></h2>
 | 
						|
<p>Your object can now generate errors using the method:</p>
 | 
						|
<pre>
 | 
						|
    $self->error(CODE, LEVEL, [args]);</pre>
 | 
						|
<p>CODE should be a key to a hash of error codes to user readable
 | 
						|
error messages. This hash should be stored in $ERRORS which is
 | 
						|
defined in your pacakge, or the package named in $ERROR_MESSAGE.</p>
 | 
						|
<p>LEVEL should be either 'FATAL' or 'WARN'. If not specified it defaults
 | 
						|
to FATAL. If it's a fatal error, the program will print the message
 | 
						|
to STDERR and die.</p>
 | 
						|
<p>args can be used to format the error message. For instance, you can
 | 
						|
defined commonly used errors like:</p>
 | 
						|
<pre>
 | 
						|
    CANTOPEN => "Unable to open file: '%s': %s"</pre>
 | 
						|
<p>in your $ERRORS hash. Then you can call error like:</p>
 | 
						|
<pre>
 | 
						|
    open FILE, "somefile.txt"
 | 
						|
        or return $self->error(CANTOPEN => FATAL => "somefile.txt", "$!");</pre>
 | 
						|
<p>The error handler will format your message using sprintf(), so all
 | 
						|
regular printf formatting strings are allowed.</p>
 | 
						|
<p>Since errors are kept within an array, too many errors can pose a
 | 
						|
memory problem. To clear the error stack simply call:</p>
 | 
						|
<pre>
 | 
						|
    $self->clear_errors();</pre>
 | 
						|
<p>
 | 
						|
</p>
 | 
						|
<h2><a name="error_trapping">Error Trapping</a></h2>
 | 
						|
<p>You can specify at run time to trap errors.</p>
 | 
						|
<pre>
 | 
						|
    $self->catch_errors(\&code_ref);</pre>
 | 
						|
<p>which sets a $SIG{__DIE__} handler. Any fatal errors that occur, will
 | 
						|
run your function. The function will not be run if the fatal was thrown
 | 
						|
inside of an eval though.</p>
 | 
						|
<p>
 | 
						|
</p>
 | 
						|
<h2><a name="stack_trace">Stack Trace</a></h2>
 | 
						|
<p>You can print out a stack trace at any time by using:</p>
 | 
						|
<pre>
 | 
						|
    $self->stack_trace(1);
 | 
						|
    Class->stack_trace(1);</pre>
 | 
						|
<p>If you pass in 1, the stack trace will be returned as a string, otherwise
 | 
						|
it will be printed to STDOUT.</p>
 | 
						|
<p>
 | 
						|
</p>
 | 
						|
<h2><a name="accessor_methods">Accessor Methods</a></h2>
 | 
						|
<p>Using GT::Base automatically provides accessor methods for all your
 | 
						|
attributes. By specifying:</p>
 | 
						|
<pre>
 | 
						|
    $ATTRIBS = {
 | 
						|
        attrib => 'default',
 | 
						|
        ...
 | 
						|
    };</pre>
 | 
						|
<p>in your package, you can now call:</p>
 | 
						|
<pre>
 | 
						|
    my $val = $obj->attrib();
 | 
						|
    $obj->attrib($set_val);</pre>
 | 
						|
<p>to set and retrieve the attributes for that value.</p>
 | 
						|
<p>Note: This uses AUTOLOAD, so if you implement AUTOLOAD in your package,
 | 
						|
you must have it fall back to GT::Base::AUTOLOAD if it fails. This
 | 
						|
can be done with:</p>
 | 
						|
<pre>
 | 
						|
    AUTOLOAD {
 | 
						|
        ...
 | 
						|
        goto &GT::Base::AUTOLOAD;
 | 
						|
    }</pre>
 | 
						|
<p>which will pass all arguments as well.</p>
 | 
						|
<p>
 | 
						|
</p>
 | 
						|
<h2><a name="parameter_parsing">Parameter Parsing</a></h2>
 | 
						|
<p>GT::Base also provides a method to parse parameters. In your methods you
 | 
						|
can do:</p>
 | 
						|
<pre>
 | 
						|
    my $self = shift;
 | 
						|
    my $parm = $self->common_param(@_);</pre>
 | 
						|
<p>This will convert any of a hash reference, hash or CGI object into a hash
 | 
						|
reference.</p>
 | 
						|
<p>
 | 
						|
</p>
 | 
						|
<hr />
 | 
						|
<h1><a name="copyright">COPYRIGHT</a></h1>
 | 
						|
<p>Copyright (c) 2004 Gossamer Threads Inc.  All Rights Reserved.
 | 
						|
<a href="http://www.gossamer-threads.com/">http://www.gossamer-threads.com/</a></p>
 | 
						|
<p>
 | 
						|
</p>
 | 
						|
<hr />
 | 
						|
<h1><a name="version">VERSION</a></h1>
 | 
						|
<p>Revision: $Id: Base.pm,v 1.132 2005/06/22 19:59:25 jagerman Exp $</p>
 | 
						|
 | 
						|
</body>
 | 
						|
 | 
						|
</html>
 |