DBIx-Class-VirtualColumns

 view release on metacpan or  search on metacpan

lib/DBIx/Class/VirtualColumns.pm  view on Meta::CPAN

sub store_column {
    my ($self, $column, $value) = @_;

    # Check if a localized colum has been requested
    if (defined $self->_virtual_columns
        && exists $self->_virtual_columns->{$column}) {
        return $self->{_virtual_values}{$column} = $value;
    }

    return $self->next::method($column, $value);
}

=head2 set_column

Overloaded method. L<DBIx::Class::Row/"set_column">

=cut

sub set_column {
    my ($self, $column, $value) = @_;

    if (defined $self->_virtual_columns
        && exists $self->_virtual_columns->{$column}) {
        return $self->{_virtual_values}{$column} = $value;
    }
    return $self->next::method($column, $value);
}

=head2 column_info

Overloaded method. L<DBIx::Class::ResultSource/"column_info">

Additionally returns the HASH key 'virtual' which indicates if the requested
column is virtual or not.

=cut

sub column_info {
    my ($self, $column) = @_;

    # Fetch localized column info
    if (defined $self->_virtual_columns
        && exists $self->_virtual_columns->{$column}) {
        my $column_info = $self->_virtual_columns->{$column};
        $column_info->{virtual} = 1;
        return $column_info;
    }
    
    my $column_info = $self->next::method($column);
    $column_info->{virtual} = 0;
    return $column_info;
}


=head2 update

Overloaded method. L<DBIx::Class::Row/"update">

=cut

sub update {
    my $self = shift;
    my $attr = shift;
 
    # Filter localized values
    my ($virtual_attrs,$main_attrs) = $self->_virtual_filter($attr);
    
    # Do regular update
    $self->next::method($main_attrs);
    
    if (scalar %{$virtual_attrs}) {
        while ( my($column,$value) = each %$virtual_attrs ) {
            $self->{_virtual_values}{$column} = $value;
        }
    }
    return $self;
}

=head1 CAVEATS

The best way to add non-column data to DBIC objects is to use 
L<Class::Accessor::Grouped>. 

 __PACKAGE__->mk_group_accessors(simple => qw(foo bar baz));

Use L<DBIx::Class::VirtualColumns> only if you rely on L<DBIx::Class::Row> 
methods like C<set_column>, C<get_column>, ... 

=head1 SUPPORT

This module was just a proof of concept, and is not actively developed 
anymore. Patches are still welcome though.

Please report any bugs to 
C<bug-dbix-class-virtualcolumns@rt.cpan.org>, or through the web interface at
L<http://rt.cpan.org/Public/Bug/Report.html?Queue=DBIx::Class::VirtualColumns>.
I will be notified, and then you'll automatically be notified of progress on 
your report as I make changes.

=head1 AUTHOR

    Maroš Kollár
    CPAN ID: MAROS
    maros [at] k-1.com
    L<http://www.revdev.at>

=head1 ACKNOWLEDGEMENTS 

This module was written for Revdev L<http://www.revdev.at>, a nice litte
software company I run with Koki and Domm (L<http://search.cpan.org/~domm/>).

=head1 COPYRIGHT

DBIx::Class::VirtualColumns is Copyright (c) 2008 Maroš Kollár 
- L<http://www.revdev.at>

This program is free software; you can redistribute it and/or modify it under 
the same terms as Perl itself.

The full text of the license can be found in the
LICENSE file included with this module.



( run in 3.231 seconds using v1.01-cache-2.11-cpan-63c85eba8c4 )