Changeset e26abb6
- Timestamp:
- Feb 23, 2013, 5:44:21 PM (12 years ago)
- Branches:
- master, release-1.10
- Children:
- bbc31e4
- Parents:
- 523146b
- git-author:
- David Benjamin <davidben@mit.edu> (02/16/13 15:43:20)
- git-committer:
- David Benjamin <davidben@mit.edu> (02/23/13 17:44:21)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
perl/lib/BarnOwl.pm
r523146b re26abb6 18 18 new_command 19 19 new_variable_int new_variable_bool new_variable_string 20 new_variable_enum 20 21 quote redisplay); 21 22 our %EXPORT_TAGS = (all => \@EXPORT_OK); … … 402 403 =head2 new_variable_string NAME [{ARGS}] 403 404 404 Add a new owl variable, either an int, a bool, or a string, with the 405 =head2 new_variable_enum NAME [{ARGS}] 406 407 Add a new owl variable, either an int, a bool, a string, or an enum with the 405 408 specified name. 406 409 407 ARGS can optionally contain the following keys: 410 For new_variable_enum, ARGS is required to contain a validsettings key pointing 411 to an array reference. For all four, it can optionally contain the following 412 keys: 408 413 409 414 =over 4 … … 469 474 validsettings => "<string>", 470 475 takes_on_off => 0, 476 }); 477 } 478 479 sub new_variable_enum { 480 my ($name, $args) = @_; 481 482 # Gather the valid settings. 483 die "validsettings is required" unless defined($args->{validsettings}); 484 my %valid; 485 map { $valid{$_} = 1 } @{$args->{validsettings}}; 486 487 my $storage = (defined($args->{default}) ? 488 $args->{default} : 489 $args->{validsettings}->[0]); 490 BarnOwl::new_variable_full($name, { 491 %{$args}, 492 get_tostring => sub { $storage }, 493 set_fromstring => sub { 494 return -1 unless $valid{$_[0]}; 495 $storage = $_[0]; 496 return 0; 497 }, 498 validsettings => join(",", @{$args->{validsettings}}) 471 499 }); 472 500 }
Note: See TracChangeset
for help on using the changeset viewer.