You are using subroutine prototypes to convey a count. Since you are looking up the prototype you must be building the argument list dynamically which means you are also bypassing the prototype (or using eval which is probably worse). So it seems you are misusing the prototype.

Now you want to put an attribute on the subroutine just so you can check for it. I think these both sound like you are fixated on using a specific channel for conveying information and you should consider alternatives.

You could convey the number of arguments by how many letters in the subroutine name and use uppercase if you want a reference and lower case if not. (just to give you an exagerated idea of how your current plan sounds to me)

Another alternative would be to have the subroutine return the meta information when you call it with no arguments:

sub mysub { return -4 unless @_; my( $svA, $svB, $svC, $svD )= @_; ... }
meaning it wants 4 arguments that are references.

Good luck with your attributes problem. I did a quick look in perlsub which pointed to the documentation for attributes.pm which mentions doing custom attributes, so perhaps you should just go read that.

                - tye

In reply to Re: custom attribute? (wrong channel) by tye
in thread custom attribute? by Flame

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.