in reply to Object accessors with unknown data
But I'd suggest you don't. Classes like this are usually a sign of a problem that's either not analyzed properly or that doesn't benefit from solving it in an OO way. In any case it doesn't exactly make your program easier to understand or debug.my $o = Anything->new(qw/foo bar baz/); $o->bar; package Anything; use strict; use warnings; sub new { my ($class, @methods) = @_; my $self = bless {}, $class; for my $method (@methods) { no strict 'refs'; *$method = sub { print "this is method $method\n" }; } return $self; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Object accessors with unknown data
by Anonymous Monk on Jan 26, 2015 at 11:02 UTC |