TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Examples of using dispatch tables in perl

36 pointsby f00li5hover 14 years ago

3 comments

Xurinosover 14 years ago
This looks more like perl scripting than perl programming.<p>If I put all those functions into a class and then called $class_object-&#62;can($method), I get the same effect, only without the crazy hash. Perl has built-in dispatching.<p>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.<p>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).
评论 #1787713 未加载
评论 #1786972 未加载
wizard_2over 14 years ago
I'm pretty new to perl scripting but most of my cgi's at work look like this near the beginning. How is that crazy bit of code better? (Post_only is just a function that returns the function or a 404 if the request isn't a post)<p><pre><code> # Dispatcher my %action = ( 'search' =&#62; \&#38;controller_search, 'view' =&#62; \&#38;controller_view, 'save' =&#62; post_only(\&#38;controller_edit), 'delete' =&#62; post_only(\&#38;controller_delete), 'index' =&#62; \&#38;controller_index, ); if(exists $action{$q-&#62;param('do')}){ $action{$q-&#62;param('do')}-&#62;(); }else{ $action{'index'}-&#62;(); } exit;</code></pre>
评论 #1786984 未加载
评论 #1786981 未加载
absconditusover 14 years ago
<a href="http://hop.perl.plover.com/book/pdf/02DispatchTables.pdf" rel="nofollow">http://hop.perl.plover.com/book/pdf/02DispatchTables.pdf</a>
评论 #1786997 未加载