# FAT::Object
#  is the minimal interface to add, update or retrieve object
#  from/to the digital archive
#
# Copyright (C) 2003,2004,2005 Alexandre Dulaunoy <adulau@foo.be>
#
# This program is  free software; you can redistribute  it and/or modify
# it under the  terms of the GNU General Public  License as published by
# the Free Software Foundation; either  version 2 of the License, or (at
# your option) any later version.
#
# This program  is distributed in the  hope that it will  be useful, but
# WITHOUT   ANY  WARRANTY;   without  even   the  implied   warranty  of
# MERCHANTABILITY  or FITNESS  FOR A  PARTICULAR PURPOSE.   See  the GNU
# General Public License for more details.
#
# You  should have received  a copy  of the  GNU General  Public License
# along  with  this  program;  if   not,  write  to  the  Free  Software
# Foundation, Inc., 59 Temple Place  - Suite 330, Boston, MA 02111-1307,
# USA.
#
# $Id: Config.pm,v 1.2 2004/07/21 19:45:40 adulau Exp $


use lib "../.";

package FAT::Object;

use strict;
use File::HStore;
use FAT::Config;

use vars qw(%globalconfig);
*globalconfig = \%FAT::Config::globalconfig;

sub new {
    my $this = shift;
    my $id = shift;			### an ID is required for updating an object
    my $class = ref($this) || $this;
    my $self  = {};

    bless $self, $class;
    #if (defined($id)) { $self->{id} = $id; }

    return $self;
}

sub getID {
    my $self = shift;
    return $self->{'id'};
}


# Adding an object to the archive library
# 
# An object is always composed of one unique file.
#
#  Depending of the configuration, objects with the same hash :
#
#   * can be added (adding multiple possible similar files in the archive)
#   * or cannot be added
#
# The "uniqueonly" parameter permits to the control the behavior.  
#
# 
## Parameters ($filename of the file to be uploaded)

sub add {
    my $self = shift;
    my $filename = shift;

    my $store = File::HStore->new($globalconfig{global}{fat_rep},"FAT",$globalconfig{global}{archivename});

    my $id = $store->add($filename);

    return $id;
}


1;

