You can use the predefined ref
function:
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 -w
or use warnings
.)