line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
1
|
|
|
1
|
|
4
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
40
|
|
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
package LittleORM::Model::Field; |
4
|
1
|
|
|
1
|
|
8
|
use Moose; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
41
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
has 'model' => ( is => 'rw', |
7
|
|
|
|
|
|
|
isa => 'Str' ); |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
has 'table_alias' => ( is => 'rw', isa => 'Str' ); |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
has 'base_attr' => ( is => 'rw', |
12
|
|
|
|
|
|
|
isa => 'Str', |
13
|
|
|
|
|
|
|
default => '' ); |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
has 'base_field' => ( is => 'rw', |
16
|
|
|
|
|
|
|
isa => 'LittleORM::Model::Field' ); |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
has 'db_func' => ( is => 'rw', |
19
|
|
|
|
|
|
|
isa => 'Str' ); |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
has 'db_func_tpl' => ( is => 'rw', |
22
|
|
|
|
|
|
|
isa => 'Str', |
23
|
|
|
|
|
|
|
default => '%s(%s)' ); |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
has 'func_args_tpl' => ( is => 'rw', |
26
|
|
|
|
|
|
|
isa => 'Str', |
27
|
|
|
|
|
|
|
default => '%s' ); |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
has 'select_as' => ( is => 'rw', |
30
|
|
|
|
|
|
|
isa => 'Str', |
31
|
|
|
|
|
|
|
default => \&get_select_as_field_name ); |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
has 'post_process' => ( is => 'rw', |
34
|
|
|
|
|
|
|
isa => 'CodeRef', |
35
|
|
|
|
|
|
|
default => sub { sub { $_[ 0 ] } } ); |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
has 'db_field_type' => ( is => 'rw', |
38
|
|
|
|
|
|
|
isa => 'Str' ); |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
has '_distinct' => ( is => 'rw', |
41
|
|
|
|
|
|
|
isa => 'Bool', |
42
|
|
|
|
|
|
|
default => 0 ); |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
has 'orm_coerce' => ( is => 'rw', |
45
|
|
|
|
|
|
|
isa => 'Bool', |
46
|
|
|
|
|
|
|
default => 1 ); |
47
|
|
|
|
|
|
|
|
48
|
1
|
|
|
1
|
|
5428
|
use Carp::Assert 'assert'; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
10
|
|
49
|
1
|
|
|
1
|
|
121
|
use Scalar::Util 'blessed'; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
407
|
|
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
{ |
52
|
|
|
|
|
|
|
my $cnt = 0; |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
sub get_select_as_field_name |
55
|
|
|
|
|
|
|
{ |
56
|
0
|
|
|
0
|
0
|
|
$cnt ++; |
57
|
|
|
|
|
|
|
|
58
|
0
|
|
|
|
|
|
return '_f' . $cnt; # lowcase |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
sub determine_ta_for_field_from_another_model |
64
|
|
|
|
|
|
|
{ |
65
|
0
|
|
|
0
|
0
|
|
my ( $self, $tables ) = @_; |
66
|
|
|
|
|
|
|
|
67
|
0
|
|
|
|
|
|
my $rv = $self -> table_alias(); |
68
|
|
|
|
|
|
|
|
69
|
0
|
0
|
|
|
|
|
unless( $rv ) |
70
|
|
|
|
|
|
|
{ |
71
|
0
|
|
|
|
|
|
$rv = $self -> model() -> _db_table(); |
72
|
|
|
|
|
|
|
|
73
|
0
|
0
|
|
|
|
|
if( $tables ) |
74
|
|
|
|
|
|
|
{ |
75
|
0
|
|
|
|
|
|
eocEfjT38ttaOGys: |
76
|
0
|
|
|
|
|
|
foreach my $t ( @{ $tables } ) |
77
|
|
|
|
|
|
|
{ |
78
|
0
|
|
|
|
|
|
my ( $table, $alias ) = split( /\s+/, $t ); |
79
|
0
|
0
|
|
|
|
|
if( $table eq $rv ) |
80
|
|
|
|
|
|
|
{ |
81
|
0
|
|
|
|
|
|
$rv = $alias; |
82
|
0
|
|
|
|
|
|
last eocEfjT38ttaOGys; |
83
|
|
|
|
|
|
|
} |
84
|
|
|
|
|
|
|
} |
85
|
|
|
|
|
|
|
} |
86
|
|
|
|
|
|
|
} |
87
|
|
|
|
|
|
|
|
88
|
0
|
|
|
|
|
|
return $rv; |
89
|
|
|
|
|
|
|
} |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
sub this_is_field |
92
|
|
|
|
|
|
|
{ |
93
|
0
|
|
|
0
|
0
|
|
my ( $self, $attr ) = @_; |
94
|
|
|
|
|
|
|
|
95
|
0
|
|
|
|
|
|
my $rv = 0; |
96
|
|
|
|
|
|
|
|
97
|
0
|
0
|
0
|
|
|
|
if( blessed( $attr ) and ( $attr -> isa( 'LittleORM::Model::Field' ) ) ) |
98
|
|
|
|
|
|
|
{ |
99
|
0
|
|
|
|
|
|
$rv = 1; |
100
|
|
|
|
|
|
|
} |
101
|
0
|
|
|
|
|
|
return $rv; |
102
|
|
|
|
|
|
|
} |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
sub assert_model_soft |
105
|
|
|
|
|
|
|
{ |
106
|
0
|
|
|
0
|
0
|
|
my ( $self, $model ) = @_; |
107
|
0
|
0
|
|
|
|
|
if( $self -> model() ) |
108
|
|
|
|
|
|
|
{ |
109
|
0
|
|
|
|
|
|
$self -> assert_model( $model ); |
110
|
|
|
|
|
|
|
} |
111
|
|
|
|
|
|
|
} |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
sub assert_model |
114
|
|
|
|
|
|
|
{ |
115
|
0
|
|
|
0
|
0
|
|
my ( $self, $model ) = @_; |
116
|
|
|
|
|
|
|
|
117
|
0
|
|
0
|
|
|
|
my $t = ( ref( $model ) or $model ); |
118
|
0
|
|
|
|
|
|
assert( $self -> model() eq $t ); |
119
|
|
|
|
|
|
|
} |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
sub form_field_name_for_db_select |
122
|
|
|
|
|
|
|
{ |
123
|
0
|
|
|
0
|
0
|
|
my ( $self, $table ) = @_; |
124
|
|
|
|
|
|
|
|
125
|
0
|
|
|
|
|
|
my $rv = $self -> base_attr(); |
126
|
|
|
|
|
|
|
|
127
|
0
|
0
|
|
|
|
|
if( $rv ) |
|
|
0
|
|
|
|
|
|
128
|
|
|
|
|
|
|
{ |
129
|
0
|
|
|
|
|
|
assert( $self -> model() ); |
130
|
0
|
0
|
|
|
|
|
$rv = ( $table ? $table . '.' : '' ) . |
131
|
|
|
|
|
|
|
&LittleORM::Model::__get_db_field_name( $self -> model() -> meta() -> find_attribute_by_name( $rv ) ); |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
} elsif( my $f = $self -> base_field() ) |
134
|
|
|
|
|
|
|
{ |
135
|
0
|
|
|
|
|
|
$rv = $f -> form_field_name_for_db_select(); |
136
|
|
|
|
|
|
|
} |
137
|
|
|
|
|
|
|
|
138
|
0
|
0
|
|
|
|
|
if( my $f = $self -> db_func() ) |
139
|
|
|
|
|
|
|
{ |
140
|
0
|
0
|
|
|
|
|
$rv = sprintf( $self -> db_func_tpl(), |
141
|
|
|
|
|
|
|
$f, |
142
|
|
|
|
|
|
|
sprintf( $self -> func_args_tpl(), |
143
|
|
|
|
|
|
|
( $self -> _distinct() ? ' DISTINCT ' : '' ) . $rv ) ); |
144
|
|
|
|
|
|
|
} |
145
|
|
|
|
|
|
|
|
146
|
0
|
|
|
|
|
|
return $rv; |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
} |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
sub form_field_name_for_db_select_with_as |
151
|
|
|
|
|
|
|
{ |
152
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
153
|
|
|
|
|
|
|
|
154
|
0
|
|
|
|
|
|
my $rv = $self -> form_field_name_for_db_select( @_ ) . ' AS ' . $self -> select_as(); |
155
|
|
|
|
|
|
|
|
156
|
0
|
|
|
|
|
|
return $rv; |
157
|
|
|
|
|
|
|
} |
158
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
394041; |