discourse-legacysite-perl/site/glist/templates/help/GT/Delay.html
2024-06-17 22:24:05 +10:00

386 lines
9.2 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::Delay - Generic delayed module loading</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>
<li><a href="#functions">FUNCTIONS</a></li>
<ul>
<li><a href="#gt__delay">GT::Delay</a></li>
</ul>
<li><a href="#caveats_and_limitations">CAVEATS and LIMITATIONS</a></li>
<li><a href="#maintainer">MAINTAINER</a></li>
<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::Delay - Generic delayed module loading</p>
<p>
</p>
<hr />
<h1><a name="synopsis">SYNOPSIS</a></h1>
<pre>
use GT::Delay;</pre>
<pre>
my $obj = GT::Delay('GT::Foo', 'HASH', foo =&gt; &quot;bar&quot;, bar =&gt; 12);</pre>
<pre>
... # time passes without using $obj</pre>
<pre>
$obj-&gt;method();</pre>
<p>
</p>
<hr />
<h1><a name="description">DESCRIPTION</a></h1>
<p>This module provides a simple way to handle delayed module loading in a fairly
generic way. Your object will only be a very lightweight GT::Delay object
until you call a method on it, at which point the desired module will be loaded,
your object will be changed into an object of the desired type.</p>
<p>
</p>
<hr />
<h1><a name="functions">FUNCTIONS</a></h1>
<p>There is only one usable function provided by this module, GT::Delay() (not
GT::Delay::Delay as this module attempts to leave the GT::Delay namespace as
empty as possible).</p>
<p>
</p>
<h2><a name="gt__delay">GT::Delay</a></h2>
<p>GT::Delay is used to create a new delayed object. It takes at least two
arguments. The first is the package to load, such as 'GT::Foo' to require
GT/Foo.pm and create a new GT::Foo object. The second is the type of blessed
data structure a 'GT::Foo' object really is. This can be one of either 'HASH',
'ARRAY', or 'SCALAR'. Any additional arguments are kept and passed in as
arguments to the <code>new()</code> method of the object when created.</p>
<p>The object type ('HASH', 'ARRAY', or 'SCALAR') is needed is to get around a
caveat of references - if $a and $b both point to the same reference, $b cannot
be changed from $a - which makes it impossible to just get a new object and
replace $_[0] with that object, because although that would change one of
either $a or $b, it wouldn't change the other and you could easily end up with
two separate objects. When a method is called, the new object is created, then
copied into the original object which is then reblessed into the desired
package. This doesn't change either $a or $b, but rather changes the reference
they point to. You have to pass the object type because the reference must be
reblessed, but the underlying data type cannot change. Unfortunately, this
approach has a few caveats of its own, listed below.</p>
<p>
</p>
<hr />
<h1><a name="caveats_and_limitations">CAVEATS and LIMITATIONS</a></h1>
<p>Modules that are created by a method other than <code>new()</code> are not supported.</p>
<p>Modules that use a namespace different from the module location are not
supported. For example, a package Foo::Bar::Blah located in Foo/Bar.pm. If
you have such a module that would benefit from delayed loading, you need to
rethink your package/filename naming scheme, or not use this module. It _is_
possible to do this with a hack such as:
<code>$INC{'Foo/Bar/Blah.pm'} = './Foo/Bar.pm';</code> - but other than for testing,
doing such a thing is strongly discouraged.</p>
<p>Objects cannot have their elements directly accessed - for example,
<code>$obj-&gt;{foo}</code>. But, since that is bad practise anyway, it isn't that much
of a limitation. That said, objects _can_ be accessed directly _after_ any
method has been called.</p>
<p>Modules that store a string or integer form of $self (GT::Config does this to
store object attributes) will not work, since the working object will not be
the same object create a new(), but rather a copy.</p>
<p>Modules with DESTROY methods that do things to references in $self (for
example, <code>delete $self-&gt;{foo}-&gt;{bar}</code> - though <code>delete
$self-E&lt;gt&gt;{foo}</code> would be safe) will most likely not work properly as the copy
is not deep - i.e. references are copied as-is.</p>
<p>Along the same lines as the previous point, the first object will be destroyed
before the first method call goes through, so modules that do things (e.g.
delete files, close filehandles, etc.) in DESTROY will most likely not work.</p>
<p>Any module that doesn't fall into any of the points above will be perfectly
well supported by this module.</p>
<p>
</p>
<hr />
<h1><a name="maintainer">MAINTAINER</a></h1>
<p>Jason Rhinelander</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: Delay.pm,v 1.4 2004/01/13 01:35:15 jagerman Exp $</p>
</body>
</html>