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 returns main in the first case, and so does ref. 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.
#!/usr/bin/perl
use strict;
use warnings;
use Scalar::Util 'blessed';
my $ref = bless [], "";
print ref $ref, "\n";
print blessed $ref, "\n";
__END__
Explicit blessing to '' (assuming package main) at "..." line 8.
main
main
| [reply] [d/l] |
| [reply] [d/l] |
| [reply] |
That sounds like a bug to me. Internally, all Perl strings are zero terminated, but on the language level, Perl is supposed to be better than C, and be able to deal with "\0" correctly. Here it doesn't. It seems that bless [], "\0" and bless [], "\0foo" are blessed into the same package.
| [reply] [d/l] [select] |
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.
I'm pretty sure you can bless into "" from XS code. Didn't go so far as to try it though.
| [reply] |
That's fair enough. So, how would you recommend I handle the cases I bring up?
My criteria for good software:
- Does it work?
- Can someone else come in, make a change, and be reasonably certain no bugs were introduced?
| [reply] |