I think it's easiest to see what bless does by constructing an object and method without any module or package. Here's a bare-bones object with a single method.
# a method - get/set the value sub Foo::value () :lvalue { ${$_[0]} } # make three references to two things my ($foo, $bar) = (do { my $v = 1; \$v }) x 2; # 2 refs to same $v my $baz = do { my $v = 1; \$v }; # different $v # . . . and a fourth my $quux = bless $foo, 'Foo'; printf "\$foo\t%s\n\$bar\t%s\n\$baz\t%s\$quux\t%s\n", $foo, $bar, $baz, $quux; print 'value is ', $foo->value(), $/; $bar->value() = 10; print 'now, ', $quux->value(), $/; __END__ $foo Foo=SCALAR(0x80591e8) $bar Foo=SCALAR(0x80591e8) $baz SCALAR(0x8059248) $quux Foo=SCALAR(0x80591e8) value is 1 now, 10
Notice that $bar got blessed, too, though we didn't do a thing to $bar itself. $baz escaped, having its own thing to point to.
So, we see what bless does. It takes a reference and an identifier string, and marks what the reference points to as an object tagged by the identifier. That identifier is used in looking for methods by checking the symbol table for the tag and looking under it for subs.
After Compline,
Zaxo
In reply to Re: why "Bless" in OO Perl
by Zaxo
in thread why "Bless" in OO Perl
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |