line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Test::Fixture::DBI::Util; |
2
|
|
|
|
|
|
|
|
3
|
3
|
|
|
3
|
|
1601
|
use strict; |
|
3
|
|
|
|
|
5
|
|
|
3
|
|
|
|
|
103
|
|
4
|
3
|
|
|
3
|
|
14
|
use warnings; |
|
3
|
|
|
|
|
5
|
|
|
3
|
|
|
|
|
87
|
|
5
|
3
|
|
|
3
|
|
15
|
use Exporter qw(import); |
|
3
|
|
|
|
|
5
|
|
|
3
|
|
|
|
|
101
|
|
6
|
|
|
|
|
|
|
|
7
|
3
|
|
|
3
|
|
15
|
use Carp; |
|
3
|
|
|
|
|
3
|
|
|
3
|
|
|
|
|
229
|
|
8
|
3
|
|
|
3
|
|
6780
|
use DBI; |
|
3
|
|
|
|
|
54292
|
|
|
3
|
|
|
|
|
196
|
|
9
|
3
|
|
|
3
|
|
2640
|
use YAML::Syck; |
|
3
|
|
|
|
|
6036
|
|
|
3
|
|
|
|
|
204
|
|
10
|
3
|
|
|
3
|
|
2284
|
use UNIVERSAL::require; |
|
3
|
|
|
|
|
4822
|
|
|
3
|
|
|
|
|
39
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
our $VERSION = '0.01'; |
13
|
|
|
|
|
|
|
our @EXPORT = qw(make_database_yaml make_fixture_yaml); |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
sub make_database_yaml { |
16
|
0
|
|
|
0
|
1
|
|
my ( $dbh, $filename ) = @_; |
17
|
0
|
|
|
|
|
|
my $driver = $dbh->{Driver}{Name}; |
18
|
0
|
|
|
|
|
|
my $driver_class = __PACKAGE__ . '::' . $driver; |
19
|
0
|
0
|
|
|
|
|
unless ( eval { $driver_class->require; 1 } ) { |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
20
|
0
|
|
|
|
|
|
croak( sprintf( 'Driver %s is not supported yet', $driver ) ); |
21
|
|
|
|
|
|
|
} |
22
|
0
|
|
|
|
|
|
my $data = $driver_class->make_database($dbh); |
23
|
0
|
0
|
|
|
|
|
if ($filename) { |
24
|
0
|
|
|
|
|
|
YAML::Syck::DumpFile( $filename, $data ); |
25
|
|
|
|
|
|
|
} |
26
|
|
|
|
|
|
|
else { |
27
|
0
|
|
|
|
|
|
return $data; |
28
|
|
|
|
|
|
|
} |
29
|
|
|
|
|
|
|
} |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
sub make_fixture_yaml { |
32
|
0
|
|
|
0
|
1
|
|
my ( $dbh, $schema, $name_column, $sql, $filename ) = @_; |
33
|
0
|
|
|
|
|
|
my $rows = $dbh->selectall_arrayref( $sql, +{ Slice => +{} } ); |
34
|
|
|
|
|
|
|
|
35
|
0
|
|
|
|
|
|
my @data; |
36
|
0
|
|
|
|
|
|
for my $row (@$rows) { |
37
|
0
|
|
|
|
|
|
push( |
38
|
|
|
|
|
|
|
@data, |
39
|
|
|
|
|
|
|
+{ |
40
|
|
|
|
|
|
|
name => ref $name_column |
41
|
0
|
0
|
|
|
|
|
? join( '_', map { $row->{$_} } @$name_column ) |
42
|
|
|
|
|
|
|
: $row->{$name_column}, |
43
|
|
|
|
|
|
|
schema => $schema, |
44
|
|
|
|
|
|
|
data => $row, |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
); |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
|
49
|
0
|
0
|
|
|
|
|
if ($filename) { |
50
|
0
|
|
|
|
|
|
YAML::Syck::DumpFile( $filename, \@data ); |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
else { |
53
|
0
|
|
|
|
|
|
return \@data; |
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
1; |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
__END__ |