I want to check if a
use Scalar::Util qw(blessed);
defined blessed $thing && blessed $thing eq __PACKAGE__
(blessed $thing or '') eq __PACKAGE__
You can use the predefined
ref($thing) eq __PACKAGE__
That said, I think the more-permissive
isa is really better practice. You shouldn't generally need to check if an object's type is exactly something.
[…] I'm not sure if a package can legally be empty or not.
It cannot. (And incidentally, if you try to bless a reference to
'', it will actually get blessed into
main. Perl will warn you about this, provided you have