line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package # hide from PAUSE |
2
|
|
|
|
|
|
|
DBIx::Class::CDBICompat::TempColumns; |
3
|
|
|
|
|
|
|
|
4
|
2
|
|
|
2
|
|
974
|
use strict; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
48
|
|
5
|
2
|
|
|
2
|
|
8
|
use warnings; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
42
|
|
6
|
2
|
|
|
2
|
|
8
|
use base qw/Class::Data::Inheritable/; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
152
|
|
7
|
|
|
|
|
|
|
|
8
|
2
|
|
|
2
|
|
10
|
use Carp; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
1289
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
__PACKAGE__->mk_classdata('_temp_columns' => { }); |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub _add_column_group { |
13
|
0
|
|
|
0
|
|
|
my ($class, $group, @cols) = @_; |
14
|
|
|
|
|
|
|
|
15
|
0
|
0
|
|
|
|
|
return $class->next::method($group, @cols) unless $group eq 'TEMP'; |
16
|
|
|
|
|
|
|
|
17
|
0
|
|
|
|
|
|
my %new_cols = map { $_ => 1 } @cols; |
|
0
|
|
|
|
|
|
|
18
|
0
|
|
|
|
|
|
my %tmp_cols = %{$class->_temp_columns}; |
|
0
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
|
20
|
0
|
|
|
|
|
|
for my $existing_col ( grep $new_cols{$_}, $class->columns ) { |
21
|
|
|
|
|
|
|
# Already been declared TEMP |
22
|
0
|
0
|
|
|
|
|
next if $tmp_cols{$existing_col}; |
23
|
|
|
|
|
|
|
|
24
|
0
|
|
|
|
|
|
carp "Declaring column $existing_col as TEMP but it already exists"; |
25
|
|
|
|
|
|
|
} |
26
|
|
|
|
|
|
|
|
27
|
0
|
|
|
|
|
|
$class->_register_column_group($group => @cols); |
28
|
0
|
|
|
|
|
|
$class->mk_group_accessors('temp' => @cols); |
29
|
|
|
|
|
|
|
|
30
|
0
|
|
|
|
|
|
$class->_temp_columns({ %tmp_cols, %new_cols }); |
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
sub new { |
34
|
0
|
|
|
0
|
0
|
|
my ($class, $attrs, @rest) = @_; |
35
|
|
|
|
|
|
|
|
36
|
0
|
|
|
|
|
|
my $temp = $class->_extract_temp_data($attrs); |
37
|
|
|
|
|
|
|
|
38
|
0
|
|
|
|
|
|
my $new = $class->next::method($attrs, @rest); |
39
|
|
|
|
|
|
|
|
40
|
0
|
|
|
|
|
|
$new->set_temp($_, $temp->{$_}) for keys %$temp; |
41
|
|
|
|
|
|
|
|
42
|
0
|
|
|
|
|
|
return $new; |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
sub _extract_temp_data { |
46
|
0
|
|
|
0
|
|
|
my($self, $data) = @_; |
47
|
|
|
|
|
|
|
|
48
|
0
|
|
|
|
|
|
my %temp; |
49
|
0
|
|
|
|
|
|
foreach my $key (keys %$data) { |
50
|
0
|
0
|
|
|
|
|
$temp{$key} = delete $data->{$key} if $self->_temp_columns->{$key}; |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
|
53
|
0
|
|
|
|
|
|
return \%temp; |
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
sub find_column { |
57
|
0
|
|
|
0
|
0
|
|
my ($class, $col, @rest) = @_; |
58
|
0
|
0
|
|
|
|
|
return $col if $class->_temp_columns->{$col}; |
59
|
0
|
|
|
|
|
|
return $class->next::method($col, @rest); |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
sub set { |
63
|
0
|
|
|
0
|
0
|
|
my($self, %data) = @_; |
64
|
|
|
|
|
|
|
|
65
|
0
|
|
|
|
|
|
my $temp_data = $self->_extract_temp_data(\%data); |
66
|
|
|
|
|
|
|
|
67
|
0
|
|
|
|
|
|
$self->set_temp($_, $temp_data->{$_}) for keys %$temp_data; |
68
|
|
|
|
|
|
|
|
69
|
0
|
|
|
|
|
|
return $self->next::method(%data); |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
sub get_temp { |
73
|
0
|
|
|
0
|
0
|
|
my ($self, $column) = @_; |
74
|
0
|
0
|
|
|
|
|
$self->throw_exception( "Can't fetch data as class method" ) unless ref $self; |
75
|
0
|
0
|
|
|
|
|
$self->throw_exception( "No such TEMP column '${column}'" ) unless $self->_temp_columns->{$column} ; |
76
|
|
|
|
|
|
|
return $self->{_temp_column_data}{$column} |
77
|
0
|
0
|
|
|
|
|
if exists $self->{_temp_column_data}{$column}; |
78
|
0
|
|
|
|
|
|
return undef; |
79
|
|
|
|
|
|
|
} |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
sub set_temp { |
82
|
0
|
|
|
0
|
0
|
|
my ($self, $column, $value) = @_; |
83
|
|
|
|
|
|
|
$self->throw_exception( "No such TEMP column '${column}'" ) |
84
|
0
|
0
|
|
|
|
|
unless $self->_temp_columns->{$column}; |
85
|
0
|
0
|
|
|
|
|
$self->throw_exception( "set_temp called for ${column} without value" ) |
86
|
|
|
|
|
|
|
if @_ < 3; |
87
|
0
|
|
|
|
|
|
return $self->{_temp_column_data}{$column} = $value; |
88
|
|
|
|
|
|
|
} |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
sub has_real_column { |
91
|
0
|
0
|
|
0
|
0
|
|
return 1 if shift->has_column(shift); |
92
|
|
|
|
|
|
|
} |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
1; |