- Timestamp:
- 08/13/15 18:07:55 (9 years ago)
- Location:
- trunk/LATMOS-Accounts
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/LATMOS-Accounts/lib/LATMOS/Accounts/Utils.pm
r1151 r1378 21 21 22 22 @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); 25 25 26 26 =head2 to_ascii($text) … … 248 248 } 249 249 250 =head2 genpassword 250 =head2 genpassword(%options) 251 252 Generate a random password, options are: 253 254 =over4 255 256 =item length 257 258 The minimum password length (default is 6) 259 260 =item nonalpha 261 262 Include non alpha-numeric caracters 263 264 =item syllables 265 266 Use a set of syllables instead letter 267 268 =back 251 269 252 270 =cut … … 296 314 } 297 315 316 =head2 yesno($value, $default) 317 318 Check is a paramter mean yes or no 319 320 =cut 321 322 sub 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 298 337 1; 299 338 -
trunk/LATMOS-Accounts/t/05_utils.t
r1216 r1378 1 1 use strict; 2 2 use warnings; 3 use Test::More tests => 16;3 use Test::More tests => 21; 4 4 use File::Temp qw(mkstemp); 5 5 … … 44 44 ok(LATMOS::Accounts::Utils::check_ug_validity('5toto'), '"5toto" is invalid username'); 45 45 ok(!LATMOS::Accounts::Utils::check_ug_validity('t5oto'), '"t5oto" is valid username'); 46 47 is(yesno('yes'), 1, 'yes is true'); 48 is(yesno('true'), 1, 'true is true'); 49 is(yesno('23'), 1, '23 is true'); 50 is(yesno('no'), 0, 'no is false'); 51 is(yesno('what'), 'what', 'what is what?');
Note: See TracChangeset
for help on using the changeset viewer.