Cheers Rob, below is the clone() from URI::WithBase
(the base class of URI::URL).
sub clone {
my $self = shift;
bless [$self->[0]->clone, $self->[0]], ref($self);
}
Which is the last package included with 'use' in my
original example piece of code, so I assume this
clone() is the prevalent version.
This is what I have as my constructor:
# *(A)*
sub new {
my($class, $init) = @_;
my $self;
if (ref $init) {
$self = $init->clone;
} else {
$self = bless {
'id' => undef,
'username' => undef,
'contents' => {},
# *(B)*
'status' => 'B',
'updated' => undef,
'created' => undef,
}, $class;
}
}
My next question is: What is the difference between
variables declared (A) outside the constructor and
those included (B) in the blessing within the
constructor?
I guess I really just don't understand the
documentation on bless, I used to do a quite bit of
C++ a few years ago and like the OO approach but Perl
is so ambiguous and cryptic at times it turns my
brain inside out.
How I understand bless is that it tells Perl to treat
an item pointed to by a ref as an object. But what
does that mean in actual terms, the access method for
package variables doesn't change.
Thanks again,
Tom Norwood.
-----Original Message-----
From: Rob Dixon [mailto:[EMAIL PROTECTED]
Sent: 12 March 2003 11:51
To: [EMAIL PROTECTED]
Subject: Re: Inheritance and clone()
David Wilson wrote:
> There is a clone module on CPAN.
>
> Take a look at it. It will do what you need.
>
Tom's original post was about how to call the 'clone'
method of a given object. His assumption was that
clone was a built-in, so he was failing to find
documentation on it. It was not a question about
how to clone an object in general.
Rob
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
This email has been scanned for viruses by NetBenefit using Sophos
anti-virus technology
This email has been scanned for viruses by NetBenefit using Sophos anti-virus
technology
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]