Since the empty string is a valid blessed class
No, it's not. If the second argument of bless is the empty string, the thing being blessed is blessed into main
. If you turn on warnings, Perl will tell you so.
Otherwise, how would you distinguish the empty blessing from the unblessed, religious overtones notwithstanding?
That's easy. blessed
in the first case, and so does ref
returns the empty string if its argument isn't a reference - and that's never ambigious, and hence there would be any ambiguity if blessed
would do the same.
use Scalar::Util 'blessed';
my $ref = bless , "";
print ref $ref, "\n";
print blessed $ref, "\n";
Explicit blessing to '' (assuming package main) at "..." line 8.