line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Test::Fixture::Teng; |
2
|
2
|
|
|
2
|
|
212021
|
use strict; |
|
2
|
|
|
|
|
14
|
|
|
2
|
|
|
|
|
60
|
|
3
|
2
|
|
|
2
|
|
11
|
use warnings; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
81
|
|
4
|
|
|
|
|
|
|
our $VERSION = '0.01'; |
5
|
2
|
|
|
2
|
|
12
|
use base 'Exporter'; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
173
|
|
6
|
|
|
|
|
|
|
our @EXPORT = qw/construct_fixture/; |
7
|
2
|
|
|
2
|
|
1185
|
use Params::Validate ':all'; |
|
2
|
|
|
|
|
19332
|
|
|
2
|
|
|
|
|
381
|
|
8
|
2
|
|
|
2
|
|
17
|
use Carp (); |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
49
|
|
9
|
2
|
|
|
2
|
|
1090
|
use Kwalify (); |
|
2
|
|
|
|
|
11805
|
|
|
2
|
|
|
|
|
800
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
sub construct_fixture { |
12
|
2
|
|
|
2
|
1
|
11370
|
my %args = validate( |
13
|
|
|
|
|
|
|
@_ => +{ |
14
|
|
|
|
|
|
|
db => 1, |
15
|
|
|
|
|
|
|
fixture => 1, |
16
|
|
|
|
|
|
|
} |
17
|
|
|
|
|
|
|
); |
18
|
|
|
|
|
|
|
|
19
|
2
|
|
|
|
|
16
|
my $fixture = _validate_fixture(_load_fixture($args{fixture})); |
20
|
2
|
|
|
|
|
9
|
_delete_all($args{db}); |
21
|
2
|
|
|
|
|
946
|
return _insert($args{db}, $fixture); |
22
|
|
|
|
|
|
|
} |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
sub _load_fixture { |
25
|
2
|
|
|
2
|
|
4
|
my $stuff = shift; |
26
|
|
|
|
|
|
|
|
27
|
2
|
100
|
|
|
|
8
|
if (ref $stuff) { |
28
|
1
|
50
|
|
|
|
5
|
if (ref $stuff eq 'ARRAY') { |
29
|
1
|
|
|
|
|
4
|
return $stuff; |
30
|
|
|
|
|
|
|
} else { |
31
|
0
|
|
|
|
|
0
|
Carp::croak "invalid fixture stuff. should be ARRAY: $stuff"; |
32
|
|
|
|
|
|
|
} |
33
|
|
|
|
|
|
|
} else { |
34
|
1
|
|
|
|
|
569
|
require YAML::Syck; |
35
|
1
|
|
|
|
|
1875
|
return YAML::Syck::LoadFile($stuff); |
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
sub _validate_fixture { |
40
|
2
|
|
|
2
|
|
263
|
my $stuff = shift; |
41
|
|
|
|
|
|
|
|
42
|
2
|
|
|
|
|
29
|
Kwalify::validate( |
43
|
|
|
|
|
|
|
{ |
44
|
|
|
|
|
|
|
type => 'seq', |
45
|
|
|
|
|
|
|
sequence => [ |
46
|
|
|
|
|
|
|
{ |
47
|
|
|
|
|
|
|
type => 'map', |
48
|
|
|
|
|
|
|
mapping => { |
49
|
|
|
|
|
|
|
table => { type => 'str', required => 1 }, |
50
|
|
|
|
|
|
|
name => { type => 'str', required => 1 }, |
51
|
|
|
|
|
|
|
data => { type => 'any', required => 1 }, |
52
|
|
|
|
|
|
|
}, |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
] |
55
|
|
|
|
|
|
|
}, |
56
|
|
|
|
|
|
|
$stuff |
57
|
|
|
|
|
|
|
); |
58
|
|
|
|
|
|
|
|
59
|
2
|
|
|
|
|
1695
|
$stuff; |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
sub _delete_all { |
63
|
2
|
|
|
2
|
|
3
|
my $db = shift; |
64
|
2
|
|
|
|
|
5
|
$db->delete($_) for |
65
|
2
|
|
|
|
|
7
|
keys %{$db->schema->tables}; |
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
sub _insert { |
69
|
2
|
|
|
2
|
|
7
|
my ($db, $fixture) = @_; |
70
|
|
|
|
|
|
|
|
71
|
2
|
|
|
|
|
15
|
my $result = {}; |
72
|
2
|
|
|
|
|
7
|
for my $row ( @{ $fixture } ) { |
|
2
|
|
|
|
|
6
|
|
73
|
6
|
|
|
|
|
4695
|
$result->{ $row->{name} } = $db->insert($row->{table}, $row->{data}); |
74
|
|
|
|
|
|
|
} |
75
|
2
|
|
|
|
|
2057
|
return $result; |
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
1; |
79
|
|
|
|
|
|
|
__END__ |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
=head1 NAME |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
Test::Fixture::Teng - load fixture data to storage for Teng |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
=head1 SYNOPSIS |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
# in your t/*.t |
88
|
|
|
|
|
|
|
use Test::Fixture::Teng; |
89
|
|
|
|
|
|
|
my $data = construct_fixture( |
90
|
|
|
|
|
|
|
db => Your::Teng::Class, |
91
|
|
|
|
|
|
|
fixture => 'fixture.yaml', |
92
|
|
|
|
|
|
|
); |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
# in your fixture.yaml |
95
|
|
|
|
|
|
|
- table: entry |
96
|
|
|
|
|
|
|
name: entry1 |
97
|
|
|
|
|
|
|
data: |
98
|
|
|
|
|
|
|
id: 1 |
99
|
|
|
|
|
|
|
title: my policy |
100
|
|
|
|
|
|
|
body: shut the f*ck up and write some code |
101
|
|
|
|
|
|
|
timestamp: 2008-01-01 11:22:44 |
102
|
|
|
|
|
|
|
- table: entry |
103
|
|
|
|
|
|
|
name: entry2 |
104
|
|
|
|
|
|
|
data: |
105
|
|
|
|
|
|
|
id: 2 |
106
|
|
|
|
|
|
|
title: please join |
107
|
|
|
|
|
|
|
body: #coderepos-en@freenode. |
108
|
|
|
|
|
|
|
timestamp: 2008-02-23 23:22:58 |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
=head1 DESCRIPTION |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
Test::Fixture::Teng is fixture data loader for Teng. |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
=head1 METHODS |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
=head2 construct_fixture |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
my $data = construct_fixture( |
119
|
|
|
|
|
|
|
db => Your::Teng::Class, |
120
|
|
|
|
|
|
|
fixture => 'fixture.yaml', |
121
|
|
|
|
|
|
|
); |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
construct your fixture. |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
=head1 AUTHOR |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
Masahiro Iuchi E<lt>masahiro.iuchi _at_ gmail _dot_ comE<gt> |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
=head1 SEE ALSO |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
L<Teng>, L<Kwalify> |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
=head1 THANKS |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
Mostly copied from L<Test::Fixture::DBIxSkinny> |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
=head1 REPOSITORY |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
git clone git://github.com/masiuchi/p5-test-fixture-teng.git |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
=head1 LICENSE |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or modify |
144
|
|
|
|
|
|
|
it under the same terms as Perl itself. |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
=cut |