line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Test::Fixture::DBIC::Schema; |
2
|
1
|
|
|
1
|
|
6
|
use strict; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
718
|
|
3
|
1
|
|
|
1
|
|
4
|
use warnings; |
|
1
|
|
|
|
|
0
|
|
|
1
|
|
|
|
|
37
|
|
4
|
|
|
|
|
|
|
our $VERSION = '0.04'; |
5
|
1
|
|
|
1
|
|
3
|
use base 'Exporter'; |
|
1
|
|
|
|
|
0
|
|
|
1
|
|
|
|
|
85
|
|
6
|
|
|
|
|
|
|
our @EXPORT = qw/construct_fixture/; |
7
|
1
|
|
|
1
|
|
444
|
use Params::Validate ':all'; |
|
1
|
|
|
|
|
6908
|
|
|
1
|
|
|
|
|
161
|
|
8
|
1
|
|
|
1
|
|
423
|
use Kwalify (); |
|
1
|
|
|
|
|
4037
|
|
|
1
|
|
|
|
|
17
|
|
9
|
1
|
|
|
1
|
|
5
|
use Carp; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
307
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
sub construct_fixture { |
12
|
0
|
|
|
0
|
1
|
|
validate( |
13
|
|
|
|
|
|
|
@_ => +{ |
14
|
|
|
|
|
|
|
schema => +{ isa => 'DBIx::Class::Schema' }, |
15
|
|
|
|
|
|
|
fixture => 1, |
16
|
|
|
|
|
|
|
} |
17
|
|
|
|
|
|
|
); |
18
|
0
|
|
|
|
|
|
my %args = @_; |
19
|
|
|
|
|
|
|
|
20
|
0
|
|
|
|
|
|
my $fixture = _validate_fixture(_load_fixture($args{fixture})); |
21
|
0
|
|
|
|
|
|
_delete_all($args{schema}); |
22
|
0
|
|
|
|
|
|
return _insert($args{schema}, $fixture); |
23
|
|
|
|
|
|
|
} |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
sub _load_fixture { |
26
|
0
|
|
|
0
|
|
|
my $stuff = shift; |
27
|
|
|
|
|
|
|
|
28
|
0
|
0
|
|
|
|
|
if (ref $stuff) { |
29
|
0
|
0
|
|
|
|
|
if (ref $stuff eq 'ARRAY') { |
30
|
0
|
|
|
|
|
|
return $stuff; |
31
|
|
|
|
|
|
|
} else { |
32
|
0
|
|
|
|
|
|
croak "invalid fixture stuff. should be ARRAY: $stuff"; |
33
|
|
|
|
|
|
|
} |
34
|
|
|
|
|
|
|
} else { |
35
|
0
|
|
|
|
|
|
require YAML::Syck; |
36
|
0
|
|
|
|
|
|
return YAML::Syck::LoadFile($stuff); |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
sub _validate_fixture { |
41
|
0
|
|
|
0
|
|
|
my $stuff = shift; |
42
|
|
|
|
|
|
|
|
43
|
0
|
|
|
|
|
|
Kwalify::validate( |
44
|
|
|
|
|
|
|
{ |
45
|
|
|
|
|
|
|
type => 'seq', |
46
|
|
|
|
|
|
|
sequence => [ |
47
|
|
|
|
|
|
|
{ |
48
|
|
|
|
|
|
|
type => 'map', |
49
|
|
|
|
|
|
|
mapping => { |
50
|
|
|
|
|
|
|
schema => { type => 'str', required => 1 }, |
51
|
|
|
|
|
|
|
name => { type => 'str', required => 1 }, |
52
|
|
|
|
|
|
|
data => { type => 'any', required => 1 }, |
53
|
|
|
|
|
|
|
}, |
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
] |
56
|
|
|
|
|
|
|
}, |
57
|
|
|
|
|
|
|
$stuff |
58
|
|
|
|
|
|
|
); |
59
|
|
|
|
|
|
|
|
60
|
0
|
|
|
|
|
|
$stuff; |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
sub _delete_all { |
64
|
0
|
|
|
0
|
|
|
my $schema = shift; |
65
|
|
|
|
|
|
|
|
66
|
0
|
|
|
|
|
|
$schema->resultset($_)->delete for |
67
|
0
|
|
|
|
|
|
grep { $schema->source_registrations->{$_}->isa('DBIx::Class::ResultSource::Table') } |
68
|
|
|
|
|
|
|
$schema->sources; |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
sub _insert { |
72
|
0
|
|
|
0
|
|
|
my ($schema, $fixture) = @_; |
73
|
|
|
|
|
|
|
|
74
|
0
|
|
|
|
|
|
my $result = {}; |
75
|
0
|
|
|
|
|
|
for my $row ( @{ $fixture } ) { |
|
0
|
|
|
|
|
|
|
76
|
0
|
|
|
|
|
|
$schema->resultset( $row->{schema} )->create( $row->{data} ); |
77
|
0
|
|
|
|
|
|
$result->{ $row->{name} } = $schema->resultset( $row->{schema} )->find( $row->{data} ); |
78
|
|
|
|
|
|
|
} |
79
|
0
|
|
|
|
|
|
return $result; |
80
|
|
|
|
|
|
|
} |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
1; |
83
|
|
|
|
|
|
|
__END__ |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
=encoding utf8 |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
=for stopwords Fushihara Kan |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
=head1 NAME |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
Test::Fixture::DBIC::Schema - load fixture data to storage. |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
=head1 SYNOPSIS |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
# in your t/*.t |
96
|
|
|
|
|
|
|
use Test::Fixture::DBIC::Schema; |
97
|
|
|
|
|
|
|
my $data = construct_fixture( |
98
|
|
|
|
|
|
|
schema => $self->model, |
99
|
|
|
|
|
|
|
fixture => 'fixture.yaml', |
100
|
|
|
|
|
|
|
); |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
# in your fixture.yaml |
103
|
|
|
|
|
|
|
- schema: Entry |
104
|
|
|
|
|
|
|
name: entry1 |
105
|
|
|
|
|
|
|
data: |
106
|
|
|
|
|
|
|
id: 1 |
107
|
|
|
|
|
|
|
title: my policy |
108
|
|
|
|
|
|
|
body: shut the f*ck up and write some code |
109
|
|
|
|
|
|
|
timestamp: 2008-01-01 11:22:44 |
110
|
|
|
|
|
|
|
- schema::Entry |
111
|
|
|
|
|
|
|
name: entry2 |
112
|
|
|
|
|
|
|
data: |
113
|
|
|
|
|
|
|
id: 2 |
114
|
|
|
|
|
|
|
title: please join |
115
|
|
|
|
|
|
|
body: #coderepos-en@freenode. |
116
|
|
|
|
|
|
|
timestamp: 2008-02-23 23:22:58 |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
=head1 DESCRIPTION |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
Test::Fixture::DBIC::Schema is fixture data loader for DBIx::Class::Schema. |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
=head1 METHODS |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
=head2 construct_fixture |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
my $data = construct_fixture( |
127
|
|
|
|
|
|
|
schema => $self->model, |
128
|
|
|
|
|
|
|
fixture => 'fixture.yaml', |
129
|
|
|
|
|
|
|
); |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
construct your fixture. |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
=head1 CODE COVERAGE |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
---------------------------- ------ ------ ------ ------ ------ ------ ------ |
136
|
|
|
|
|
|
|
File stmt bran cond sub pod time total |
137
|
|
|
|
|
|
|
---------------------------- ------ ------ ------ ------ ------ ------ ------ |
138
|
|
|
|
|
|
|
...st/Fixture/DBIC/Schema.pm 100.0 100.0 n/a 100.0 100.0 100.0 100.0 |
139
|
|
|
|
|
|
|
Total 100.0 100.0 n/a 100.0 100.0 100.0 100.0 |
140
|
|
|
|
|
|
|
---------------------------- ------ ------ ------ ------ ------ ------ ------ |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
=head1 AUTHOR |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
Tokuhiro Matsuno E<lt>tokuhirom@gmail.comE<gt> |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
Kan Fushihara |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
=head1 SEE ALSO |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
L<DBIx::Class>, L<Kwalify> |
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
=head1 LICENSE |
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or modify |
155
|
|
|
|
|
|
|
it under the same terms as Perl itself. |
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
=cut |