from my as yet uncommitted P5EEx::Black, a few simplistic
but possibly sufficient implementations that could
theoretically be added to Class::Base:

sub clone {
    my ($self) = @_;

    my $clone = bless {}, ref($self);
    for my $field (keys %$self) {
        $sclone->{$field} = $self->{$field};
    }

    return $clone;
}

sub equals {
    my ($self, $obj) = @_;

    return $self eq $obj;
}

sub to_string {
    my ($self) = @_;

    return ref($self);
}

i ignored class, since in java it returns an object of class
Class, which isn't a notion in perl - ref($self) seems
sufficient.

On Mon, 14 Jan 2002, Matt Sergeant wrote:

> On Mon, 14 Jan 2002, brian moseley wrote:
>
> > On Mon, 14 Jan 2002, Matt Sergeant wrote:
> >
> > > I was surprised by this, being an Andy Wardley module I
> > > expected it to be a lot more all encompassing (if you're
> > > listening, Hi Andy!). Whereas in fact it simply seems to
> > > create a new hashref object and call init() if it's
> > > available. That's all it does (unless I'm very much
> > > mistaken).
> >
> > there's some error handling too:
> >
> >   my $obj = My::Object->new or die "$0: whoops: " . My::Object->error;
> >
> > and there's a little bit of useful code for handling either
> > hashrefs or hashes of named args in the constructor. that's
> > code which is irritating to cut and paste over and over, to
> > be sure.
> >
> > what else would be useful but general enough? clone(),
> > equals(), to_string() come to mind..
>
> (this is based on java.lang.Object, sorry folks)
>
> equals
> class
> to_string
> clone
>
> There's some other more Java-ish stuff, but I think that'll do.
>
>

Reply via email to