Bioperl-guts: statics

Steve Chervitz sac@neomorphic.com
Fri, 16 Jul 1999 11:44:39 -0700 (PDT)


The problem is caused by the fact that your module does not return a
true value. The last thing the compiler executes is your my
$staticVar; declaration, which returns undef (I believe).

To fix, just put the following two lines at the bottom of
AUselessObject.pm:

1;
__END__

This is standard perl module etiquette. You can add extra comments,
pod, or unused code underneath __END__ to your heart's content since
the compiler ingores anything below it.

SteveC

Kate writes:
 >   The last few days, I've tried to set up some static variables in a perl
 > module.  In the blue camel book, I've seen this done with a my declaration
 > before the first variable.   But when I do this, the use invocation from the
 > script fails.  If I comment out the variable, it completes successfully.
 > 
 >   To isolate the problem, I created a trivial module, AUselessObject that
 > inherits from Object.  I've stored it in Tools.  I also created a script,
 > NoClue.pl, that calls it from examples.  If you have the time to offer any
 > suggestions, I'd appreciate it.
 > 
 >   Thanks.
 > 
 >                                  Kate
 > #------------------------------------------------------------------------=
 > -----
 > # PACKAGE : Bio::Tools::AUselessObject.pm
 > # AUTHOR  : Katharine Lindner   ( katharine_l@hotmail.com
 > # CREATED : July, 1999
 > # REVISION: $Id: Codpn,v 1.1.1.1.8.1 1999/06/25 09:06:34 sac Exp $
 > #           =20
 > # Copyright (c) 1999 Katharine Lindner. All Rights Reserved.
 > #           This module is free software; you can redistribute it and/or =
 > 
 > #           modify it under the same terms as Perl itself.
 > #------------------------------------------------------------------------=
 > -----
 > 
 > package Bio::Tools::AUselessObject;
 > 
 > use Bio::Root::Global qw(:devel);
 > use Carp;
 > require Exporter;
 > use Bio::Root::Object;
 > 
 > @ISA =3D qw(Bio::Root::Object Exporter );
 > use strict;
 > use vars qw ($ID $VERSION);
 > 
 > 
 > #########################################################################=
 > ############
 > ##                                 CONSTRUCTOR                           =
 > 	     ##
 > #########################################################################=
 > ############
 > 
 > 
 > =3Dhead1 _initialize
 > 
 >  Title     : _initialize
 >  Usage     : n/a; automatically called by Bio::Root::Object::new()
 >  Purpose   : None
 >  Returns   : n/a
 >  Argument  : Parameters passed to new()
 >  Throws    : Exception if the pattern string (seq) is empty.
 >  Comments  :=20
 > 
 > See Also   :=20
 > 
 > =3Dcut
 > 
 > my $staticVar;
 > #----------------
 > sub _initialize {
 > #----------------
 > 
 >     my($self, @p ) =3D @_;
 > 
 >     my $make =3D $self->SUPER::_initialize(@p);  ## SAC: Added line.
 >     print "initializing AUselessObject";
 >     $make;
 > }
=========== Bioperl Project Mailing List Message Footer =======
Project URL: http://bio.perl.org
For info about how to (un)subscribe, where messages are archived, etc:
http://www.techfak.uni-bielefeld.de/bcd/Perl/Bio/vsns-bcd-perl-guts.html
====================================================================