line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# $Id: Table.pm 4 2007-09-13 10:16:35Z asksol $ |
2
|
|
|
|
|
|
|
# $Source$ |
3
|
|
|
|
|
|
|
# $Author: asksol $ |
4
|
|
|
|
|
|
|
# $HeadURL: https://class-dot-model.googlecode.com/svn/trunk/lib/Class/Dot/Model/Table.pm $ |
5
|
|
|
|
|
|
|
# $Revision: 4 $ |
6
|
|
|
|
|
|
|
# $Date: 2007-09-13 12:16:35 +0200 (Thu, 13 Sep 2007) $ |
7
|
|
|
|
|
|
|
package Class::Dot::Model::Table; |
8
|
|
|
|
|
|
|
|
9
|
1
|
|
|
1
|
|
2984
|
use strict; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
54
|
|
10
|
1
|
|
|
1
|
|
7
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
38
|
|
11
|
1
|
|
|
1
|
|
6
|
use version; our $VERSION = qv('0.1.3'); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
20
|
|
12
|
1
|
|
|
1
|
|
169
|
use 5.006_001; |
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
47
|
|
13
|
|
|
|
|
|
|
|
14
|
1
|
|
|
1
|
|
7
|
use Carp qw(croak); |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
222
|
|
15
|
1
|
|
|
1
|
|
1330
|
use English qw( -no_match_vars ); |
|
1
|
|
|
|
|
5714
|
|
|
1
|
|
|
|
|
8
|
|
16
|
1
|
|
|
1
|
|
659
|
use Params::Util qw(_ARRAY); |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
59
|
|
17
|
1
|
|
|
|
|
9
|
use Class::Dot::Model::Util qw( |
18
|
|
|
|
|
|
|
push_base_class run_as_call_class |
19
|
|
|
|
|
|
|
install_coderef FQDN |
20
|
1
|
|
|
1
|
|
568
|
); |
|
1
|
|
|
|
|
4
|
|
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
my $BASE_CLASS = 'DBIx::Class'; |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
my @DEFAULT_DBIC_COMPONENTS = qw( |
25
|
|
|
|
|
|
|
PK::Auto |
26
|
|
|
|
|
|
|
Core |
27
|
|
|
|
|
|
|
); |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
my $UPLEVEL = 2; |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
sub requires { |
32
|
0
|
|
|
0
|
1
|
0
|
my @requires = map { join q{::}, $BASE_CLASS, $_ } @DEFAULT_DBIC_COMPONENTS; |
|
0
|
|
|
|
|
0
|
|
33
|
0
|
|
|
|
|
0
|
unshift @requires, $BASE_CLASS; |
34
|
0
|
|
|
|
|
0
|
return @requires; |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
my %RELATIONSHIPS_FOR; |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
sub import { |
40
|
1
|
|
|
1
|
|
12
|
my $class = shift; |
41
|
1
|
|
|
|
|
3
|
my $call_class = caller 0; |
42
|
|
|
|
|
|
|
|
43
|
1
|
|
|
|
|
3
|
push_base_class($BASE_CLASS => $call_class); |
44
|
|
|
|
|
|
|
|
45
|
1
|
|
|
|
|
5
|
run_as_call_class( |
46
|
|
|
|
|
|
|
$call_class, 'load_components', @DEFAULT_DBIC_COMPONENTS |
47
|
|
|
|
|
|
|
); |
48
|
|
|
|
|
|
|
|
49
|
1
|
50
|
|
|
|
21
|
return if not scalar @_; |
50
|
|
|
|
|
|
|
|
51
|
0
|
|
|
|
|
|
my @SUBS_TO_EXPORT = qw( |
52
|
|
|
|
|
|
|
Table |
53
|
|
|
|
|
|
|
Columns |
54
|
|
|
|
|
|
|
Primary_Key |
55
|
|
|
|
|
|
|
RELATIONSHIPS |
56
|
|
|
|
|
|
|
); |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
my %SUBROUTINES = ( |
59
|
|
|
|
|
|
|
Table => sub { |
60
|
0
|
|
|
0
|
|
|
return $call_class->table(@_); |
61
|
|
|
|
|
|
|
}, |
62
|
|
|
|
|
|
|
Columns => sub { |
63
|
0
|
|
|
0
|
|
|
my @columns = @_; |
64
|
0
|
|
|
|
|
|
$call_class->add_columns(@columns); |
65
|
1
|
|
|
1
|
|
6
|
no strict 'refs'; ## no critic; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
527
|
|
66
|
0
|
|
|
|
|
|
*{ FQDN($call_class, 'COLUMNS') } = sub { |
67
|
0
|
0
|
|
|
|
|
return wantarray ? @columns : \@columns; |
68
|
0
|
|
|
|
|
|
}; |
69
|
|
|
|
|
|
|
}, |
70
|
|
|
|
|
|
|
Primary_Key => sub { |
71
|
0
|
|
|
0
|
|
|
return $call_class->set_primary_key(@_); |
72
|
|
|
|
|
|
|
}, |
73
|
|
|
|
|
|
|
Has_Many => sub { |
74
|
0
|
|
|
0
|
|
|
$call_class->has_many(@_); |
75
|
0
|
|
|
|
|
|
$RELATIONSHIPS_FOR{$call_class}{$_[0]} = 1; |
76
|
0
|
|
|
|
|
|
return; |
77
|
|
|
|
|
|
|
}, |
78
|
|
|
|
|
|
|
Belongs_To => sub { |
79
|
0
|
|
|
0
|
|
|
$call_class->belongs_to(@_); |
80
|
0
|
|
|
|
|
|
$RELATIONSHIPS_FOR{$call_class}{$_[0]} = 1; |
81
|
|
|
|
|
|
|
}, |
82
|
|
|
|
|
|
|
Many_To_Many => sub { |
83
|
0
|
|
|
0
|
|
|
$call_class->many_to_many(@_); |
84
|
0
|
|
|
|
|
|
$RELATIONSHIPS_FOR{$call_class}{$_[0]} = 1; |
85
|
0
|
|
|
|
|
|
return; |
86
|
|
|
|
|
|
|
}, |
87
|
|
|
|
|
|
|
Has_One => sub { |
88
|
0
|
|
|
0
|
|
|
$call_class->has_one(@_); |
89
|
0
|
|
|
|
|
|
$RELATIONSHIPS_FOR{$call_class}{$_[0]} = 1; |
90
|
|
|
|
|
|
|
}, |
91
|
|
|
|
|
|
|
RELATIONSHIPS => sub { |
92
|
0
|
|
|
0
|
|
|
return $RELATIONSHIPS_FOR{$call_class}; |
93
|
|
|
|
|
|
|
}, |
94
|
0
|
|
|
|
|
|
); |
95
|
|
|
|
|
|
|
|
96
|
0
|
|
|
|
|
|
my %EXPORT_TAGS = ( |
97
|
|
|
|
|
|
|
':all' => [ keys %SUBROUTINES ], |
98
|
|
|
|
|
|
|
':std' => [ keys %SUBROUTINES ], |
99
|
|
|
|
|
|
|
':has_many' => [ @SUBS_TO_EXPORT, 'Has_Many', 'Belongs_To', ], |
100
|
|
|
|
|
|
|
':belongs_to' => [ @SUBS_TO_EXPORT, 'Belongs_To' ], |
101
|
|
|
|
|
|
|
':child' => [ @SUBS_TO_EXPORT, ], |
102
|
|
|
|
|
|
|
':many_to_many' => [ @SUBS_TO_EXPORT, 'Many_To_Many', ], |
103
|
|
|
|
|
|
|
':has_one' => [ @SUBS_TO_EXPORT, 'Has_One', ], |
104
|
|
|
|
|
|
|
); |
105
|
|
|
|
|
|
|
|
106
|
0
|
|
|
|
|
|
for my $arg (@_) { |
107
|
0
|
0
|
|
|
|
|
if ($arg =~ m/^:/xms) { |
108
|
0
|
|
|
|
|
|
my $export_class_ref = $EXPORT_TAGS{$arg}; |
109
|
0
|
0
|
|
|
|
|
croak "No such export class: $arg" |
110
|
|
|
|
|
|
|
if ! _ARRAY($export_class_ref); |
111
|
0
|
|
|
|
|
|
for my $export_sub (@{ $export_class_ref }) { |
|
0
|
|
|
|
|
|
|
112
|
0
|
|
|
|
|
|
install_coderef( |
113
|
|
|
|
|
|
|
$SUBROUTINES{$export_sub} => $call_class, $export_sub |
114
|
|
|
|
|
|
|
); |
115
|
|
|
|
|
|
|
} |
116
|
|
|
|
|
|
|
} |
117
|
|
|
|
|
|
|
else { |
118
|
0
|
|
|
|
|
|
my $coderef = $SUBROUTINES{$arg}; |
119
|
|
|
|
|
|
|
|
120
|
0
|
|
|
|
|
|
install_coderef( |
121
|
|
|
|
|
|
|
$coderef => $call_class, $arg |
122
|
|
|
|
|
|
|
); |
123
|
|
|
|
|
|
|
} |
124
|
|
|
|
|
|
|
} |
125
|
|
|
|
|
|
|
|
126
|
0
|
|
|
|
|
|
return; |
127
|
|
|
|
|
|
|
} |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
1; |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
# TODO |
133
|
|
|
|
|
|
|
#sub isa_Char { ## no critic |
134
|
|
|
|
|
|
|
# my ($size) = @_; |
135
|
|
|
|
|
|
|
# |
136
|
|
|
|
|
|
|
# return { |
137
|
|
|
|
|
|
|
# data_type => 'char', |
138
|
|
|
|
|
|
|
# size => $size, |
139
|
|
|
|
|
|
|
# } |
140
|
|
|
|
|
|
|
#} |
141
|
|
|
|
|
|
|
# |
142
|
|
|
|
|
|
|
#sub isa_Varchar { ## no critic |
143
|
|
|
|
|
|
|
# my ($size) = @_; |
144
|
|
|
|
|
|
|
# |
145
|
|
|
|
|
|
|
# return { |
146
|
|
|
|
|
|
|
# data_type => 'varchar', |
147
|
|
|
|
|
|
|
# size => $size; |
148
|
|
|
|
|
|
|
# } |
149
|
|
|
|
|
|
|
#} |
150
|
|
|
|
|
|
|
# |
151
|
|
|
|
|
|
|
#sub isa_ShortInt { ## no critic |
152
|
|
|
|
|
|
|
# return isa_Integer(4); |
153
|
|
|
|
|
|
|
#} |
154
|
|
|
|
|
|
|
# |
155
|
|
|
|
|
|
|
#sub isa_BigInt { ## no critic |
156
|
|
|
|
|
|
|
# return isa_Integer(64); |
157
|
|
|
|
|
|
|
#} |
158
|
|
|
|
|
|
|
# |
159
|
|
|
|
|
|
|
#sub isa_Integer { ## no critic |
160
|
|
|
|
|
|
|
# my ($size) = @_; |
161
|
|
|
|
|
|
|
# |
162
|
|
|
|
|
|
|
# return { |
163
|
|
|
|
|
|
|
# data_type => 'integer', |
164
|
|
|
|
|
|
|
# size => $size, |
165
|
|
|
|
|
|
|
# } |
166
|
|
|
|
|
|
|
#} |
167
|
|
|
|
|
|
|
# |
168
|
|
|
|
|
|
|
__END__ |