in reply to How to morph a plain module to OO

What you're doing will work, but storing the class name in each instance is overkill.
sub isFile { my $self = shift if ref $_[0] && ref $_[0] eq $_[0]->{class}; my $file = shift; # a file in current directory expected
is still going to break if someone passes a reference argument that isn't an instance of the class. ($file will end up holding the errant reference.) You might as well just do
sub isFile { my $self = shift if ref $_[0]; my $file = shift;

Replies are listed 'Best First'.
Re: Re: How to morph a plain module to OO
by sauoq (Abbot) on Sep 07, 2002 at 19:22 UTC
    . . .is still going to break if someone passes a reference argument that isn't an instance of the class.

    At least it will break in the same way that it used to break if someone passed a reference. Unless, of course, that reference isn't a hash reference. Or even if it is a hash reference, it is running with warnings enabled and the referenced hash doesn't have a class key...

    *shiver*

    -sauoq
    "My two cents aren't worth a dime.";