dod38fr / config-model

Perl module to create configuration editor with semantic validation
58 stars 12 forks source link

warn_if_match and warn_unless match problem #2

Closed nowinter closed 9 years ago

nowinter commented 9 years ago

the run_regexp_set_onvalue sub callback is set to compare $[0] to $rxp I think it should be $$value (which is the value) instead of $_[0] (which is the Value object)

dod38fr commented 9 years ago

The critical line in run_regexp_set_on_value (in Value.pm) is this one:

 my $sub = sub { $test_sub->( $_[0], $rxp ) };

The trick is: $test_sub is not run here, but stored in another anonymous sub ($sub). In this anonymous sub, $rxp is a closure, and $_[0] is the first parameter passed to $sub when it is called. (outside of this sub definition, $_[0] is indeed $self, i.e. the Value object).

The call to $sub is done in run_code_on_value in the following line:

    my $ret = $sub->($$value_r);

Thus $_[0] is indeed set to $$value_r as you suggested

Does this answer your concern ?

nowinter commented 9 years ago

Ooops, sorry, you are right! This is not an issue

dod38fr commented 9 years ago

no problem. I'm glad to find out that some people are reading my code :-)