in reply to Re^6: Is "ref($class) || $class" a bad thing?
in thread Is "ref($class) || $class" a bad thing?
Because a common idiom used to "solve" the "class or object method?" question, can lead to odd behavior when a constructor is called as a function and not a method.
I disagree:
#!/usr/bin/perl -w use strict; use Test::More tests => 2; package Foo; sub new { my $class = shift; bless {}, $class; } sub test { 1; } package Bar; sub new { my $class = shift; $class = ref( $class ) || $class; bless {}, $class; } sub test { 1; } package main; sub test { 0; } my $foo = Foo::new(); ok( $foo->test() ); my $bar = Bar::new(); ok( $bar->test() );
That's the same behavior regardless of the "class or object?" check. This leads me to conclude that that check has no bearing on the behavior. What leads you to believe otherwise?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^8: Is "ref($class) || $class" a bad thing?
by stvn (Monsignor) on Jul 13, 2004 at 01:39 UTC |