in reply to Blessing into the same package in class (object) and tie contexts
Requiring users of MyPackage objects to know that the objects are hashrefs isn't good OO (no encapsulation). And dereferencing the hashref to use it as a tied hash seems convoluted and unnatural e.g. compared to an interface likemy $p = MyPackage->new(); $$p{Hello} = "world"; print $p->to_string, "\n";
i.e. in the example you've given there doesn't seem to be a case for going beyond the standard tied hash semantics.tie my %h, MyPackage; $h{Hello} = "world"; # use tied to call object methods print tied(%h)->to_string, "\n"; # -> 'Hello World'
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Blessing into the same package in class (object) and tie contexts
by ryangies (Initiate) on Mar 28, 2008 at 02:05 UTC |