| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Teng::Schema::Loader; |
|
2
|
2
|
|
|
2
|
|
1128
|
use strict; |
|
|
2
|
|
|
|
|
5
|
|
|
|
2
|
|
|
|
|
49
|
|
|
3
|
2
|
|
|
2
|
|
8
|
use warnings; |
|
|
2
|
|
|
|
|
4
|
|
|
|
2
|
|
|
|
|
43
|
|
|
4
|
2
|
|
|
2
|
|
709
|
use DBIx::Inspector; |
|
|
2
|
|
|
|
|
8681
|
|
|
|
2
|
|
|
|
|
43
|
|
|
5
|
2
|
|
|
2
|
|
12
|
use Teng::Schema; |
|
|
2
|
|
|
|
|
4
|
|
|
|
2
|
|
|
|
|
41
|
|
|
6
|
2
|
|
|
2
|
|
304
|
use Teng::Schema::Table; |
|
|
2
|
|
|
|
|
6
|
|
|
|
2
|
|
|
|
|
52
|
|
|
7
|
2
|
|
|
2
|
|
13
|
use Carp (); |
|
|
2
|
|
|
|
|
4
|
|
|
|
2
|
|
|
|
|
22
|
|
|
8
|
2
|
|
|
2
|
|
9
|
use Class::Load (); |
|
|
2
|
|
|
|
|
2
|
|
|
|
2
|
|
|
|
|
125
|
|
|
9
|
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
sub load { |
|
11
|
4
|
|
|
4
|
1
|
31407
|
my $class = shift; |
|
12
|
4
|
50
|
|
|
|
27
|
my %args = @_==1 ? %{$_[0]} : @_; |
|
|
0
|
|
|
|
|
0
|
|
|
13
|
|
|
|
|
|
|
|
|
14
|
4
|
50
|
|
|
|
18
|
my $namespace = $args{namespace} or Carp::croak("missing mandatory parameter 'namespace'"); |
|
15
|
|
|
|
|
|
|
|
|
16
|
4
|
100
|
|
|
|
19
|
Class::Load::load_optional_class($namespace) or do { |
|
17
|
|
|
|
|
|
|
# make teng class automatically |
|
18
|
1
|
|
|
|
|
514
|
require Teng; |
|
19
|
2
|
|
|
2
|
|
14
|
no strict 'refs'; @{"$namespace\::ISA"} = ('Teng'); |
|
|
2
|
|
|
|
|
3
|
|
|
|
2
|
|
|
|
|
413
|
|
|
|
1
|
|
|
|
|
3
|
|
|
|
1
|
|
|
|
|
15
|
|
|
20
|
|
|
|
|
|
|
}; |
|
21
|
|
|
|
|
|
|
|
|
22
|
4
|
|
|
|
|
370
|
my $teng = $namespace->new(%args, loader => 1); |
|
23
|
4
|
|
|
|
|
18
|
my $dbh = $teng->dbh; |
|
24
|
4
|
50
|
|
|
|
10
|
unless ($dbh) { |
|
25
|
0
|
|
|
|
|
0
|
Carp::croak("missing mandatory parameter 'dbh' or 'connect_info'"); |
|
26
|
|
|
|
|
|
|
} |
|
27
|
|
|
|
|
|
|
|
|
28
|
4
|
|
|
|
|
21
|
my $schema = Teng::Schema->new(namespace => $args{namespace}); |
|
29
|
|
|
|
|
|
|
|
|
30
|
4
|
|
|
|
|
21
|
my $inspector = DBIx::Inspector->new(dbh => $dbh); |
|
31
|
4
|
|
|
|
|
2819
|
for my $table_info ($inspector->tables) { |
|
32
|
|
|
|
|
|
|
|
|
33
|
4
|
|
|
|
|
3184
|
my $table_name = $table_info->name; |
|
34
|
4
|
|
|
|
|
29
|
my @table_pk = map { $_->name } $table_info->primary_key; |
|
|
4
|
|
|
|
|
6302
|
|
|
35
|
4
|
|
|
|
|
39
|
my @col_names; |
|
36
|
|
|
|
|
|
|
my %sql_types; |
|
37
|
4
|
|
|
|
|
16
|
for my $col ($table_info->columns) { |
|
38
|
16
|
|
|
|
|
4798
|
push @col_names, $col->name; |
|
39
|
16
|
|
|
|
|
71
|
$sql_types{$col->name} = $col->data_type; |
|
40
|
|
|
|
|
|
|
} |
|
41
|
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
$schema->add_table( |
|
43
|
4
|
|
|
|
|
54
|
Teng::Schema::Table->new( |
|
44
|
|
|
|
|
|
|
columns => \@col_names, |
|
45
|
|
|
|
|
|
|
name => $table_name, |
|
46
|
|
|
|
|
|
|
primary_keys => \@table_pk, |
|
47
|
|
|
|
|
|
|
sql_types => \%sql_types, |
|
48
|
|
|
|
|
|
|
inflators => [], |
|
49
|
|
|
|
|
|
|
deflators => [], |
|
50
|
|
|
|
|
|
|
row_class => join '::', $namespace, 'Row', Teng::Schema::camelize($table_name), |
|
51
|
|
|
|
|
|
|
) |
|
52
|
|
|
|
|
|
|
); |
|
53
|
|
|
|
|
|
|
} |
|
54
|
|
|
|
|
|
|
|
|
55
|
4
|
|
|
|
|
49
|
$schema->prepare_from_dbh($dbh); |
|
56
|
4
|
|
|
|
|
113
|
$teng->schema($schema); |
|
57
|
4
|
|
|
|
|
35
|
return $teng; |
|
58
|
|
|
|
|
|
|
} |
|
59
|
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
1; |
|
61
|
|
|
|
|
|
|
__END__ |
|
62
|
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
=head1 NAME |
|
64
|
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
Teng::Schema::Loader - Dynamic Schema Loader |
|
66
|
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
68
|
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
use Teng; |
|
70
|
|
|
|
|
|
|
use Teng::Schema::Loader; |
|
71
|
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
my $teng = Teng::Schema::Loader->load( |
|
73
|
|
|
|
|
|
|
dbh => $dbh, |
|
74
|
|
|
|
|
|
|
namespace => 'MyAPP::DB' |
|
75
|
|
|
|
|
|
|
); |
|
76
|
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
=head1 DESCRIPTION |
|
78
|
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
L<Teng::Schema::Loader> loads schema directly from DB. |
|
80
|
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
=head1 CLASS METHODS |
|
82
|
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
=over 4 |
|
84
|
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
=item Teng::Schema::Loader->load(%attr) |
|
86
|
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
This is the method to load schema from DB. It returns the instance of the given C<namespace> class which inherits L<Teng>. |
|
88
|
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
The arguments are: |
|
90
|
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
=over 4 |
|
92
|
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
=item C<dbh> |
|
94
|
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
Database handle from DBI. |
|
96
|
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
=item namespace |
|
98
|
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
your project name space. |
|
100
|
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
=back |
|
102
|
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
=back |
|
104
|
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
=cut |