I only skimmed the RPC article, but I have experience with things like this in CGI. I use an "event dispatching framework" for many of my CGI applications. Basically, an event comes in from the client via qstring or post. This event is translated into a sub call.

The most traditional way of doing this, as the RPC article talks about, is to use a function mapping hash. People don't like to maintain these.

The RPC article suggests iterating over the symbol table. Chances are, that was a lot easier to describe than using attributes.

Using attributes in Perl is a little tricky. To compound that, many people don't understand the basic concepts of sub attributes and, of course, Perl's version is still in "beta" and subject to change.

So, for a public article such as this, using the symbol table approach was probably a good idea.

Now, using attributes is cleaner (IMHO) and can be done just as easily, once you get the nack for Attribute::Handler. Also, it is (again IMHO) more flexible.

Now, back to my CGI event handling framework. I tried using attributes, but found them substantially slower than my current strategy. Currently, when I process the event string, I add "event_" to the begining of it. Then I check to see if that sub exists. If so, I execute it. When I tried attributes, I would hash the names of all the subs marked as event handler. Then, When I get an event string, I would just look in the hash to see if that sub exists. If it does I would have its ref and execute it. But, I found this to be much slower than my current version.

I suspect (and I have no proof of this) that the current implimentation of attributes in Perl isn't as optimal as it could be yet (it is, of course, pretty new). To compound the issue, this was CGI. In a mod_perl environment, the extra initial overhead would not have been a problem.

Ted Young

($$<<$$=>$$<=>$$<=$$>>$$) always returns 1. :-)

In reply to Re: A useful use of Attributes? by TedYoung
in thread A useful use of Attributes? by fireartist

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.