I wrote Object::Adhoc recently which is pretty similar.
my $obj = object { foo => 1, bar => 2 };
Main differences are that mine doesn't work recursively, and mine also generates has_foo methods.
If you need nested objects, my solution would be to just be explicit:
my $connection = object { client => object { address => '10.0.0.1', port => 20001 }, server => object { address => '10.0.0.2', port => 25 }, }; say $connection->server->address;
As far as adding things like constructors and methods, I consider that beyond the scope of Object::Adhoc; use a proper class builder for that. Object::Adhoc is just for those cases where you want a sub to return something dict/struct-like.
object { ... } is conceptually a quote-like operator.
In reply to Re: Converting Hashes to Objects
by tobyink
in thread Converting Hashes to Objects
by haukex
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |