package LATMOS::Accounts::Bases::Sql::Templates;

use 5.010000;
use strict;
use warnings;

use base qw(LATMOS::Accounts::Bases::Sql::objects);
use LATMOS::Accounts::Log;
use LATMOS::Accounts::I18N;

our $VERSION = (q$Rev: 341 $ =~ /^Rev: (\d+) /)[0];

=head1 NAME

LATMOS::Ad - Perl extension for blah blah blah

=head1 SYNOPSIS

  use LATMOS::Accounts::Bases;
  my $base = LATMOS::Accounts::Bases->new('sql');
  ...

=head1 DESCRIPTION

Account base access over standard unix file format.

=head1 FUNCTIONS

=cut

sub _object_table { 'templates' }

sub _key_field { 'name' }

sub _has_extended_attributes { 0 }

sub _get_attr_schema {
    my ($class, $base) = @_;

    $class->SUPER::_get_attr_schema($base,
        {
            objectType => {
                iname => 'objecttype',
                inline => 1,
                ro => 1,
                can_values => sub {
                    $base->list_supported_objects;
                },
            },
            data => {
                inline => 1,
                multiple => 1,
                set => sub {
                    my ($self, $data) = @_;
                    my @datas = $data
                        ? (ref $data
                            ? @$data
                            : ($data))
                        : ();
                    my $sql = @datas
                        ? '{' . join(',', map { $_ =~ s/\\/\\\\/g; '"' .$_.'"' } @datas) . '}'
                        : undef;
                    $base->db->do(
                        q{UPDATE templates SET data = }
                        . $base->db->quote($sql) . q{ where name = } .
                        $base->db->quote($self->object->id)
                    );
                    return 1;
                },
            },
        }
    )
}

1;

__END__

=head1 SEE ALSO

L<LATMOS::Accounts::Bases::Sql::Aliases>, L<LATMOS::Accounts::Bases::Sql> 

=head1 AUTHOR

Olivier Thauvin, E<lt>olivier.thauvin@latmos.ipsl.frE<gt>

=head1 COPYRIGHT AND LICENSE

Copyright (C) 2008, 2009 CNRS SA/CETP/LATMOS

This library is free software; you can redistribute it and/or modify
it under the same terms as Perl itself, either Perl version 5.10.0 or,
at your option, any later version of Perl 5 you may have available.


=cut
