Greetings!
With Version 2.0 of the train crew volunteer signup form program about
to go online, I am now turning my attention to Version 3.0, which will
be Done The Right Way.
To start with, I am going to create a class named Train. A train has a
name, a date, a crew call time, and a bunch of people working on it.
So I am creating a file named Train.pm. Since it's not a good idea for
users of a class to know about what's inside the class, I'll have a
bunch of accessor methods. Here's what I have so far:
#!/usr/bin/perl
use warnings;
use strict;
package Train;
require Exporter;
@ISA = qw(Exporter);
@EXPORT = qw(Load
SetName
GetName
SetDate
GetDate
SetCrewCall
GetCrewCall
AddCrewMember
GetCrewList
new);
sub new
{
my $self = {}; # $self is a reference to an anonymous, empty (for
now) hash
bless $self;
return $self;
}
sub SetName
{
my $self = shift; # This is the "%self" that is flagged as an error
$self{name} = shift;
}
I have a couple of questions.
When I run perl -c to check this, it complains that @ISA, @EXPORT and
%self are global symbols that need explicit package names. Why is
this? I haven't seen @ISA or @EXPORT qualified with package names in
any samples. What package name do I need to use? (I solved %self. It
should have been $$self{name}.)
I tried reading the perldoc pages about object-oriented programming,
perlobj and perltoot. I was surprised (to say the least) to come
across the following quote in perltoot:
"By proper design, we mean always using the two-argument form of
bless(), avoiding direct access of global data, and not exporting
anything."
But I thought exporting was how a script that uses a module knew what
the module had to offer! If I say "use Train", doesn't my Train.pm
module have to export the methods that let the train objects actually
be used? If I don't need to export methods here, when do I need to
export them?
Confusedly,
RobR
__________________________________________________
Do you Yahoo!?
Yahoo! Mail Plus - Powerful. Affordable. Sign up now.
http://mailplus.yahoo.com
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]