yikes, i have to resort to them whenever i want to have "generic" logi
+c that deals with a multitude of routines.
i use symbolic references for :
object methods
dispatch tables
and in most unit test scripts
If you have a better alternative; i'll consider it!
object methods :
i use anonmyous routines for the methods that deal with scalar attributes.
package <>;
our $scalarMethods;
@{ $scalarMethods } = qw( name );
foreach my $attributeScalar ( @{ $scalarMethods } ) {
no strict "refs";
*$attributeScalar = sub {
my $subName = $package . "::$attributeScalar";
if ($VRB) { print " $subName \n"; }
my ($self) = shift;
if (@_) { $self->{$attributeScalar} = shift; }
return $self->{$attributeScalar};
}
}
dispatch tables : a generic manner to call routines in a package
for ( $ndx=0; $ndx<=0; $ndx++ ) {
no strict 'refs';
($kgDATA,$pmDATA) = &{ "cktTmplt_utils::$SUB" }($ndx );
unit test scripts : within the <>.t script
# are package variables accessible ?
no strict "refs";
foreach my $pkg ( @{ $filePackages } ) {
for ( my $i=0; $i<=1; $i++ ) {
${ $pkg . "::VRB" } = $i;
is( $i, ${ $pkg . "::VRB" }, "GLBL VAR : VRB" );
${ $pkg . "::TST" } = $i;
is( $i, ${ $pkg . "::TST" }, "GLBL VAR : TST" );
}
${ $pkg . "::VRB" } = 1; # no STDOUT durings tests
${ $pkg . "::TST" } = 1; # return data and don't execute
}
use strict "refs";
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.