From 2f99841240904b6a487c9216b410e3e34e8506ac Mon Sep 17 00:00:00 2001
From: Daniel Friesel <derf@finalrewind.org>
Date: Tue, 17 May 2011 19:56:31 +0200
Subject: Improve $hashl->add_file

---
 lib/App/Hashl.pm | 35 +++++++++++++++++++++++++++++++++--
 1 file changed, 33 insertions(+), 2 deletions(-)

(limited to 'lib/App')

diff --git a/lib/App/Hashl.pm b/lib/App/Hashl.pm
index f99406f..3f9bfa7 100644
--- a/lib/App/Hashl.pm
+++ b/lib/App/Hashl.pm
@@ -10,6 +10,24 @@ use Storable qw(nstore retrieve);
 
 my $VERSION = '0.1';
 
+=head1 NAME
+
+App::Hashl - Partially hash files, check if files are equal etc.
+
+=head1 SYNOPSIS
+
+    use App::Hashl;
+
+    my $hashl = App::Hashl->new();
+    # or: App::Hashl->new_from_file($database_file);
+
+    for my $file (@files) {
+        $hashl->add_file($file, {
+            hash
+
+=cut
+
+
 sub new {
 	my ($obj, %conf) = @_;
 	my $ref = {
@@ -101,8 +119,21 @@ sub files {
 }
 
 sub add_file {
-	my ($self, $name, $data) = @_;
-	$self->{files}->{$name} = $data;
+	my ($self, %data) = @_;
+	my $file = $data{file};
+	my $path = $data{path};
+
+	if ($self->file($file) and
+			$self->file($file)->{mtime} == $data{mtime} and
+			$self->file($file)->{size} == $data{size} ) {
+		return;
+	}
+
+	$self->{files}->{$file} = {
+		hash  => $self->hash_file($file),
+		mtime => $data{mtime},
+		size  => $data{size},
+	};
 }
 
 sub ignored {
-- 
cgit v1.2.3