4 ms·
This looks more like perl scripting than perl programming. If I put all those functions into a class and then called $class_object->can($method), I get the sam
by Xurinos 16y ago
This looks more like perl scripting than perl programming.
If I put all those functions into a class and then called $class_object->can($method), I get the same effect, only without the crazy hash. Perl has built-in dispatching.
I can add new methods to my perl classes at any time. Better yet, if I do it all with Class::MOP (and/or Moose), I can make it cleaner, since then I can choose to add methods to the object vs the whole class. In addition, my "dispatch tables" get the potential benefits of inheritance, roles, and other abstraction tools.
It might be a good starting exercise in rolling your own dispatch tables, but you would probably get a lot more out of reading Art of the Metaobject Protocol and trying to implement a good class system (aka reimplement Moose).
- f00li5h 16y agoI did cover "with some objects" ... although it was far from a complete treatment of all the things one can do with an object system, that's for sure. I'm really not sure what the difference between "scripting" and "programming" is ... could you point me at a rant on the topic?
- imd 16y agohttp://www.perl.com/pub/2007/12/06/soto-11.html http://www.perl.com/pub/2007/12/06/soto-11.html
- phaylon 16y agoAlso note that if you need more power than string dispatch and are already using Moose, there are match_on_type[1], MooseX-Types-VariantTable[2] and MooseX-MultiMethods[3] that already go a long way. [1] http://search.cpan.org/dist/Moose/lib/Moose/Util/TypeConstraints.pm#Type_Constraint_Utilities http://search.cpan.org/dist/Moose/lib/Moose/Util/TypeConstra... [2] http://search.cpan.org/dist/MooseX-Types-VariantTable/ http://search.cpan.org/dist/MooseX-Types-VariantTable/ [3] http://search.cpan.org/dist/MooseX-MultiMethods/ http://search.cpan.org/dist/MooseX-MultiMethods/