The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

DBIx::Class::Result::ProxyField - Component Result::ProxyField is a component for DBIx::Class object which permit to defined public name for each column object

VERSION

Version 0.03

SYNOPSIS

First, this module would evolve, it is not completly finished

To use Result::ProxyField component, you need to declare it in Result and ResultSet of your DBIx::Class object

in your Result :

    package App::Schema::Result::Object;

    # declare columns : for each column you want use an other name, declare public_name

    __PACKAGE__->add_columns(
      "superobjectid",
      { data_type => "integer", is_nullable => 1, public_name => 'super_object_id' },
      "actif",
      { data_type => "tinyint", default_value => 1, is_nullable => 1 },
      "creation_datetime",
      { data_type => "datetime", is_nullable => 1, public_name => 'created_at'}
    );

    # after declare columns you can initialise the Result::ProxyField component

    __PACKAGE__->load_component(qw/Result::ProxyField/);
    __PACKAGE__->init_proxy_field();

in your ResultSet

    package App::Schema::ResultSet::Object;
    use base 'DBIx::Class::ResultSet::ProxyField';

On your code, you can use public_name to set or get column

    my $schema = App::Schema->connect('dbi:SQLite:db/example.db');

    my @objects = $schema->resultset('Object')->search({created_at => {"==", undef},super_object_id => 1});
    # is the same than
    my @objects = $schema->resultset('Object')->search({creation_datetime => {"==", undef}, superobjectid => 1});

    my $object = $objects[0];

    $object->created_at(DateTime.now());
    #is the same than
    $object->creation_datetime(DateTime.now());

    my $created_at = $object->created_at;
    #is the same than
    my $created_at = $object->creation_datetime;

    ...etc

becareful, the relationship id stay superobjectid

CLASS VARIABLES

$rh_ext_to_bdd store mapping table from public to database by class

$rh_bdd_to_ext store mapping table from database to public by class

SUBROUTINES/METHODS

rh_ext_to_bdd

Class function

Accessor to mapping table from public to database for a class

rh_bdd_to_ext

Class function

Accessor to mapping table from database to public for a class

init_proxy_field

Class function

Init function which defined accessor from class definition

adaptator_to_ext

Instance function

set public accessor from database accessor

sub adaptator_to_ext { my $self = shift; my $class = ref $self; foreach my $key_bdd (keys %{$rh_bdd_to_ext->{$class}}) { my $key_ext = $rh_bdd_to_ext->{$class}->{$key_bdd}; $self->$key_ext( $self->$key_bdd ); } }

adaptator_to_bdd

Instance function

set database accessor from public accessor

sub adaptator_to_bdd { my $self = shift; my $class = ref $self; foreach my $key_ext (keys %{$rh_ext_to_bdd->{$class}}) { # $key = champ bdd my $key_bdd = $rh_ext_to_bdd->{$class}->{$key_ext}; $self->$key_bdd( $self->$key_ext ) if defined $self->$key_ext; } }

class_adaptator_to_bdd

Class function

format hash columns data of object with public accessor

columns_data

Instance function

re defined columns_data function to component Result::DataColumns

return only column data Hash with public name

update

Instance function

re defined update to adapt object field before update

insert

Instance function

re defined insert to adapt object field before insert

delete

Instance function

re defined delete to adapt object field before delete

AUTHOR

Nicolas Oudard, nicolas@oudard.org

BUGS

Please report any bugs or feature requests to bug-dbix-class-result-proxyfield at rt.cpan.org, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=DBIx-Class-Result-ProxyField. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.

SUPPORT

You can find documentation for this module with the perldoc command.

    perldoc DBIx::Class::Result::ProxyField

ACKNOWLEDGEMENTS

LICENSE AND COPYRIGHT

Copyright 2010 Nicolas Oudard.

This program is free software; you can redistribute it and/or modify it under the terms of either: the GNU General Public License as published by the Free Software Foundation; or the Artistic License.

See http://dev.perl.org/licenses/ for more information.