in reply to Object accessors with unknown data

You could do something like this without any eval magic:
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; }
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.

Replies are listed 'Best First'.
Re^2: Object accessors with unknown data
by Anonymous Monk on Jan 26, 2015 at 11:02 UTC

    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.

    Or hes inventing a class builder, like Mo? Ha