Changeset 69f74c2 for perl/lib/BarnOwl.pm
- Timestamp:
- Feb 19, 2013, 8:29:34 PM (12 years ago)
- Branches:
- master, release-1.10
- Children:
- 3b9ca71
- Parents:
- e5210c9
- git-author:
- David Benjamin <davidben@mit.edu> (06/09/12 23:05:48)
- git-committer:
- David Benjamin <davidben@mit.edu> (02/19/13 20:29:34)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
perl/lib/BarnOwl.pm
r374089a r69f74c2 426 426 427 427 sub new_variable_int { 428 unshift @_, \&BarnOwl::Internal::new_variable_int, 0; 428 unshift @_, 0, "<int>", sub { "$_[0]" }, # to string 429 sub { $_[0] =~ /^-?[0-9]+$/ }, # validate 430 sub { 0 + $_[0] }; # from string 429 431 goto \&_new_variable; 430 432 } 431 433 432 434 sub new_variable_bool { 433 unshift @_, \&BarnOwl::Internal::new_variable_bool, 0; 435 unshift @_, 0, "on,off", sub { $_[0] ? "on" : "off" }, # to string 436 sub { $_[0] eq "on" || $_[0] eq "off" }, # validate 437 sub { $_[0] eq "on" }; # from string 434 438 goto \&_new_variable; 435 439 } 436 440 437 441 sub new_variable_string { 438 unshift @_, \&BarnOwl::Internal::new_variable_string, ""; 442 unshift @_, "", "<string>", sub { $_[0] }, # to string 443 sub { 1 }, # validate 444 sub { $_[0] }; # from string 439 445 goto \&_new_variable; 440 446 } 441 447 442 448 sub _new_variable { 443 my $func = shift;444 449 my $default_default = shift; 450 my $validsettings = shift; 451 my $tostring_fn = shift; 452 my $validate_fn = shift; 453 my $fromstring_fn = shift; 454 445 455 my $name = shift; 446 456 my $args = shift || {}; … … 450 460 default => $default_default, 451 461 %{$args}); 452 $func->($name, $args{default}, $args{summary}, $args{description}); 462 463 # Store the value in a closure. 464 my $value = $args{default}; 465 466 my $get_tostring_fn = sub { $tostring_fn->($value) }; 467 my $set_fromstring_fn = sub { 468 my ($dummy, $newval) = @_; 469 return -1 unless $validate_fn->($newval); 470 $value = $fromstring_fn->($newval); 471 return 0; 472 }; 473 474 BarnOwl::Internal::new_variable($name, $args{summary}, $args{description}, $validsettings, 475 $get_tostring_fn, $set_fromstring_fn, undef); 453 476 } 454 477
Note: See TracChangeset
for help on using the changeset viewer.