in reply to Re^3: custom attribute? (wrong channel)
in thread custom attribute?

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)

Replies are listed 'Best First'.
Re^5: custom attribute? (wrong channel)
by tye (Sage) on Jan 29, 2003 at 01:33 UTC

    I prefer the latter. Seeing the former I would think things like "Why is he using a prototype on an anonymous sub when prototypes are completely ignored on those?", "Will a future version of Perl complain or fail for that since it is useless?", etc. (:

                    - tye
      Well for now I'll go with the currying solution for now... but I still hope to eventually get the smaller (at least for me) solution working. This is the currying sub I've decided to use (or at least variations on this):
      sub ctest { _self(@_); #Eliminate any object that may be in the args my %opts = @_; unless(defined($opts{'code'}) && ref($opts{'code'}) eq 'CODEREF'){ return ERROR; } unless(defined($opts{'mod'})){ $opts{'mod'} = 0; } return sub { #Retun useage info if called without args return [$opts{'args'},$opts{'mod'}] if(!@_); $opts{'code'}->(@_); } } #Used as: my $coderef = ctest( args => 3, code => sub { return 1 if(int($_[0]) == $_[0]); return; } ); $coderef->(4.23);




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

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