#!/usr/bin/perl

###########################
### Autor: Sebastian Enger / B.Sc. 
### Copyright: Sebastian Enger
### Licence: Commercial
### Version: 1.1.1  - 2013-09-18
### Contact: sebastian.enger@gmail.com
###########################

package Crawler::MemStore;
### http://perldoc.perl.org/Storable.html

use strict;
use Storable;
use File::Path;
use DB_File;
use Fcntl;

# Konstruktor
sub new {

	my ($cfgFile) = @_;
	if ($cfgFile !~ /\w{3,}/ig){
		$cfgFile = "/home/thecerial/trendcrawler/trendcrawler.db";
	}

	my ($DB,%DB);
	tie (%DB, DB_File, $cfgFile, O_RDWR|O_CREAT, 0644, $DB_HASH);
	
#	my %Store = ();
#	store \%Store, $cfgFile;
#	my $hashref = retrieve($cfgFile);
	
	my $self = {
	#	'store' => $hashref,
		'db_flat' => $DB,
	};
	bless $self, $class;
	make_path '/home/thecerial/trendcrawler/', {owner=>'thecerial', group=>'users'};

	return $self;
}

sub empty(){

	my $self = shift;
	
	delete $self->{db_flat}{googlelinks};
	delete $self->{db_flat}{binglinks};
	delete $self->{db_flat}{content};
	delete $self->{db_flat}{rawcloud};
	delete $self->{db_flat}{source};
	delete $self->{db_flat}->{twitterlinks};

	return 1;
}


sub close(){
	
	my $self = shift;
	untie $self->{db_flat};
	
	return 1;
}