Ignore:
Timestamp:
Feb 19, 2013, 8:29:38 PM (9 years ago)
Author:
David Benjamin <davidben@mit.edu>
Branches:
master
Children:
4584d1f
Parents:
69f74c2
git-author:
David Benjamin <davidben@mit.edu> (06/09/12 23:16:53)
git-committer:
David Benjamin <davidben@mit.edu> (02/19/13 20:29:38)
Message:
Allow perl variables to participate in argumentless set/unset
File:
1 edited

Legend:

Unmodified
Added
Removed
  • perl/lib/BarnOwl.pm

    r69f74c2 r3b9ca71  
    426426
    427427sub new_variable_int {
    428     unshift @_, 0, "<int>", sub { "$_[0]" }, # to string
    429                             sub { $_[0] =~ /^-?[0-9]+$/ }, # validate
    430                             sub { 0 + $_[0] }; # from string
     428    unshift @_, 0, "<int>", 0, sub { "$_[0]" }, # to string
     429                               sub { $_[0] =~ /^-?[0-9]+$/ }, # validate
     430                               sub { 0 + $_[0] }; # from string
    431431    goto \&_new_variable;
    432432}
    433433
    434434sub new_variable_bool {
    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
     435    unshift @_, 0, "on,off", 1, sub { $_[0] ? "on" : "off" }, # to string
     436                                sub { $_[0] eq "on" || $_[0] eq "off" }, # validate
     437                                sub { $_[0] eq "on" }; # from string
    438438    goto \&_new_variable;
    439439}
    440440
    441441sub new_variable_string {
    442     unshift @_, "", "<string>", sub { $_[0] }, # to string
    443                                 sub { 1 }, # validate
    444                                 sub { $_[0] }; # from string
     442    unshift @_, "", "<string>", 0, sub { $_[0] }, # to string
     443                                   sub { 1 }, # validate
     444                                   sub { $_[0] }; # from string
    445445    goto \&_new_variable;
    446446}
     
    449449    my $default_default = shift;
    450450    my $validsettings = shift;
     451    my $takes_on_off = shift;
    451452    my $tostring_fn = shift;
    452453    my $validate_fn = shift;
     
    473474
    474475    BarnOwl::Internal::new_variable($name, $args{summary}, $args{description}, $validsettings,
    475                                     $get_tostring_fn, $set_fromstring_fn, undef);
     476                                    $takes_on_off, $get_tostring_fn, $set_fromstring_fn, undef);
    476477}
    477478
Note: See TracChangeset for help on using the changeset viewer.