line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Teng::Schema; |
2
|
71
|
|
|
71
|
|
64486
|
use strict; |
|
71
|
|
|
|
|
142
|
|
|
71
|
|
|
|
|
1638
|
|
3
|
71
|
|
|
71
|
|
309
|
use warnings; |
|
71
|
|
|
|
|
129
|
|
|
71
|
|
|
|
|
1436
|
|
4
|
71
|
|
|
71
|
|
1522
|
use Teng::Row; |
|
71
|
|
|
|
|
142
|
|
|
71
|
|
|
|
|
1673
|
|
5
|
|
|
|
|
|
|
use Class::Accessor::Lite |
6
|
71
|
|
|
|
|
419
|
rw => [ qw( |
7
|
|
|
|
|
|
|
tables |
8
|
|
|
|
|
|
|
namespace |
9
|
|
|
|
|
|
|
) ] |
10
|
71
|
|
|
71
|
|
1387
|
; |
|
71
|
|
|
|
|
2503
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub new { |
13
|
76
|
|
|
76
|
1
|
289
|
my ($class, %args) = @_; |
14
|
76
|
|
|
|
|
457
|
bless { |
15
|
|
|
|
|
|
|
tables => {}, |
16
|
|
|
|
|
|
|
namespace => '', |
17
|
|
|
|
|
|
|
%args, |
18
|
|
|
|
|
|
|
}, $class; |
19
|
|
|
|
|
|
|
} |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
sub set_default_instance { |
22
|
71
|
|
|
71
|
1
|
202
|
my ($class, $instance) = @_; |
23
|
71
|
|
|
71
|
|
8975
|
no strict 'refs'; |
|
71
|
|
|
|
|
228
|
|
|
71
|
|
|
|
|
1762
|
|
24
|
71
|
|
|
71
|
|
336
|
no warnings 'once'; |
|
71
|
|
|
|
|
149
|
|
|
71
|
|
|
|
|
4669
|
|
25
|
71
|
|
|
|
|
138
|
${"$class\::DEFAULT_INSTANCE"} = $instance; |
|
71
|
|
|
|
|
391
|
|
26
|
|
|
|
|
|
|
} |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
sub instance { |
29
|
573
|
|
|
573
|
1
|
972
|
my $class = shift; |
30
|
71
|
|
|
71
|
|
375
|
no strict 'refs'; |
|
71
|
|
|
|
|
155
|
|
|
71
|
|
|
|
|
1630
|
|
31
|
71
|
|
|
71
|
|
316
|
no warnings 'once'; |
|
71
|
|
|
|
|
136
|
|
|
71
|
|
|
|
|
16479
|
|
32
|
573
|
|
|
|
|
846
|
${"$class\::DEFAULT_INSTANCE"}; |
|
573
|
|
|
|
|
2948
|
|
33
|
|
|
|
|
|
|
} |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
sub add_table { |
36
|
243
|
|
|
243
|
1
|
503
|
my ($self, $table) = @_; |
37
|
243
|
|
|
|
|
709
|
$self->{tables}->{$table->name} = $table; |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
sub get_table { |
41
|
515
|
|
|
515
|
1
|
14193
|
my ($self, $name) = @_; |
42
|
515
|
100
|
|
|
|
1303
|
return unless $name; |
43
|
514
|
|
|
|
|
1883
|
$self->{tables}->{$name}; |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
sub get_row_class { |
47
|
72
|
|
|
72
|
1
|
10933
|
my ($self, $table_name) = @_; |
48
|
|
|
|
|
|
|
|
49
|
72
|
|
|
|
|
183
|
my $table = $self->{tables}->{$table_name}; |
50
|
72
|
100
|
|
|
|
371
|
return $table->{row_class} if $table; |
51
|
3
|
|
|
|
|
16
|
return 'Teng::Row'; |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
sub camelize { |
55
|
242
|
|
|
242
|
1
|
401
|
my $s = shift; |
56
|
242
|
|
|
|
|
1731
|
join('', map{ ucfirst $_ } split(/(?<=[A-Za-z])_(?=[A-Za-z])|\b/, $s)); |
|
698
|
|
|
|
|
3558
|
|
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
sub prepare_from_dbh { |
60
|
143
|
|
|
143
|
0
|
400
|
my ($self, $dbh) = @_; |
61
|
|
|
|
|
|
|
|
62
|
143
|
|
|
|
|
271
|
$_->prepare_from_dbh($dbh) for values %{$self->{tables}}; |
|
143
|
|
|
|
|
1079
|
|
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
1; |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
__END__ |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
=head1 NAME |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
Teng::Schema - Schema API for Teng |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
=head1 METHODS |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
=over 4 |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
=item $schema = Teng::Schema->new |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
create new Teng::Schema's object. |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
=item $schema = Teng::Schema->instance |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
Get Teng::Schema's default instance object, was set by C<< Teng::Schema->set_default_instance() >>. |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
=item Teng::Schema->set_default_instance($schema) |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
set default Schema instance. |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
=item $schema->add_table($table); |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
add Teng::Schema::Table's object. |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
=item my $table = $schema->get_table($table_name); |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
get Teng::Schema::Table's object. |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
=item my $row_class = $schema->get_row_class($table_name); |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
get your table row class or Teng::Row class. |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
=item $schema->camelize($string) |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
convert from under_score text to CamelCase one. |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
=back |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
=cut |
108
|
|
|
|
|
|
|
|