| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Test::FixtureBuilder; |
|
2
|
5
|
|
|
5
|
|
734931
|
use strict; |
|
|
5
|
|
|
|
|
13
|
|
|
|
5
|
|
|
|
|
183
|
|
|
3
|
5
|
|
|
5
|
|
28
|
use warnings; |
|
|
5
|
|
|
|
|
10
|
|
|
|
5
|
|
|
|
|
202
|
|
|
4
|
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
our $VERSION = '0.001'; |
|
6
|
|
|
|
|
|
|
|
|
7
|
5
|
|
|
5
|
|
28
|
use Exporter::Declare; |
|
|
5
|
|
|
|
|
26
|
|
|
|
5
|
|
|
|
|
36
|
|
|
8
|
|
|
|
|
|
|
|
|
9
|
5
|
|
|
5
|
|
7964
|
use Scalar::Util qw/blessed/; |
|
|
5
|
|
|
|
|
10
|
|
|
|
5
|
|
|
|
|
321
|
|
|
10
|
5
|
|
|
5
|
|
27
|
use Carp qw/croak confess/; |
|
|
5
|
|
|
|
|
7
|
|
|
|
5
|
|
|
|
|
4902
|
|
|
11
|
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub after_import { |
|
13
|
3
|
|
|
3
|
0
|
405
|
my $class = shift; |
|
14
|
3
|
|
|
|
|
9
|
my ($importer, $specs) = @_; |
|
15
|
3
|
|
|
|
|
9
|
$importer->FIXTURE_BUILDER_META->{class} = $class; |
|
16
|
|
|
|
|
|
|
} |
|
17
|
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
gen_default_export FIXTURE_BUILDER_META => sub { |
|
19
|
|
|
|
|
|
|
my $meta = { class => undef }; |
|
20
|
12
|
|
|
12
|
|
11341
|
return sub { $meta }; |
|
21
|
|
|
|
|
|
|
}; |
|
22
|
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
default_export fixture_db => sub { |
|
24
|
1
|
|
|
1
|
|
374424
|
my $caller = caller; |
|
25
|
1
|
|
|
|
|
19
|
my ($name, $code) = @_; |
|
26
|
|
|
|
|
|
|
|
|
27
|
1
|
50
|
|
|
|
32
|
croak "'$caller' does not have metadata!" |
|
28
|
|
|
|
|
|
|
unless $caller->can('FIXTURE_BUILDER_META'); |
|
29
|
|
|
|
|
|
|
|
|
30
|
1
|
|
|
|
|
78
|
my $meta = $caller->FIXTURE_BUILDER_META; |
|
31
|
|
|
|
|
|
|
|
|
32
|
1
|
50
|
|
|
|
13
|
croak "Cannot set db to '$name', already set to '$meta->{db}'" |
|
33
|
|
|
|
|
|
|
if exists $meta->{db}; |
|
34
|
1
|
|
|
|
|
18
|
$meta->{db} = $name; |
|
35
|
|
|
|
|
|
|
|
|
36
|
1
|
|
|
|
|
62
|
$meta->{builder} = $meta->{class}->new(%$meta); |
|
37
|
|
|
|
|
|
|
|
|
38
|
1
|
|
|
|
|
3
|
my $success = eval { $code->($meta->{builder}); 1 }; |
|
|
1
|
|
|
|
|
19
|
|
|
|
1
|
|
|
|
|
1242
|
|
|
39
|
1
|
|
|
|
|
8
|
my $error = $@; |
|
40
|
|
|
|
|
|
|
|
|
41
|
1
|
|
|
|
|
26
|
delete $meta->{$_} for qw/db dbh builder/; |
|
42
|
|
|
|
|
|
|
|
|
43
|
1
|
50
|
0
|
|
|
6
|
die $error || "Unknown Error" |
|
44
|
|
|
|
|
|
|
unless $success; |
|
45
|
|
|
|
|
|
|
|
|
46
|
1
|
|
|
|
|
4
|
return $name; |
|
47
|
|
|
|
|
|
|
}; |
|
48
|
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
default_export fixture_table => sub { |
|
50
|
2
|
|
|
2
|
|
2402
|
my $caller = caller; |
|
51
|
2
|
|
|
|
|
7
|
my ($name, $code) = @_; |
|
52
|
|
|
|
|
|
|
|
|
53
|
2
|
50
|
|
|
|
23
|
croak "'$caller' does not have metadata!" |
|
54
|
|
|
|
|
|
|
unless $caller->can('FIXTURE_BUILDER_META'); |
|
55
|
|
|
|
|
|
|
|
|
56
|
2
|
|
|
|
|
7
|
my $meta = $caller->FIXTURE_BUILDER_META; |
|
57
|
|
|
|
|
|
|
|
|
58
|
2
|
50
|
|
|
|
10
|
croak "Cannot set table to '$name', already set to '$meta->{table}'" |
|
59
|
|
|
|
|
|
|
if exists $meta->{table}; |
|
60
|
2
|
|
|
|
|
15
|
$meta->{table} = $name; |
|
61
|
|
|
|
|
|
|
|
|
62
|
2
|
|
|
|
|
3
|
my $success = eval { $code->($meta->{builder}, $name); 1 }; |
|
|
2
|
|
|
|
|
7
|
|
|
|
2
|
|
|
|
|
33
|
|
|
63
|
2
|
|
|
|
|
8
|
my $error = $@; |
|
64
|
|
|
|
|
|
|
|
|
65
|
2
|
|
|
|
|
19
|
delete $meta->{$_} for qw/table/; |
|
66
|
|
|
|
|
|
|
|
|
67
|
2
|
50
|
0
|
|
|
11
|
die $error || "Unknown Error" |
|
68
|
|
|
|
|
|
|
unless $success; |
|
69
|
|
|
|
|
|
|
|
|
70
|
2
|
|
|
|
|
11
|
return $name; |
|
71
|
|
|
|
|
|
|
}; |
|
72
|
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
default_export fixture_row => sub { |
|
74
|
6
|
|
|
6
|
|
190
|
my $caller = caller; |
|
75
|
|
|
|
|
|
|
|
|
76
|
6
|
50
|
|
|
|
78
|
croak "'$caller' does not have metadata!" |
|
77
|
|
|
|
|
|
|
unless $caller->can('FIXTURE_BUILDER_META'); |
|
78
|
|
|
|
|
|
|
|
|
79
|
6
|
|
|
|
|
26
|
my $meta = $caller->FIXTURE_BUILDER_META; |
|
80
|
|
|
|
|
|
|
|
|
81
|
6
|
50
|
|
|
|
70
|
my $row = @_ > 1 ? {@_} : $_[0]; |
|
82
|
|
|
|
|
|
|
|
|
83
|
6
|
|
|
|
|
50
|
return $meta->{builder}->insert_row( $meta->{table} => $row ); |
|
84
|
|
|
|
|
|
|
}; |
|
85
|
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
sub name_to_handle { |
|
87
|
0
|
|
|
0
|
1
|
0
|
my $class = shift; |
|
88
|
0
|
|
|
|
|
0
|
my ($name) = @_; |
|
89
|
|
|
|
|
|
|
|
|
90
|
0
|
0
|
|
|
|
0
|
return $name if blessed $name; |
|
91
|
|
|
|
|
|
|
|
|
92
|
0
|
|
|
|
|
0
|
croak "I don't know how to convert '$name' to a database handle, override name_to_handle()"; |
|
93
|
|
|
|
|
|
|
} |
|
94
|
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
sub new { |
|
96
|
2
|
|
|
2
|
1
|
223381
|
my $class = shift; |
|
97
|
2
|
|
|
|
|
19
|
my %params = @_; |
|
98
|
|
|
|
|
|
|
|
|
99
|
2
|
|
|
|
|
29
|
my $self = bless {}, $class; |
|
100
|
|
|
|
|
|
|
|
|
101
|
2
|
|
|
|
|
25
|
for my $field ( keys %params ) { |
|
102
|
3
|
50
|
|
|
|
67
|
croak "'$field' is not a valid accessor for '$class'" |
|
103
|
|
|
|
|
|
|
unless $self->can($field); |
|
104
|
|
|
|
|
|
|
|
|
105
|
3
|
|
|
|
|
32
|
$self->$field($params{$field}); |
|
106
|
|
|
|
|
|
|
} |
|
107
|
|
|
|
|
|
|
|
|
108
|
2
|
|
|
|
|
30
|
return $self; |
|
109
|
|
|
|
|
|
|
} |
|
110
|
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
sub db { |
|
112
|
2
|
|
|
2
|
1
|
5
|
my $self = shift; |
|
113
|
|
|
|
|
|
|
|
|
114
|
2
|
50
|
|
|
|
10
|
return $self->dbh |
|
115
|
|
|
|
|
|
|
unless @_; |
|
116
|
|
|
|
|
|
|
|
|
117
|
2
|
|
|
|
|
10
|
my ($name) = @_; |
|
118
|
|
|
|
|
|
|
|
|
119
|
2
|
|
|
|
|
9
|
my $dbh = $self->name_to_handle($name); |
|
120
|
2
|
50
|
|
|
|
28
|
croak "Could not get db handle for '$name'" |
|
121
|
|
|
|
|
|
|
unless $dbh; |
|
122
|
|
|
|
|
|
|
|
|
123
|
2
|
|
|
|
|
31
|
$self->dbh( $dbh ); |
|
124
|
|
|
|
|
|
|
} |
|
125
|
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
for my $field (qw/dbh class/) { |
|
127
|
|
|
|
|
|
|
my $accessor = sub { |
|
128
|
15
|
|
|
15
|
|
36
|
my $self = shift; |
|
129
|
|
|
|
|
|
|
|
|
130
|
15
|
50
|
33
|
|
|
640
|
croak "Accessor '$field' called without instance!" |
|
131
|
|
|
|
|
|
|
unless blessed $self && $self->isa( __PACKAGE__ ); |
|
132
|
|
|
|
|
|
|
|
|
133
|
15
|
100
|
|
|
|
82
|
($self->{$field}) = @_ if @_; |
|
134
|
|
|
|
|
|
|
|
|
135
|
15
|
|
|
|
|
104
|
return $self->{$field}; |
|
136
|
|
|
|
|
|
|
}; |
|
137
|
5
|
|
|
5
|
|
29
|
no strict 'refs'; |
|
|
5
|
|
|
|
|
10
|
|
|
|
5
|
|
|
|
|
1424
|
|
|
138
|
|
|
|
|
|
|
*$field = $accessor; |
|
139
|
|
|
|
|
|
|
} |
|
140
|
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
sub insert_row { |
|
142
|
12
|
|
|
12
|
1
|
4046
|
my $self = shift; |
|
143
|
12
|
|
|
|
|
39
|
my ($table, $row) = @_; |
|
144
|
|
|
|
|
|
|
|
|
145
|
12
|
|
33
|
|
|
46
|
my $dbh = $self->dbh || croak "No database handle set!"; |
|
146
|
|
|
|
|
|
|
|
|
147
|
12
|
|
|
|
|
340
|
my $quoted_table = $dbh->quote_identifier(undef, undef, $table); |
|
148
|
12
|
|
|
|
|
1314
|
my @vals = values %$row; |
|
149
|
12
|
|
|
|
|
50
|
my $cols = join ',' => map { $dbh->quote_identifier($_) } keys %$row; |
|
|
24
|
|
|
|
|
701
|
|
|
150
|
12
|
|
|
|
|
633
|
my $vals = join ',' => map { '?' } @vals; |
|
|
24
|
|
|
|
|
84
|
|
|
151
|
|
|
|
|
|
|
|
|
152
|
12
|
|
|
|
|
136
|
my $sth = $dbh->prepare("INSERT INTO $quoted_table ($cols) VALUES($vals)"); |
|
153
|
12
|
|
|
|
|
326079
|
$sth->execute(@vals); |
|
154
|
|
|
|
|
|
|
|
|
155
|
12
|
|
50
|
|
|
138
|
return eval { $dbh->last_insert_id } || 0; |
|
156
|
|
|
|
|
|
|
} |
|
157
|
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
sub insert_rows { |
|
159
|
1
|
|
|
1
|
1
|
46
|
my $self = shift; |
|
160
|
1
|
|
|
|
|
3
|
my ($table, @rows) = @_; |
|
161
|
|
|
|
|
|
|
|
|
162
|
1
|
|
|
|
|
14
|
$self->insert_row($table => $_) for @rows; |
|
163
|
|
|
|
|
|
|
} |
|
164
|
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
1; |
|
166
|
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
__END__ |