line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Acme::Tests; |
2
|
2
|
|
|
2
|
|
552
|
use v5.8.0; |
|
2
|
|
|
|
|
6
|
|
|
2
|
|
|
|
|
117
|
|
3
|
2
|
|
|
2
|
|
2079
|
use Spiffy -Base; |
|
2
|
|
|
|
|
28112
|
|
|
2
|
|
|
|
|
17
|
|
4
|
2
|
|
|
2
|
|
15654
|
our $VERSION = '0.03'; |
|
2
|
|
|
2
|
|
12
|
|
|
2
|
|
|
|
|
83
|
|
|
2
|
|
|
|
|
9
|
|
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
123
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
=head1 NAME |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
Acme::Tests - How much do you know ? |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
=head1 SYNOPSIS |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
perl Makefile.PL |
13
|
|
|
|
|
|
|
make test |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
=head1 DESCRIPTION |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
This module is a "test software", it has tests in the software rather |
18
|
|
|
|
|
|
|
then software tests. Upon installation, you are reqruied to answered |
19
|
|
|
|
|
|
|
several question, and the installation would be only successful if all |
20
|
|
|
|
|
|
|
you pass them all. |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
=head1 HELP |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
So please help out providing a nice quailty test library! |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
=head1 COPYRIGHT |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
Copyright 2005,2006 by Kang-min Liu . |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify |
31
|
|
|
|
|
|
|
it under the same terms as Perl itself. |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
See |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
=cut |
36
|
|
|
|
|
|
|
|
37
|
2
|
|
|
2
|
|
11
|
use List::Util qw(shuffle); |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
1298
|
|
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
field unanswered => {}, -init => '$self->load_tests()'; |
40
|
|
|
|
|
|
|
field tests => {}, -init => '$self->load_tests()'; |
41
|
|
|
|
|
|
|
|
42
|
2
|
|
|
2
|
0
|
4
|
sub data { |
43
|
2
|
|
33
|
|
|
22
|
my $package = shift || ref($self); |
44
|
2
|
|
|
0
|
|
25
|
local $SIG{__WARN__} = sub {}; |
|
0
|
|
|
|
|
0
|
|
45
|
2
|
|
|
|
|
9
|
local $/; |
46
|
2
|
|
|
|
|
201
|
eval "package $package; "; |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
|
49
|
2
|
|
|
2
|
0
|
43
|
sub load_tests { |
50
|
2
|
|
|
|
|
14
|
my $lib = $self->data; |
51
|
2
|
|
|
|
|
7
|
my $tests = {}; |
52
|
2
|
|
|
|
|
18
|
for(split(/\n----\n/,$lib)) { |
53
|
8
|
|
|
|
|
21
|
s/^\s+//; s/\s+$//s; |
|
8
|
|
|
|
|
49
|
|
54
|
8
|
50
|
|
|
|
22
|
next unless $_; |
55
|
8
|
|
|
|
|
52
|
my ($q,$a) = $_ =~ /(.+?)\n+Ans:\s*(.+?)\n*/s; |
56
|
8
|
100
|
66
|
|
|
37
|
next unless $q && $a; |
57
|
7
|
|
|
|
|
28
|
$tests->{$q} = lc($a); |
58
|
|
|
|
|
|
|
} |
59
|
2
|
|
|
|
|
59
|
$self->tests($tests); |
60
|
2
|
|
|
|
|
219
|
$self->unanswered([shuffle (keys %$tests)]); |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
|
63
|
9
|
|
|
9
|
0
|
294
|
sub next_question { |
64
|
9
|
|
|
|
|
256
|
my $una = $self->unanswered; |
65
|
9
|
|
|
|
|
743
|
my $q = shift @$una; |
66
|
9
|
|
|
|
|
209
|
$self->unanswered($una); |
67
|
9
|
|
|
|
|
76
|
return $q; |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
|
70
|
7
|
|
|
7
|
0
|
2849
|
sub is_correct { |
71
|
7
|
|
|
|
|
13
|
my ($q,$a) = @_; |
72
|
7
|
|
|
|
|
86
|
$a =~ s/^\s+//gs; |
73
|
7
|
|
|
|
|
67
|
$a =~ s/\s+$//gs; |
74
|
7
|
|
|
|
|
177
|
return ($self->tests->{$q} eq lc($a)) |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
__DATA__ |