[MARKSTOS - Sun Jul 3 15:29:20 2005]:
Show quoted text> [guest - Mon Jun 13 12:11:47 2005]:
>
> > Using this patch I can write something like:
> >
> > $input_profile->{defaults} = {
> > creation_date => sub {
> > require Time::Piece;
> > my $now = Timie::Piece->new();
> > return $now->ymd;
> > }
> > }
> >
> > and have the 'creation_date' filled with current date left blank.
>
> I will accept this feature addition. Could you also add a test for it
> and update the docs and Changes files as well? I'm CC'ing the mailing
> list against someone else wants to contribute that work as well.
>
> Otherwise, I'll get to it eventually myself.
>
> Stalling ticket for feedback.
>
> Mark
>
I have written a simple addition to 25_results.t, and while doing that I
realized it might be useful to pass $field as an argument to the
coderef. So here are the new Restuls.pm patch and the 25_results.t patch:
-------------------- 25_results.t ------------------
1c1
< use Test::More tests => 4;
---
Show quoted text> use Test::More tests => 6;
13c13
< required => 'stick',
---
Show quoted text> required => [ 'stick', 'fromsub', 'whoami' ],
15c15,18
<
---
Show quoted text> defaults => {
> fromsub => sub { return "got value from a subroutine"; },
> whoami => sub { my $me = shift; return "I am field $me"; },
> },
29c32,33
<
---
Show quoted text> ok($results->valid('fromsub') eq "got value from a subroutine", 'usg
CODE references as default values');
Show quoted text> ok($results->valid('whoami') eq "I am field whoami", 'usg CODE
references as default values');
~
~
-------------------- Results.pm ------------------
262c262,268
< $valid{$field} = $value unless exists $valid{$field};
---
Show quoted text> unless(exists $valid{$field}) {
> if (ref($value) && ref($value) eq "CODE") {
> $valid{$field} = $value->($field);
> } else {
> $valid{$field} = $value;
> }
> }
I'll post a patch to the docs ASAP.