line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Teng::Schema; |
2
|
72
|
|
|
72
|
|
134068
|
use strict; |
|
72
|
|
|
|
|
187
|
|
|
72
|
|
|
|
|
2260
|
|
3
|
72
|
|
|
72
|
|
423
|
use warnings; |
|
72
|
|
|
|
|
183
|
|
|
72
|
|
|
|
|
2489
|
|
4
|
72
|
|
|
72
|
|
2758
|
use Teng::Row; |
|
72
|
|
|
|
|
246
|
|
|
72
|
|
|
|
|
2484
|
|
5
|
|
|
|
|
|
|
use Class::Accessor::Lite |
6
|
72
|
|
|
|
|
622
|
rw => [ qw( |
7
|
|
|
|
|
|
|
tables |
8
|
|
|
|
|
|
|
namespace |
9
|
|
|
|
|
|
|
) ] |
10
|
72
|
|
|
72
|
|
2005
|
; |
|
72
|
|
|
|
|
4217
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub new { |
13
|
77
|
|
|
77
|
1
|
298
|
my ($class, %args) = @_; |
14
|
77
|
|
|
|
|
623
|
bless { |
15
|
|
|
|
|
|
|
tables => {}, |
16
|
|
|
|
|
|
|
namespace => '', |
17
|
|
|
|
|
|
|
%args, |
18
|
|
|
|
|
|
|
}, $class; |
19
|
|
|
|
|
|
|
} |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
sub set_default_instance { |
22
|
72
|
|
|
72
|
1
|
291
|
my ($class, $instance) = @_; |
23
|
72
|
|
|
72
|
|
11843
|
no strict 'refs'; |
|
72
|
|
|
|
|
221
|
|
|
72
|
|
|
|
|
2640
|
|
24
|
72
|
|
|
72
|
|
438
|
no warnings 'once'; |
|
72
|
|
|
|
|
201
|
|
|
72
|
|
|
|
|
7034
|
|
25
|
72
|
|
|
|
|
148
|
${"$class\::DEFAULT_INSTANCE"} = $instance; |
|
72
|
|
|
|
|
491
|
|
26
|
|
|
|
|
|
|
} |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
sub instance { |
29
|
582
|
|
|
582
|
1
|
1064
|
my $class = shift; |
30
|
72
|
|
|
72
|
|
538
|
no strict 'refs'; |
|
72
|
|
|
|
|
215
|
|
|
72
|
|
|
|
|
2988
|
|
31
|
72
|
|
|
72
|
|
456
|
no warnings 'once'; |
|
72
|
|
|
|
|
192
|
|
|
72
|
|
|
|
|
26666
|
|
32
|
582
|
|
|
|
|
2002
|
${"$class\::DEFAULT_INSTANCE"}; |
|
582
|
|
|
|
|
4470
|
|
33
|
|
|
|
|
|
|
} |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
sub add_table { |
36
|
247
|
|
|
247
|
1
|
607
|
my ($self, $table) = @_; |
37
|
247
|
|
|
|
|
799
|
$self->{tables}->{$table->name} = $table; |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
sub get_table { |
41
|
524
|
|
|
524
|
1
|
20036
|
my ($self, $name) = @_; |
42
|
524
|
100
|
|
|
|
1470
|
return unless $name; |
43
|
523
|
|
|
|
|
2413
|
$self->{tables}->{$name}; |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
sub get_row_class { |
47
|
72
|
|
|
72
|
1
|
15186
|
my ($self, $table_name) = @_; |
48
|
|
|
|
|
|
|
|
49
|
72
|
|
|
|
|
198
|
my $table = $self->{tables}->{$table_name}; |
50
|
72
|
100
|
|
|
|
483
|
return $table->{row_class} if $table; |
51
|
3
|
|
|
|
|
23
|
return 'Teng::Row'; |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
sub camelize { |
55
|
246
|
|
|
246
|
1
|
522
|
my $s = shift; |
56
|
246
|
|
|
|
|
2286
|
join('', map{ ucfirst $_ } split(/(?<=[A-Za-z])_(?=[A-Za-z])|\b/, $s)); |
|
710
|
|
|
|
|
3126
|
|
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
sub prepare_from_dbh { |
60
|
144
|
|
|
144
|
0
|
650
|
my ($self, $dbh) = @_; |
61
|
|
|
|
|
|
|
|
62
|
144
|
|
|
|
|
1184
|
$_->prepare_from_dbh($dbh) for values %{$self->{tables}}; |
|
144
|
|
|
|
|
3378
|
|
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
|
|
|
|
|
|
|
|