I'd rather use 'inside-in' objects to encapsulate private data:
#!/usr/bin/perl package Foo; use Alter; use strict; sub new { my $class = shift; my $hashref = bless {}, $class; Alter::alter($hashref, {}); $hashref; } sub attr : lvalue { my $self = shift; my $attr = shift; my $ego = Alter::ego($self); if (@_) { $ego->{$attr} = shift; } $ego->{$attr}; } package main; use strict; my $foo = Foo->new(); print "\$foo is a HASH\n" if $foo->isa('HASH'); $foo->{foo} = 'bar'; $foo->attr('foo') = 'quux'; print "\$foo->{foo} = $foo->{foo}\n"; print "attr \$foo('foo') = ", $foo->attr('foo'),"\n"; __END__ $foo is a HASH $foo->{foo} = bar attr $foo('foo') = quux
The object is just a hashref. You can store anything in it, but it's private data is only accessible via its methods. See Alter.
And no, I wouldn't use source filters, except for templates, maybe.
In reply to Re: RFC: The Poor Man's Accessor Filter
by shmem
in thread RFC: The Poor Man's Accessor Filter
by rje
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |