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