| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package DBIx::Model::Table; |
|
2
|
1
|
|
|
1
|
|
7
|
use strict; |
|
|
1
|
|
|
|
|
3
|
|
|
|
1
|
|
|
|
|
96
|
|
|
3
|
1
|
|
|
1
|
|
7
|
use warnings; |
|
|
1
|
|
|
|
|
3
|
|
|
|
1
|
|
|
|
|
34
|
|
|
4
|
1
|
|
|
1
|
|
431
|
use DBIx::Model::Column; |
|
|
1
|
|
|
|
|
3
|
|
|
|
1
|
|
|
|
|
36
|
|
|
5
|
1
|
|
|
1
|
|
478
|
use DBIx::Model::FK; |
|
|
1
|
|
|
|
|
3
|
|
|
|
1
|
|
|
|
|
37
|
|
|
6
|
1
|
|
|
1
|
|
5
|
use Types::Standard qw/ArrayRef Int/; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
5
|
|
|
7
|
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
our $VERSION = '0.0.1_2'; |
|
9
|
|
|
|
|
|
|
our $INLINE = { |
|
10
|
|
|
|
|
|
|
_columns => { |
|
11
|
|
|
|
|
|
|
is => 'ro', |
|
12
|
|
|
|
|
|
|
isa => ArrayRef, |
|
13
|
|
|
|
|
|
|
default => sub { [] }, |
|
14
|
|
|
|
|
|
|
}, |
|
15
|
|
|
|
|
|
|
db => { |
|
16
|
|
|
|
|
|
|
is => 'ro', |
|
17
|
|
|
|
|
|
|
required => 1, |
|
18
|
|
|
|
|
|
|
weaken => 1, |
|
19
|
|
|
|
|
|
|
}, |
|
20
|
|
|
|
|
|
|
name => { |
|
21
|
|
|
|
|
|
|
is => 'ro', |
|
22
|
|
|
|
|
|
|
required => 1, |
|
23
|
|
|
|
|
|
|
}, |
|
24
|
|
|
|
|
|
|
name_lc => { |
|
25
|
|
|
|
|
|
|
is => 'ro', |
|
26
|
|
|
|
|
|
|
init_arg => undef, |
|
27
|
|
|
|
|
|
|
default => sub { lc $_[0]->name }, |
|
28
|
|
|
|
|
|
|
}, |
|
29
|
|
|
|
|
|
|
type => { |
|
30
|
|
|
|
|
|
|
is => 'ro', |
|
31
|
|
|
|
|
|
|
required => 1, |
|
32
|
|
|
|
|
|
|
}, |
|
33
|
|
|
|
|
|
|
ref_count => { |
|
34
|
|
|
|
|
|
|
is => 'rw', |
|
35
|
|
|
|
|
|
|
isa => Int, |
|
36
|
|
|
|
|
|
|
default => 0, |
|
37
|
|
|
|
|
|
|
}, |
|
38
|
|
|
|
|
|
|
target_count => { |
|
39
|
|
|
|
|
|
|
is => 'rw', |
|
40
|
|
|
|
|
|
|
isa => Int, |
|
41
|
|
|
|
|
|
|
default => 0, |
|
42
|
|
|
|
|
|
|
}, |
|
43
|
|
|
|
|
|
|
_foreign_keys => { |
|
44
|
|
|
|
|
|
|
is => 'ro', |
|
45
|
|
|
|
|
|
|
isa => ArrayRef, |
|
46
|
|
|
|
|
|
|
default => sub { [] }, |
|
47
|
|
|
|
|
|
|
}, |
|
48
|
|
|
|
|
|
|
}; |
|
49
|
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
sub add_column { |
|
51
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
|
52
|
0
|
|
|
|
|
|
my $col = DBIx::Model::Column->new( @_, table => $self ); |
|
53
|
0
|
|
|
|
|
|
push( @{ $self->_columns }, $col ); |
|
|
0
|
|
|
|
|
|
|
|
54
|
0
|
|
|
|
|
|
return $col; |
|
55
|
|
|
|
|
|
|
} |
|
56
|
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
sub add_foreign_key { |
|
58
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
|
59
|
0
|
|
|
|
|
|
my $fk = DBIx::Model::FK->new( @_, table => $self ); |
|
60
|
0
|
|
|
|
|
|
push( @{ $self->_foreign_keys }, $fk ); |
|
|
0
|
|
|
|
|
|
|
|
61
|
0
|
|
|
|
|
|
return $fk; |
|
62
|
|
|
|
|
|
|
} |
|
63
|
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
sub as_string { |
|
65
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
|
66
|
0
|
|
|
|
|
|
my $prefix = shift; |
|
67
|
0
|
|
|
|
|
|
my $str = $prefix . $self->name; |
|
68
|
|
|
|
|
|
|
|
|
69
|
0
|
|
|
|
|
|
foreach my $col ( $self->columns ) { |
|
70
|
0
|
|
|
|
|
|
$str .= "\n" . $col->as_string( $prefix . ' ' ); |
|
71
|
|
|
|
|
|
|
} |
|
72
|
|
|
|
|
|
|
|
|
73
|
0
|
0
|
|
|
|
|
if ( my @pri = $self->primaries ) { |
|
74
|
|
|
|
|
|
|
$str .= |
|
75
|
0
|
|
|
|
|
|
"\n${prefix} PRIMARY(" . join( ',', map { $_->name } @pri ) . ')'; |
|
|
0
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
} |
|
77
|
|
|
|
|
|
|
|
|
78
|
0
|
|
|
|
|
|
foreach my $fk ( $self->foreign_keys ) { |
|
79
|
0
|
|
|
|
|
|
$str .= "\n" . $fk->as_string( $prefix . ' ' ); |
|
80
|
|
|
|
|
|
|
} |
|
81
|
|
|
|
|
|
|
|
|
82
|
0
|
|
|
|
|
|
return $str; |
|
83
|
|
|
|
|
|
|
} |
|
84
|
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
sub bump_ref_count { |
|
86
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
|
87
|
0
|
|
|
|
|
|
$self->ref_count( $self->ref_count + 1 ); |
|
88
|
|
|
|
|
|
|
} |
|
89
|
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
sub bump_target_count { |
|
91
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
|
92
|
0
|
|
|
|
|
|
$self->target_count( $self->target_count + 1 ); |
|
93
|
|
|
|
|
|
|
} |
|
94
|
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
sub columns { |
|
96
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
|
97
|
0
|
0
|
|
|
|
|
return @{ $self->_columns } if wantarray; |
|
|
0
|
|
|
|
|
|
|
|
98
|
0
|
|
|
|
|
|
return $self->_columns; |
|
99
|
|
|
|
|
|
|
} |
|
100
|
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
sub primaries { |
|
102
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
|
103
|
0
|
|
|
|
|
|
return grep { $_->primary } $self->columns; |
|
|
0
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
} |
|
105
|
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
sub foreign_keys { |
|
107
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
|
108
|
0
|
0
|
|
|
|
|
return @{ $self->_foreign_keys } if wantarray; |
|
|
0
|
|
|
|
|
|
|
|
109
|
0
|
|
|
|
|
|
return $self->_foreign_keys; |
|
110
|
|
|
|
|
|
|
} |
|
111
|
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
### DO NOT EDIT BELOW! (generated by Class::Inline v0.0.1) |
|
113
|
|
|
|
|
|
|
#<<< |
|
114
|
0
|
|
|
0
|
0
|
|
require Carp;require Scalar::Util;our@ATTRS_UNEX=(undef);sub new {my$class= |
|
115
|
0
|
0
|
|
|
|
|
shift;my$self={@_ ? @_ > 1 ? @_ : %{$_[0]}: ()};map {local$Carp::CarpLevel= |
|
|
0
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
$Carp::CarpLevel + 1;Carp::croak( |
|
117
|
|
|
|
|
|
|
"missing attribute DBIx::Model::Table::$_ is required")unless exists$self->{ |
|
118
|
0
|
0
|
|
|
|
|
$_}}'db','name','type';map {delete$self->{$_}}'name_lc';if (@ATTRS_UNEX){map |
|
|
0
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
119
|
0
|
|
|
|
|
|
{local$Carp::CarpLevel=$Carp::CarpLevel + 1;Carp::carp( |
|
|
0
|
|
|
|
|
|
|
|
120
|
0
|
|
|
|
|
|
"DBIx::Model::Table attribute '$_' unexpected");delete$self->{$_ }}sort grep |
|
121
|
0
|
|
|
|
|
|
{not exists$INLINE->{$_ }}keys %$self}else {@ATTRS_UNEX=map {delete$self->{ |
|
|
0
|
|
|
|
|
|
|
|
122
|
0
|
|
0
|
|
|
|
$_ };$_}grep {not exists$INLINE->{$_ }}keys %$self}bless$self,ref$class || |
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
123
|
0
|
|
|
|
|
|
$class;map {$self->{$_ }=eval {$INLINE->{$_ }->{'isa'}->($self->{$_ })}; |
|
|
0
|
|
|
|
|
|
|
|
124
|
0
|
0
|
|
|
|
|
Carp::croak(qq{DBIx::Model::Table::$_ value invalid ($@)})if $@}grep {exists |
|
|
0
|
|
|
|
|
|
|
|
125
|
0
|
|
|
|
|
|
$self->{$_ }}'_columns','_foreign_keys','ref_count','target_count';map { |
|
126
|
0
|
|
0
|
|
|
|
Scalar::Util::weaken($self->{$_ })}grep {defined$self->{$_ }// undef}'db'; |
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
127
|
0
|
|
|
0
|
|
|
$self}sub __ro {my (undef,undef,undef,$sub)=caller(1);local$Carp::CarpLevel= |
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
128
|
0
|
|
0
|
|
|
|
$Carp::CarpLevel + 1;Carp::croak("attribute $sub is read-only (value: '" .( |
|
129
|
0
|
0
|
|
0
|
|
|
$_[1]// 'undef')."')")}sub _columns {$_[0]->__ro($_[1])if @_ > 1;$_[0]{ |
|
130
|
0
|
|
0
|
|
|
|
'_columns'}//= eval {$INLINE->{'_columns'}->{'isa'}->($INLINE->{'_columns'} |
|
131
|
0
|
0
|
|
|
|
|
->{'default'}->($_[0]))};Carp::croak( |
|
|
0
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
'invalid (DBIx::Model::Table::_columns) default value: ' .$@)if $@;$_[0]{ |
|
133
|
0
|
0
|
|
0
|
|
|
'_columns'}}sub _foreign_keys {$_[0]->__ro($_[1])if @_ > 1;$_[0]{ |
|
|
0
|
|
|
|
|
|
|
|
134
|
0
|
|
0
|
|
|
|
'_foreign_keys'}//= eval {$INLINE->{'_foreign_keys'}->{'isa'}->($INLINE->{ |
|
135
|
0
|
0
|
|
|
|
|
'_foreign_keys'}->{'default'}->($_[0]))};Carp::croak( |
|
|
0
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
'invalid (DBIx::Model::Table::_foreign_keys) default value: ' .$@)if $@;$_[0 |
|
137
|
0
|
0
|
|
0
|
0
|
|
]{'_foreign_keys'}}sub db {$_[0]->__ro($_[1])if @_ > 1;$_[0]{'db'}}sub name |
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
138
|
0
|
0
|
|
0
|
0
|
|
{$_[0]->__ro($_[1])if @_ > 1;$_[0]{'name'}}sub name_lc {$_[0]->__ro($_[1])if |
|
|
0
|
0
|
|
0
|
0
|
|
|
|
|
0
|
|
|
|
|
|
|
|
139
|
0
|
|
0
|
|
|
|
@_ > 1;$_[0]{'name_lc'}//= $INLINE->{'name_lc'}->{'default'}->($_[0])}sub |
|
140
|
0
|
0
|
|
0
|
0
|
|
ref_count {if (@_ > 1){$_[0]{'ref_count'}=eval {$INLINE->{'ref_count'}->{ |
|
|
0
|
|
|
|
|
|
|
|
141
|
0
|
0
|
|
|
|
|
'isa'}->($_[1])};Carp::croak( |
|
|
0
|
|
|
|
|
|
|
|
142
|
0
|
|
|
|
|
|
'invalid (DBIx::Model::Table::ref_count) value: '.$@)if $@;return $_[0]}$_[0 |
|
143
|
0
|
|
0
|
|
|
|
]{'ref_count'}//= eval {$INLINE->{'ref_count'}->{'isa'}->($INLINE->{ |
|
144
|
0
|
0
|
|
|
|
|
'ref_count'}->{'default'})};Carp::croak( |
|
|
0
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
'invalid (DBIx::Model::Table::ref_count) default value: ' .$@)if $@;$_[0]{ |
|
146
|
0
|
0
|
|
0
|
0
|
|
'ref_count'}}sub target_count {if (@_ > 1){$_[0]{'target_count'}=eval { |
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
147
|
0
|
0
|
|
|
|
|
$INLINE->{'target_count'}->{'isa'}->($_[1])};Carp::croak( |
|
|
0
|
|
|
|
|
|
|
|
148
|
0
|
|
|
|
|
|
'invalid (DBIx::Model::Table::target_count) value: '.$@)if $@;return $_[0]} |
|
149
|
0
|
|
0
|
|
|
|
$_[0]{'target_count'}//= eval {$INLINE->{'target_count'}->{'isa'}->($INLINE |
|
150
|
0
|
0
|
|
|
|
|
->{'target_count'}->{'default'})};Carp::croak( |
|
|
0
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
'invalid (DBIx::Model::Table::target_count) default value: ' .$@)if $@;$_[0] |
|
152
|
0
|
0
|
|
0
|
0
|
|
{'target_count'}}sub type {$_[0]->__ro($_[1])if @_ > 1;$_[0]{'type'}} |
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
#>>> |
|
154
|
|
|
|
|
|
|
### DO NOT EDIT ABOVE! (generated by Class::Inline v0.0.1) |
|
155
|
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
1; |