Ignore:
Timestamp:
08/13/15 18:07:55 (9 years ago)
Author:
nanardon
Message:

add yesno() function for configutration option

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/LATMOS-Accounts/lib/LATMOS/Accounts/Utils.pm

    r1151 r1378  
    2121 
    2222@ISA = qw(Exporter); 
    23 @EXPORT = qw(to_ascii exec_command switch_user run_via_sudo); 
    24 @EXPORT_OK = qw(to_ascii exec_command switch_user run_via_sudo); 
     23@EXPORT = qw(to_ascii exec_command switch_user run_via_sudo yesno); 
     24@EXPORT_OK = qw(to_ascii exec_command switch_user run_via_sudo yesno); 
    2525 
    2626=head2 to_ascii($text) 
     
    248248} 
    249249 
    250 =head2 genpassword 
     250=head2 genpassword(%options) 
     251 
     252Generate a random password, options are: 
     253 
     254=over4 
     255 
     256=item length 
     257 
     258The minimum password length (default is 6) 
     259 
     260=item nonalpha 
     261 
     262Include non alpha-numeric caracters 
     263 
     264=item syllables 
     265 
     266Use a set of syllables instead letter 
     267 
     268=back 
    251269 
    252270=cut 
     
    296314} 
    297315 
     316=head2 yesno($value, $default) 
     317 
     318Check is a paramter mean yes or no 
     319 
     320=cut 
     321 
     322sub yesno { 
     323    my ($value, $default) = @_; 
     324 
     325    if ($value =~ /^(yes|1|true)$/i) { 
     326        return 1; 
     327    } 
     328    if ($value =~ /^(no|0|false)$/i) { 
     329        return 0; 
     330    } 
     331    if ($value =~ /^\d+$/ and $value != 0) { 
     332        return 1; 
     333    } 
     334    return $default || $value; 
     335} 
     336 
    2983371; 
    299338 
Note: See TracChangeset for help on using the changeset viewer.