1 package DBIx::Class::CDBICompat::TempColumns;
5 use base qw/DBIx::Class/;
7 __PACKAGE__->mk_classdata('_temp_columns' => { });
9 sub _add_column_group {
10 my ($class, $group, @cols) = @_;
11 if ($group eq 'TEMP') {
12 $class->_register_column_group($group => @cols);
13 $class->mk_group_accessors('temp' => @cols);
14 my %tmp = %{$class->_temp_columns};
15 $tmp{$_} = 1 for @cols;
16 $class->_temp_columns(\%tmp);
18 return $class->next::method($group, @cols);
23 my ($class, $attrs, @rest) = @_;
25 foreach my $key (keys %$attrs) {
26 $temp{$key} = delete $attrs->{$key} if $class->_temp_columns->{$key};
28 my $new = $class->next::method($attrs, @rest);
29 foreach my $key (keys %temp) {
30 $new->set_temp($key, $temp{$key});
37 my ($class, $col, @rest) = @_;
38 return $col if $class->_temp_columns->{$col};
39 return $class->next::method($col, @rest);
43 my ($self, $column) = @_;
44 $self->throw( "Can't fetch data as class method" ) unless ref $self;
45 $self->throw( "No such TEMP column '${column}'" ) unless $self->_temp_columns->{$column} ;
46 return $self->{_temp_column_data}{$column}
47 if exists $self->{_temp_column_data}{$column};
52 my ($self, $column, $value) = @_;
53 $self->throw( "No such TEMP column '${column}'" )
54 unless $self->_temp_columns->{$column};
55 $self->throw( "set_temp called for ${column} without value" )
57 return $self->{_temp_column_data}{$column} = $value;
61 return 1 if shift->has_column(shift);