in reply to Dynamically Creating (and Calling) Object Methods
As gaal says, you need to call the per-instance methods by accessing the elements of the hashref. If you want to install them in the class itself, do this:
foreach my $method (@method_names_from_file) { no strict 'refs'; *{"BigDB::" . $method} = sub { print "it worked!\n" }; }
That will add a new subroutine to the package's symbol table. Note that this will affect all instances of the class, even ones which were created earlier.
If you want to have unique, per-instance methods that you can call directly without peeking in the object hash-ref, one way is to use Class::Unique which was written by a really super cool dude. If you want a full-fledged, robust prototype-OO framework, check out Class::Prototyped.
|
|---|