in reply to Re: Problem with My New Perl Object
in thread Problem with My New Perl Object
To make even neater write:
to be able to pull off tricks like this:sub new { my $pkg = shift; return bless {}, ref $pkg || $pkg; }
use strict; use warnings; package BaseClass; sub new { my $pkg = shift; bless {}, ref $pkg || $pkg; } sub bar { $_[0]->{'BaseClass::bar'} = $_[1]; } package SubClass; our @ISA = qw/BaseClass/; package main; my $obj = SubClass->new; my $foo = $obj->new; printf "obj isa %s\nfoo isa %s\n", $obj, $foo;
Using the bless {}, ref $pkg || $pkg idiom you are writing classes that are safe to subclass.
Do have a look at Damian Conways excellent book Object Oriented Perl
Kay
In Section
Seekers of Perl Wisdom