4 use Test::More 0.94 tests => 5; # last test to print
6 for my $class (qw/Perlbal Perlbal::Service/) {
7 use_ok( $class, "can load module $class" );
10 my $class = 'Perlbal::Service';
12 subtest 'module checking' => sub {
13 isa_ok( $class->new(), $class, "can create object from $class" );
17 my @words = generate_words(1000);
19 subtest 'check sub integrity' => sub {
20 is_deeply( test_optimized(), test_original(), "sub optimized" );
21 is_deeply( test_hash(), test_original(), "sub hash" );
26 skip "need Benchmark module", 1 unless eval "require Benchmark";
28 subtest 'benchmark bool sub' => sub {
36 'original' => \&test_original,
37 'optimized' => \&test_optimized,
38 'hash' => \&test_hash,
51 map { _bool_original($_) } @words;
55 map { _bool_optimized($_) } @words;
59 map { Perlbal::Service::_bool($_) } @words;
65 return unless defined $val;
67 return 1 if $val =~ /^1|true|on|yes$/i;
68 return 0 if $val =~ /^0|false|off|no$/i;
81 return unless defined $val;
83 $qr_on = qr/^1|true|on|yes$/i unless defined $qr_on;
84 $qr_off = qr/^0|false|off|no$/i unless defined $qr_off;
86 return 1 if $val =~ $qr_on;
87 return 0 if $val =~ $qr_off;
94 my @words = qw/1 true on yes 0 false off no/;
99 my $w = $words[ int rand( scalar @words ) ];
107 for my $c ( 1 .. $l ) {
108 next if ( rand(2) > 1 );
109 substr( $w, $c - 1, 1 ) = uc( getn_substr( $w, $c ) );
120 return substr $_[0], $_[1] - 1, 1;