http://qs321.pair.com?node_id=11123865


in reply to questions about bless's second argument

Bless is not just for constructors!

The sample code in this post Re: Use cases for 'sub Pckg::func { }' ? shows a parser for arithmetic expressions that builds a parse tree (AbstractSyntaxTree) consisting of anonymous arrays blessed into a package named for the operation it should perform. I can then get the value of the entire tree just by sending the method ->value to the head of the tree and rely on perl's polymorphism to execute the value sub in the correct package.

The sub "node" does the blessing into any requested package.

  • Comment on Re: questions about bless's second argument