in reply to custom attribute?

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

Replies are listed 'Best First'.
Re: Re: custom attribute? (wrong channel)
by Flame (Deacon) on Jan 28, 2003 at 21:45 UTC
    Thanks for the advice tye. The problem is, I don't actually call the sub by name, I work with references, many of which are anonymous to begin with (declared inline). This is suppost to be a part of the custom tests option mentioned here: Data Validation Tests



    My code doesn't have bugs, it just develops random features.

    Flame ~ Lead Programmer: GMS (DOWN) | GMS (DOWN)

      The "suggestion" on using subroutine name was facetious, meant to illustrate another example of an inappropriate channel.

                      - tye
        Oh, I see. I was reading it while someone was talking to me, so I was a little distracted. That clears it up a bit. Perhaps I will look into having them return information when called a certain way... perhaps using some level of currying... I still hope to use my current plan though, as it just looks better in my opinion.

        After all, what would you rather see?
        $check->newrule( -name => 'myname', #required, if no element specified, takes this. -element => ['one','two'], #Takes arrayref or string -required => 0, #required has no effect unless the data is omi +tted altogether. -tests => { -def => ['array','of','test','names'], -custom => [ sub($$) : modifies { #code }, sub(@) { #code }, ], } ); #Or $check->newrule( -name => 'myname', #required, if no element specified, takes this. -element => ['one','two'], #Takes arrayref or string -required => 0, #required has no effect unless the data is omi +tted altogether. -tests => { -def => ['array','of','test','names'], -custom => [ ctest( -args => 2, -mod => 1, -code => sub { #code }, ), ctest( -args => '*', -code => sub { #code }, ), ], } );


        Personally I prefer the first, but I'll admit, the second will probably be easier to implement.



        My code doesn't have bugs, it just develops random features.

        Flame ~ Lead Programmer: GMS (DOWN) | GMS (DOWN)