On 01/08/2011 09:11 PM, Sean McAfee wrote: > package MyMatcher; > > my @SIMPLE_FIELDS = qw(FOO BAR BAZ BLETCH QUUX ...); > > for my $field (@SIMPLE_FIELDS) { > no strict 'refs'; > *{ "is_\L$field" } = sub { shift->_matches($field) }; > } >
class MyMatcher { for <FOO BAR BAZ BLETCH QUUX> -> $field { MyMatcher.^add_method($field, method() { self!matches($field); } ); } } The .^ means a method of the metaclass is called, here add_method Maybe you'll find http://perlgeek.de/en/article/discovering-meta-object-protocol interesting. Cheers, Moritz