my $obj1 = Person->new('riri', 12);
my $obj2 = Person->new('fifi', 11);
my $obj3 = Person->new('loulou', 10);
 
for my $obj ($obj1, $obj2, $obj3) {
	print $obj->get_name, " ",	$obj->get_age, "\n";
}
 
#---------------------------------------------------------
package Person;
use Inline C => <<'END';
typedef struct {
	char* name;
	int age;
} Person;

SV* new(char* class, char* name, int age) {
	Person* p = malloc(sizeof(Person));
	SV* obj_ref = newSViv(0);
	SV* obj = newSVrv(obj_ref, class);
	p->name = strdup(name);
	p->age = age;
	sv_setiv(obj, (IV)p);
	SvREADONLY_on(obj);
	return obj_ref;
}

char* get_name(SV* obj) {
	return ((Person*)SvIV(SvRV(obj)))->name;
}

int get_age(SV* obj) {
 return ((Person*)SvIV(SvRV(obj)))->age;
}

void DESTROY(SV* obj) {
	Person* p = (Person*)SvIV(SvRV(obj));
	free(p->name);
	free(p);
}
END
