Opinions: API wrapping, how close to original API should you stay?

Robbie Bow robbie at robbiebow.co.uk
Thu Oct 5 14:29:50 PDT 2006

> Nik Clayton wrote:

> [1] As an aside, there's quite a lot of tedious make-work code involved in 
> doing this.  Before I sit down and write one, is anyone aware of a simple 
> mechanism to take a hash and a mapping of hash keys to method names, and 
> generate a simple object from the two?

How about using Class::Accessor e.g. 

use base qw(Class::Accessor::Fast);
use strict;

	my $hash = { foo => 1,
		     bar => 2,

	$_ = "get$_" keys %$hash;

	my @methods = keys %$hash;


sub new {
	my $class = shift;
	my %hash  = @_;

	return __PACKAGE__->new(\%hash);

More information about the MiltonKeynes-pm mailing list