1 package # hide from PAUSE
2 DBIx::Class::CDBICompat::TempColumns;
6 use base qw/DBIx::Class/;
8 __PACKAGE__->mk_classdata('_temp_columns' => { });
10 sub _add_column_group {
11 my ($class, $group, @cols) = @_;
12 if ($group eq 'TEMP') {
13 $class->_register_column_group($group => @cols);
14 $class->mk_group_accessors('temp' => @cols);
15 my %tmp = %{$class->_temp_columns};
16 $tmp{$_} = 1 for @cols;
17 $class->_temp_columns(\%tmp);
19 return $class->next::method($group, @cols);
24 my ($class, $attrs, @rest) = @_;
26 foreach my $key (keys %$attrs) {
27 $temp{$key} = delete $attrs->{$key} if $class->_temp_columns->{$key};
29 my $new = $class->next::method($attrs, @rest);
30 foreach my $key (keys %temp) {
31 $new->set_temp($key, $temp{$key});
38 my ($class, $col, @rest) = @_;
39 return $col if $class->_temp_columns->{$col};
40 return $class->next::method($col, @rest);
44 my ($self, $column) = @_;
45 $self->throw_exception( "Can't fetch data as class method" ) unless ref $self;
46 $self->throw_exception( "No such TEMP column '${column}'" ) unless $self->_temp_columns->{$column} ;
47 return $self->{_temp_column_data}{$column}
48 if exists $self->{_temp_column_data}{$column};
53 my ($self, $column, $value) = @_;
54 $self->throw_exception( "No such TEMP column '${column}'" )
55 unless $self->_temp_columns->{$column};
56 $self->throw_exception( "set_temp called for ${column} without value" )
58 return $self->{_temp_column_data}{$column} = $value;
62 return 1 if shift->has_column(shift);