line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Test::Fixture::DBIxSkinny; |
2
|
2
|
|
|
2
|
|
871
|
use strict; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
80
|
|
3
|
2
|
|
|
2
|
|
10
|
use warnings; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
77
|
|
4
|
|
|
|
|
|
|
our $VERSION = '0.01'; |
5
|
2
|
|
|
2
|
|
10
|
use base 'Exporter'; |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
344
|
|
6
|
|
|
|
|
|
|
our @EXPORT = qw/construct_fixture/; |
7
|
2
|
|
|
2
|
|
2065
|
use Params::Validate ':all'; |
|
2
|
|
|
|
|
37648
|
|
|
2
|
|
|
|
|
616
|
|
8
|
2
|
|
|
2
|
|
17
|
use Carp (); |
|
2
|
|
|
|
|
8
|
|
|
2
|
|
|
|
|
29
|
|
9
|
2
|
|
|
2
|
|
2013
|
use Kwalify (); |
|
2
|
|
|
|
|
15531
|
|
|
2
|
|
|
|
|
809
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
sub construct_fixture { |
12
|
0
|
|
|
0
|
1
|
|
my %args = validate( |
13
|
|
|
|
|
|
|
@_ => +{ |
14
|
|
|
|
|
|
|
db => 1, |
15
|
|
|
|
|
|
|
fixture => 1, |
16
|
|
|
|
|
|
|
} |
17
|
|
|
|
|
|
|
); |
18
|
|
|
|
|
|
|
|
19
|
0
|
|
|
|
|
|
my $fixture = _validate_fixture(_load_fixture($args{fixture})); |
20
|
0
|
|
|
|
|
|
_delete_all($args{db}); |
21
|
0
|
|
|
|
|
|
return _insert($args{db}, $fixture); |
22
|
|
|
|
|
|
|
} |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
sub _load_fixture { |
25
|
0
|
|
|
0
|
|
|
my $stuff = shift; |
26
|
|
|
|
|
|
|
|
27
|
0
|
0
|
|
|
|
|
if (ref $stuff) { |
28
|
0
|
0
|
|
|
|
|
if (ref $stuff eq 'ARRAY') { |
29
|
0
|
|
|
|
|
|
return $stuff; |
30
|
|
|
|
|
|
|
} else { |
31
|
0
|
|
|
|
|
|
Carp::croak "invalid fixture stuff. should be ARRAY: $stuff"; |
32
|
|
|
|
|
|
|
} |
33
|
|
|
|
|
|
|
} else { |
34
|
0
|
|
|
|
|
|
require YAML::Syck; |
35
|
0
|
|
|
|
|
|
return YAML::Syck::LoadFile($stuff); |
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
sub _validate_fixture { |
40
|
0
|
|
|
0
|
|
|
my $stuff = shift; |
41
|
|
|
|
|
|
|
|
42
|
0
|
|
|
|
|
|
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
|
0
|
|
|
|
|
|
$stuff; |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
sub _delete_all { |
63
|
0
|
|
|
0
|
|
|
my $db = shift; |
64
|
0
|
|
|
|
|
|
$db->delete($_) for |
|
0
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
keys %{$db->schema->schema_info}; |
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
sub _insert { |
69
|
0
|
|
|
0
|
|
|
my ($db, $fixture) = @_; |
70
|
|
|
|
|
|
|
|
71
|
0
|
|
|
|
|
|
my $result = {}; |
72
|
0
|
|
|
|
|
|
for my $row ( @{ $fixture } ) { |
|
0
|
|
|
|
|
|
|
73
|
0
|
|
|
|
|
|
$result->{ $row->{name} } = $db->insert($row->{table}, $row->{data}); |
74
|
|
|
|
|
|
|
} |
75
|
0
|
|
|
|
|
|
return $result; |
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
1; |
79
|
|
|
|
|
|
|
__END__ |