in reply to Re: Is it ok to mix functional and oo programming in one package?
in thread Is it ok to mix functional and oo programming in one package?
There are some gotchas here.
bless { name => 'foo' }, ref($class)||$class;The ref dance is completely unnecessary. Unless you're implementing a prototype-based OO system (and the rest of the constructor suggests that you're not), drop it.
my $ref = ref $_[0]; if ($ref eq __PACKAGE__) {
This just broke inheritance. If you really need to do this check, use Scalar::Util's blessed() or reftype().
my $obj = new Foo;This syntax introduces weird parser ambiguities that often depend on the order of compilation. Stick with Foo->new().
Foo::bar($obj);This breaks inheritance.
... you can make the ref $_[0] business a little cleaner with use UNIVERSAL 'isa'...
That will break delegation and cognates and has the possibility of breaking inheritance. It may break overloading as well.
|
|---|