[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

[MacPerl-AnyPerl] Problem with my First Module



Hello All,

I have decided to learn about Object Oriented Perl by writing a module.
Armed with Damien Conway's excellent book I came up with the module
STAFF::Employee. (This module, obviously, will never be placed on CPAN.)

Works sort of as expected. When I ran this little script (listed below) to
test it I received the following output:

Hughes:Elton:46885:IT1

Um, where did the 1 at the end of IT come from?

Elton

ps I am using MacPerl 5.2.0r4 on a Mac G4 using MacOs 9.0.4


__________
#!/usr/local/bin/perl -w

use strict;
use STAFF;

my ($staff) = STAFF::Employee->new("Hughes", "Elton", "46885","IT");

print $staff->print_me;

----------
package STAFF::Employee;
use strict;

sub new
{
    my ($class) = @_;
    bless {
        _lname        => $_[1],
        _fname        => $_[2],
        _empnum        => $_[3],
        _unit        => $_[4],
    }, $class;
}

sub get_lname    { $_[0]->{_lname}}
sub get_fname    { $_[0]->{_fname}}
sub get_empnum    { $_[0]->{_empnum}}
sub get_unit    { $_[0]->{_unit}}

sub set_empnum
{
    my ($self, $empnum) = @_;
    $self->{_empnum} = $empnum if $empnum;
}

sub set_unit
{
    my ($self, $unit) = @_;
    $self->{_unit} = $unit if $unit;
}

sub print_me {
    my ($self) = @_;
    
    my ($lname, $fname, $empnum, $unit);
    $lname = $self->get_lname;
    $fname = $self->get_fname;
    $empnum = $self->get_empnum;
    $unit = $self->get_unit;
    
    my $emp_data = join(':', $lname, $fname, $empnum, $unit);
    
    print $emp_data;

}

1;
__END__

=head1 NAME

STAFF::Employee - contains employee data

=head1 VERSION

This document refers to version 0.01 of STAFF::Employee,
released 09/28/2000

=head1 SYNOPSIS

    use STAFF;
    
    # Create a new STAFF::Employee object

    $staff = STAFF::Employee->new ($lname, $fname, $empnum, $unit);
    
    # Print the object - it is ':' delimited
    
    print "New Employee: $staff->print_me";
    
=head1 AUTHOR

Elton A. Hughes
ehughes@novapic.org

=head1 COPYRIGHT

Copyright (c) 2000, Elton A. Hughes. All Rights Reserved.
This module is free software. It may be used, redistributed
and/or modified under the same terms as Perl itself.
----------

=========================================================================
NOVA Career Connection                        505 W. Olive Ave. Suite 550
Elton Hughes (Information Technology)                  Sunnyvale CA 94086
Phone: 408-730-7235                                     Fax: 408-730-7643
-------------------------------------------------------------------------




==== Want to unsubscribe from this list?
==== Send mail with body "unsubscribe" to macperl-anyperl-request@macperl.org