| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package DBIx::QuickORM::Schema::Table; |
|
2
|
24
|
|
|
24
|
|
210
|
use strict; |
|
|
24
|
|
|
|
|
62
|
|
|
|
24
|
|
|
|
|
1078
|
|
|
3
|
24
|
|
|
24
|
|
173
|
use warnings; |
|
|
24
|
|
|
|
|
56
|
|
|
|
24
|
|
|
|
|
3366
|
|
|
4
|
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
our $VERSION = '0.000019'; |
|
6
|
|
|
|
|
|
|
|
|
7
|
24
|
|
|
24
|
|
201
|
use Carp qw/croak/; |
|
|
24
|
|
|
|
|
160
|
|
|
|
24
|
|
|
|
|
2048
|
|
|
8
|
24
|
|
|
24
|
|
236
|
use Scalar::Util qw/blessed/; |
|
|
24
|
|
|
|
|
80
|
|
|
|
24
|
|
|
|
|
1758
|
|
|
9
|
24
|
|
|
24
|
|
218
|
use DBIx::QuickORM::Util qw/column_key merge_hash_of_objs clone_hash_of_objs/; |
|
|
24
|
|
|
|
|
73
|
|
|
|
24
|
|
|
|
|
240
|
|
|
10
|
|
|
|
|
|
|
|
|
11
|
24
|
|
|
24
|
|
17523
|
use Role::Tiny::With qw/with/; |
|
|
24
|
|
|
|
|
274295
|
|
|
|
24
|
|
|
|
|
6786
|
|
|
12
|
|
|
|
|
|
|
with 'DBIx::QuickORM::Role::Linked'; |
|
13
|
|
|
|
|
|
|
|
|
14
|
24
|
|
|
|
|
294
|
use DBIx::QuickORM::Util::HashBase qw{ |
|
15
|
|
|
|
|
|
|
+name |
|
16
|
|
|
|
|
|
|
+db_name |
|
17
|
|
|
|
|
|
|
+columns |
|
18
|
|
|
|
|
|
|
<unique |
|
19
|
|
|
|
|
|
|
<row_class |
|
20
|
|
|
|
|
|
|
<row_class_autofill |
|
21
|
|
|
|
|
|
|
<created |
|
22
|
|
|
|
|
|
|
<compiled |
|
23
|
|
|
|
|
|
|
<is_temp |
|
24
|
|
|
|
|
|
|
<links |
|
25
|
|
|
|
|
|
|
<indexes |
|
26
|
|
|
|
|
|
|
<primary_key |
|
27
|
|
|
|
|
|
|
+_links |
|
28
|
24
|
|
|
24
|
|
239
|
}; |
|
|
24
|
|
|
|
|
75
|
|
|
29
|
|
|
|
|
|
|
|
|
30
|
0
|
|
|
0
|
0
|
0
|
sub is_view { 0 } |
|
31
|
7
|
|
33
|
7
|
0
|
40465
|
sub name { $_[0]->{+NAME} //= $_[0]->{+DB_NAME} } |
|
32
|
0
|
|
0
|
0
|
0
|
0
|
sub db_name { $_[0]->{+DB_NAME} //= $_[0]->{+NAME} } |
|
33
|
91
|
|
|
91
|
|
571
|
sub _links { delete $_[0]->{+_LINKS} } |
|
34
|
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
sub init { |
|
36
|
91
|
|
|
91
|
0
|
191
|
my $self = shift; |
|
37
|
|
|
|
|
|
|
|
|
38
|
91
|
|
66
|
|
|
521
|
$self->{+DB_NAME} //= $self->{+NAME}; |
|
39
|
91
|
|
33
|
|
|
335
|
$self->{+NAME} //= $self->{+DB_NAME}; |
|
40
|
91
|
50
|
|
|
|
283
|
croak "The 'name' attribute is required" unless $self->{+NAME}; |
|
41
|
|
|
|
|
|
|
|
|
42
|
91
|
100
|
|
|
|
354
|
my $debug = $self->{+CREATED} ? " (defined in $self->{+CREATED})" : ""; |
|
43
|
|
|
|
|
|
|
|
|
44
|
91
|
|
100
|
|
|
275
|
my $cols = $self->{+COLUMNS} //= {}; |
|
45
|
91
|
50
|
|
|
|
349
|
croak "The 'columns' attribute must be a hashref${debug}" unless ref($cols) eq 'HASH'; |
|
46
|
|
|
|
|
|
|
|
|
47
|
91
|
|
|
|
|
522
|
for my $cname (sort keys %$cols) { |
|
48
|
233
|
50
|
|
|
|
638
|
my $cval = $cols->{$cname} or croak "Column '$cname' is empty${debug}"; |
|
49
|
233
|
50
|
33
|
|
|
1500
|
croak "Columns '$cname' is not an instance of 'DBIx::QuickORM::Schema::Table::Column', got: '$cval'$debug" unless blessed($cval) && $cval->isa('DBIx::QuickORM::Schema::Table::Column'); |
|
50
|
|
|
|
|
|
|
} |
|
51
|
|
|
|
|
|
|
|
|
52
|
91
|
100
|
|
|
|
346
|
if (my $pk = $self->{+PRIMARY_KEY}) { |
|
53
|
59
|
|
|
|
|
156
|
for my $cname (@$pk) { |
|
54
|
64
|
50
|
|
|
|
237
|
my $col = $self->{+COLUMNS}->{$cname} or croak "Primary Key column '$cname' is not present in the column list"; |
|
55
|
64
|
50
|
|
|
|
388
|
croak "Primary key column '$cname' is set to be omitted, this is not allowed" if $col->omit; |
|
56
|
|
|
|
|
|
|
} |
|
57
|
|
|
|
|
|
|
} |
|
58
|
|
|
|
|
|
|
|
|
59
|
91
|
|
100
|
|
|
491
|
$self->{+UNIQUE} //= {}; |
|
60
|
91
|
|
100
|
|
|
647
|
$self->{+LINKS} //= []; |
|
61
|
91
|
|
100
|
|
|
435
|
$self->{+INDEXES} //= []; |
|
62
|
|
|
|
|
|
|
} |
|
63
|
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
sub merge { |
|
65
|
3
|
|
|
3
|
0
|
9
|
my $self = shift; |
|
66
|
3
|
|
|
|
|
18
|
my ($other, %params) = @_; |
|
67
|
|
|
|
|
|
|
|
|
68
|
3
|
50
|
33
|
|
|
102
|
$params{+COLUMNS} //= merge_hash_of_objs($self->{+COLUMNS}, $other->{+COLUMNS}) if $self->{+COLUMNS} || $other->{+COLUMNS}; |
|
|
|
|
33
|
|
|
|
|
|
69
|
3
|
50
|
33
|
|
|
42
|
$params{+UNIQUE} //= merge_hash_of_objs($self->{+UNIQUE}, $other->{+UNIQUE}) if $self->{+UNIQUE} || $other->{+UNIQUE}; |
|
|
|
|
33
|
|
|
|
|
|
70
|
3
|
50
|
50
|
|
|
28
|
$params{+LINKS} //= [@{$self->{+LINKS}}, @{$other->{+LINKS}}] if $self->{+LINKS} || $other->{+LINKS}; |
|
|
3
|
|
33
|
|
|
10
|
|
|
|
3
|
|
|
|
|
14
|
|
|
71
|
3
|
50
|
50
|
|
|
35
|
$params{+INDEXES} //= [@{$self->{+INDEXES}}, @{$other->{+INDEXES}}] if $self->{+INDEXES} || $other->{+INDEXES}; |
|
|
3
|
|
33
|
|
|
11
|
|
|
|
3
|
|
|
|
|
13
|
|
|
72
|
3
|
50
|
50
|
|
|
54
|
$params{+PRIMARY_KEY} //= [@{$self->{+PRIMARY_KEY}}] if $self->{+PRIMARY_KEY} || $other->{+PRIMARY_KEY}; |
|
|
3
|
|
33
|
|
|
21
|
|
|
73
|
|
|
|
|
|
|
|
|
74
|
3
|
|
|
|
|
32
|
return blessed($self)->new(%$self, %$other, %params); |
|
75
|
|
|
|
|
|
|
} |
|
76
|
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
sub clone { |
|
78
|
28
|
|
|
28
|
0
|
76
|
my $self = shift; |
|
79
|
28
|
|
|
|
|
72
|
my (%params) = @_; |
|
80
|
|
|
|
|
|
|
|
|
81
|
28
|
50
|
33
|
|
|
546
|
$params{+COLUMNS} //= clone_hash_of_objs($self->{+COLUMNS}) if $self->{+COLUMNS}; |
|
82
|
28
|
50
|
33
|
|
|
328
|
$params{+UNIQUE} //= clone_hash_of_objs($self->{+UNIQUE}) if $self->{+UNIQUE}; |
|
83
|
28
|
50
|
50
|
|
|
273
|
$params{+LINKS} //= [@{$self->{+LINKS}}] if $self->{+LINKS}; |
|
|
28
|
|
|
|
|
157
|
|
|
84
|
28
|
50
|
50
|
|
|
273
|
$params{+INDEXES} //= [@{$self->{+INDEXES}}] if $self->{+INDEXES}; |
|
|
28
|
|
|
|
|
7216
|
|
|
85
|
28
|
100
|
50
|
|
|
276
|
$params{+PRIMARY_KEY} //= [@{$self->{+PRIMARY_KEY}}] if $self->{+PRIMARY_KEY}; |
|
|
26
|
|
|
|
|
119
|
|
|
86
|
|
|
|
|
|
|
|
|
87
|
28
|
|
|
|
|
369
|
return blessed($self)->new(%$self, %params); |
|
88
|
|
|
|
|
|
|
} |
|
89
|
|
|
|
|
|
|
|
|
90
|
95
|
|
|
95
|
0
|
1045
|
sub columns { values %{$_[0]->{+COLUMNS}} } |
|
|
95
|
|
|
|
|
649
|
|
|
91
|
0
|
|
|
0
|
0
|
0
|
sub column_names { sort keys %{$_[0]->{+COLUMNS}} } |
|
|
0
|
|
|
|
|
0
|
|
|
92
|
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
sub column { |
|
94
|
1
|
|
|
1
|
0
|
2
|
my $self = shift; |
|
95
|
1
|
|
|
|
|
4
|
my ($cname) = @_; |
|
96
|
|
|
|
|
|
|
|
|
97
|
1
|
|
50
|
|
|
12
|
return $self->{+COLUMNS}->{$cname} // undef; |
|
98
|
|
|
|
|
|
|
} |
|
99
|
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
# QuerySource role implementation |
|
101
|
|
|
|
|
|
|
{ |
|
102
|
|
|
|
|
|
|
with 'DBIx::QuickORM::Role::Source'; |
|
103
|
|
|
|
|
|
|
|
|
104
|
24
|
|
|
|
|
160
|
use DBIx::QuickORM::Util::HashBase qw{ |
|
105
|
|
|
|
|
|
|
+fields_to_fetch |
|
106
|
|
|
|
|
|
|
+fields_to_omit |
|
107
|
|
|
|
|
|
|
+fields_list_all |
|
108
|
24
|
|
|
24
|
|
264
|
}; |
|
|
24
|
|
|
|
|
63
|
|
|
109
|
|
|
|
|
|
|
|
|
110
|
169
|
|
|
169
|
0
|
816
|
sub source_db_moniker { $_[0]->{+DB_NAME} } |
|
111
|
357
|
|
|
357
|
0
|
6289
|
sub source_orm_name { $_[0]->{+NAME} } |
|
112
|
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
# row_class # In HashBase at top of file |
|
114
|
|
|
|
|
|
|
# primary_key # In HashBase at top of file |
|
115
|
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
sub field_type { |
|
117
|
329
|
|
|
329
|
0
|
722
|
my $self = shift; |
|
118
|
329
|
|
|
|
|
793
|
my ($field) = @_; |
|
119
|
329
|
50
|
|
|
|
4185
|
my $col = $self->{+COLUMNS}->{$field} or croak "No column '$field' in table '$self->{+NAME}' ($self->{+DB_NAME})"; |
|
120
|
329
|
100
|
|
|
|
1614
|
my $type = $col->type or return undef; |
|
121
|
295
|
100
|
|
|
|
1631
|
return undef if ref($type); |
|
122
|
44
|
50
|
|
|
|
437
|
return $type if $type->DOES('DBIx::QuickORM::Role::Type'); |
|
123
|
0
|
|
|
|
|
0
|
return undef; |
|
124
|
|
|
|
|
|
|
} |
|
125
|
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
sub field_affinity { |
|
127
|
239
|
|
|
239
|
0
|
536
|
my $self = shift; |
|
128
|
239
|
|
|
|
|
694
|
my ($field, $dialect) = @_; |
|
129
|
239
|
50
|
|
|
|
1192
|
my $col = $self->{+COLUMNS}->{$field} or croak "No column '$field' in table '$self->{+NAME}' ($self->{+DB_NAME})"; |
|
130
|
239
|
|
|
|
|
2182
|
return $col->affinity($dialect); |
|
131
|
|
|
|
|
|
|
} |
|
132
|
|
|
|
|
|
|
|
|
133
|
193
|
100
|
|
193
|
0
|
2916
|
sub has_field { $_[0]->{+COLUMNS}->{$_[1]} ? 1 : 0 } |
|
134
|
|
|
|
|
|
|
|
|
135
|
90
|
|
100
|
90
|
0
|
569
|
sub fields_to_fetch { $_[0]->{+FIELDS_TO_FETCH} //= [ map { $_->name } grep { !$_->omit } values %{$_[0]->{+COLUMNS}} ] } |
|
|
67
|
|
|
|
|
236
|
|
|
|
69
|
|
|
|
|
302
|
|
|
|
25
|
|
|
|
|
154
|
|
|
136
|
0
|
|
0
|
0
|
0
|
|
sub fields_to_omit { $_[0]->{+FIELDS_TO_OMIT} //= [ map { $_->name } grep { $_->omit } values %{$_[0]->{+COLUMNS}} ] } |
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
137
|
0
|
|
0
|
0
|
0
|
|
sub fields_list_all { $_[0]->{+FIELDS_LIST_ALL} //= [ map { $_->name } values %{$_[0]->{+COLUMNS}} ] } |
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
} |
|
139
|
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
1; |