SPUG:Object property question

Jay Scherrer jay at scherrer.com
Wed Apr 30 18:33:48 CDT 2003


I would do something like:
package Member;
sub new
{
my $this = {};
    bless $this;
    return $this;
}

sub init_newMember
{   
my $this = shift;
$this{id} = shift;
$this{FirstName} = shift;
$this{LastName} = shift;
}
1;

Then in your script:
$member = Member::new();
$id = 0;
$firstName = "John";
$lastName = "Doe";
$member->Member::init_newMember($id, $firstName, $lastName);

Course I'm just getting the hang of this too.
I've found that the line:
$member->Member::init_newMember($id, $firstName, $lastName);
passes ($member $id $firstName $lastName) to the function in that order.

Jay


On Wednesday 30 April 2003 03:24 pm, Dan Ebert wrote:
> The Setup:
>
> I'm working on a module to manage a membership database.  I have it set
> up so that there is a Member object with properties you can access like
>
> my $firstname = $member->firstname();
>
> and change with
>
> $member->firstname('new first name');
>
> etc.
>
> when a new member is created:
>
> $member->initialize(firstname => 'John',
>                     lastname  => 'Doe');
> $member->create();
>
> I insert the data into a table and get the member ID from an
> auto-incrementing field.
>
> The Question:
>
> I want to set a new property of the Member object (the ID).  So that you
> can retrieve the ID with
>
> $id = $member->id();
>
> In my module I tried:
>
> $member->{id} = $id
>
> but that didn't work.
>
> The only thing I've gotten to work is to return the object ... so that
> you call the create method like this:
>
> $member = $member->create();
>
> which seems a little awkward.
>
> Is there a better way?




More information about the spug-list mailing list