line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package EntityModel::Test::Cache; |
2
|
|
|
|
|
|
|
{ |
3
|
|
|
|
|
|
|
$EntityModel::Test::Cache::VERSION = '0.102'; |
4
|
|
|
|
|
|
|
} |
5
|
|
|
|
|
|
|
use EntityModel::Class { |
6
|
1
|
|
|
|
|
12
|
_isa => [qw(Exporter)], |
7
|
1
|
|
|
1
|
|
33532
|
}; |
|
1
|
|
|
|
|
73950
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
=head1 NAME |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
EntityModel::Test::Cache - tests for L and subclasses |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
=head1 VERSION |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
version 0.102 |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
=head1 SYNOPSIS |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
use EntityModel::Test::Cache; |
20
|
|
|
|
|
|
|
cache_ok('EntityModel::Cache::Perl', '::Perl subclass works'); |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
=head1 DESCRIPTION |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
Provides functions for testing L subclasses. |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
=cut |
27
|
|
|
|
|
|
|
|
28
|
1
|
|
|
1
|
|
1961
|
use Test::Builder; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
23
|
|
29
|
1
|
|
|
1
|
|
5
|
use Module::Load; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
7
|
|
30
|
|
|
|
|
|
|
|
31
|
1
|
|
|
|
|
553
|
use constant CACHE_METHODS => qw( |
32
|
|
|
|
|
|
|
new |
33
|
|
|
|
|
|
|
get |
34
|
|
|
|
|
|
|
set |
35
|
1
|
|
|
1
|
|
54
|
); |
|
1
|
|
|
|
|
2
|
|
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
=head1 EXPORTS |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
Since this is a test class, functions are exported automatically |
40
|
|
|
|
|
|
|
to match behaviour of other test modules such as L. |
41
|
|
|
|
|
|
|
To disable this, pass an empty list on the C |
42
|
|
|
|
|
|
|
use C instead: |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
use EntityModel::Test::Cache (); |
45
|
|
|
|
|
|
|
EntityModel::Test::Cache::cache_ok(...); |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
=cut |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
our @EXPORT = qw( |
50
|
|
|
|
|
|
|
cache_ok |
51
|
|
|
|
|
|
|
cache_methods_ok |
52
|
|
|
|
|
|
|
); |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
=head1 FUNCTIONS |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
=cut |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
=head2 cache_ok |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
Runs all available tests (including attempting to load the module) and returns the usual |
61
|
|
|
|
|
|
|
L ok/fail response. |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
=cut |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
sub cache_ok { |
66
|
1
|
|
|
1
|
1
|
6
|
my $class = shift; |
67
|
1
|
|
33
|
|
|
6
|
my $msg = shift || "$class is a valid, working EntityModel::Cache (sub)class"; |
68
|
1
|
|
|
|
|
2
|
my $ok = 0; |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
# First we need to be able to load our module |
72
|
|
|
|
|
|
|
try { |
73
|
1
|
|
|
|
|
6
|
Module::Load::load($class); |
74
|
1
|
|
|
|
|
3
|
} catch { |
75
|
1
|
|
|
|
|
13
|
return _report_status($ok, $msg, $_); |
76
|
|
|
|
|
|
|
}; |
77
|
|
|
|
|
|
|
|
78
|
0
|
0
|
|
|
|
0
|
_methods_ok($class, $msg) or return; |
79
|
|
|
|
|
|
|
|
80
|
0
|
|
|
|
|
0
|
$ok = 1; |
81
|
0
|
|
|
|
|
0
|
return _report_status($ok, $msg); |
82
|
|
|
|
|
|
|
} |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
sub cache_methods_ok { |
85
|
1
|
|
|
1
|
0
|
6
|
my $class = shift; |
86
|
1
|
|
33
|
|
|
8
|
my $msg = shift || "$class has all the required methods"; |
87
|
1
|
0
|
|
|
|
4
|
return 0 unless _methods_ok($class, $msg); |
88
|
0
|
|
|
|
|
0
|
return _report_status(1, $msg); |
89
|
|
|
|
|
|
|
} |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
sub _methods_ok { |
92
|
1
|
|
|
1
|
|
2
|
my $class = shift; |
93
|
1
|
|
|
|
|
16
|
my $msg = shift; |
94
|
|
|
|
|
|
|
|
95
|
1
|
|
|
|
|
3
|
my %failed; |
96
|
1
|
|
|
|
|
3
|
foreach my $method (CACHE_METHODS) { |
97
|
|
|
|
|
|
|
try { |
98
|
1
|
|
|
|
|
10
|
$class->can($method); |
99
|
1
|
0
|
0
|
|
|
1
|
} catch { |
100
|
1
|
|
|
|
|
169
|
$failed{$method} = $_; |
101
|
|
|
|
|
|
|
} or $failed{$method} ||= 'not available'; |
102
|
|
|
|
|
|
|
} |
103
|
0
|
0
|
|
|
|
0
|
if(keys %failed) { |
104
|
0
|
|
|
|
|
0
|
_report_status(0, $msg, join "\n", map { "Could not ->$_ because: " . $failed{$_} } sort keys %failed); |
|
0
|
|
|
|
|
0
|
|
105
|
0
|
|
|
|
|
0
|
return 0; |
106
|
|
|
|
|
|
|
} |
107
|
0
|
|
|
|
|
0
|
return 1; |
108
|
|
|
|
|
|
|
} |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
sub _report_status { |
111
|
1
|
|
|
1
|
|
2
|
my $ok = shift; |
112
|
1
|
|
|
|
|
2
|
my $msg = shift; |
113
|
1
|
|
|
|
|
2
|
my $diag = shift; |
114
|
|
|
|
|
|
|
|
115
|
1
|
|
|
|
|
9
|
my $test = Test::Builder->new; |
116
|
1
|
|
|
|
|
13
|
$test->ok($ok, $msg); |
117
|
1
|
50
|
|
|
|
1212
|
$test->diag($diag) if defined $diag; |
118
|
1
|
|
|
|
|
5
|
return $ok; |
119
|
|
|
|
|
|
|
} |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
1; |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
__END__ |