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?
In reply to Re^7: Is "ref($class) || $class" a bad thing?
by chromatic
in thread Is "ref($class) || $class" a bad thing?
by stvn
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |