line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Test::Fixture::KyotoTycoon; |
2
|
3
|
|
|
3
|
|
1736
|
use strict; |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
94
|
|
3
|
3
|
|
|
3
|
|
12
|
use warnings; |
|
3
|
|
|
|
|
5
|
|
|
3
|
|
|
|
|
109
|
|
4
|
3
|
|
|
3
|
|
60
|
use 5.008000; |
|
3
|
|
|
|
|
9
|
|
|
3
|
|
|
|
|
98
|
|
5
|
3
|
|
|
3
|
|
2414
|
use parent qw(Exporter); |
|
3
|
|
|
|
|
882
|
|
|
3
|
|
|
|
|
15
|
|
6
|
3
|
|
|
3
|
|
140
|
use Carp; |
|
3
|
|
|
|
|
5
|
|
|
3
|
|
|
|
|
258
|
|
7
|
3
|
|
|
3
|
|
2450
|
use Kwalify; |
|
3
|
|
|
|
|
19891
|
|
|
3
|
|
|
|
|
181
|
|
8
|
3
|
|
|
3
|
|
52838
|
use Storable qw(nfreeze); |
|
3
|
|
|
|
|
20978
|
|
|
3
|
|
|
|
|
280
|
|
9
|
3
|
|
|
3
|
|
2803
|
use YAML::XS qw(LoadFile); |
|
3
|
|
|
|
|
12031
|
|
|
3
|
|
|
|
|
1514
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
our @EXPORT = qw(construct_fixture); |
12
|
|
|
|
|
|
|
our $VERSION = '0.13'; |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
sub construct_fixture { |
15
|
|
|
|
|
|
|
|
16
|
0
|
|
|
0
|
1
|
|
my %args = @_; |
17
|
0
|
|
|
|
|
|
my $fixture; |
18
|
|
|
|
|
|
|
|
19
|
0
|
0
|
0
|
|
|
|
if (!ref($args{kt}) || ref($args{kt}) && !$args{kt}->isa("Cache::KyotoTycoon")) { |
|
|
|
0
|
|
|
|
|
20
|
0
|
|
|
|
|
|
croak "kt must be Cache::KyotoTycoon instance"; |
21
|
|
|
|
|
|
|
} |
22
|
|
|
|
|
|
|
|
23
|
0
|
0
|
|
|
|
|
if (-f $args{fixture}) { |
|
|
0
|
|
|
|
|
|
24
|
0
|
|
|
|
|
|
$fixture = LoadFile($args{fixture}); |
25
|
|
|
|
|
|
|
} elsif (ref($args{fixture}) eq "ARRAY") { |
26
|
0
|
|
|
|
|
|
$fixture = $args{fixture}; |
27
|
|
|
|
|
|
|
} else { |
28
|
0
|
|
|
|
|
|
croak "fixture must be YAML file path or ARRAY"; |
29
|
|
|
|
|
|
|
} |
30
|
0
|
|
|
|
|
|
_validate_fixture($fixture); |
31
|
|
|
|
|
|
|
|
32
|
0
|
0
|
|
|
|
|
if (ref($args{serializer}) eq "CODE") { |
33
|
0
|
|
|
|
|
|
_override_serializer($args{serializer}); |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
|
36
|
0
|
|
|
|
|
|
_delete_all($args{kt}); |
37
|
0
|
|
|
|
|
|
return _insert($args{kt}, $fixture); |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
sub _delete_all { |
41
|
|
|
|
|
|
|
|
42
|
0
|
|
|
0
|
|
|
my $kt = shift; |
43
|
0
|
|
|
|
|
|
$kt->clear; |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
sub _insert { |
47
|
|
|
|
|
|
|
|
48
|
0
|
|
|
0
|
|
|
my($kt, $fixture) = @_; |
49
|
|
|
|
|
|
|
|
50
|
0
|
|
|
|
|
|
my $data = {}; |
51
|
0
|
|
|
|
|
|
foreach my $ref (@{$fixture}) { |
|
0
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
|
53
|
0
|
|
|
|
|
|
my @values; |
54
|
0
|
0
|
|
|
|
|
push @values, (exists $ref->{namespace} ? sprintf("%s%s", $ref->{namespace}, $ref->{key}) : $ref->{key}); |
55
|
0
|
0
|
|
|
|
|
push @values, (ref($ref->{value}) ? _serializer($ref->{value}) : $ref->{value}); |
56
|
0
|
0
|
|
|
|
|
push @values, $ref->{xt} if exists $ref->{xt}; |
57
|
|
|
|
|
|
|
#$kt->set($key, $value, $xt); |
58
|
0
|
|
|
|
|
|
$kt->set(@values); |
59
|
0
|
|
|
|
|
|
$data->{$values[0]} = $values[1]; |
60
|
|
|
|
|
|
|
} |
61
|
0
|
|
|
|
|
|
return $data; |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
sub _override_serializer { |
65
|
|
|
|
|
|
|
|
66
|
0
|
|
|
0
|
|
|
my $serializer = shift; |
67
|
3
|
|
|
3
|
|
24
|
no strict "refs"; |
|
3
|
|
|
|
|
4
|
|
|
3
|
|
|
|
|
92
|
|
68
|
3
|
|
|
3
|
|
20
|
no warnings "redefine"; |
|
3
|
|
|
|
|
8
|
|
|
3
|
|
|
|
|
563
|
|
69
|
0
|
|
|
|
|
|
*_serializer = $serializer; ## no critic |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
sub _serializer { |
73
|
|
|
|
|
|
|
|
74
|
0
|
|
|
0
|
|
|
my $ref = shift; |
75
|
0
|
|
|
|
|
|
return nfreeze $ref; |
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
sub _validate_fixture { |
79
|
|
|
|
|
|
|
|
80
|
0
|
|
|
0
|
|
|
my $stuff = shift; |
81
|
0
|
|
|
|
|
|
Kwalify::validate({ |
82
|
|
|
|
|
|
|
type => 'seq', |
83
|
|
|
|
|
|
|
sequence => [{ |
84
|
|
|
|
|
|
|
type => 'map', |
85
|
|
|
|
|
|
|
mapping => { |
86
|
|
|
|
|
|
|
namespace => { type => 'str' }, |
87
|
|
|
|
|
|
|
key => { type => 'str', required => 1 }, |
88
|
|
|
|
|
|
|
value => { type => 'any', required => 1 }, |
89
|
|
|
|
|
|
|
xt => { type => 'int' } |
90
|
|
|
|
|
|
|
}, |
91
|
|
|
|
|
|
|
}] |
92
|
|
|
|
|
|
|
}, |
93
|
|
|
|
|
|
|
$stuff |
94
|
|
|
|
|
|
|
); |
95
|
0
|
|
|
|
|
|
return $stuff; |
96
|
|
|
|
|
|
|
} |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
1; |
100
|
|
|
|
|
|
|
__END__ |