package PhotoPub::Ages;
require Exporter;
@ISA = qw(Exporter);
@EXPORT_OK = qw(&initage &updateage &updateagefromfiles &getage);

use PhotoPub::Global qw(&register_init $error);
use PhotoPub::FileInfo qw(&mtime);
use Carp;

my @ages;

&register_init('startup',sub {
		 @ages=();
	       });

sub initage {
  unshift(@ages,0);
}

sub updateage {
  my ($newage)=@_;
  if (!defined $newage) { 
    carp("Undefined newage"); 
    return; 
  }
  if (!defined $ages[0]) { 
# album deliberately does this for now
#    carp("tried to update age while none was being tracked");
    return;
  }
  $ages[0]=$newage if $newage>$ages[0];
}

sub updateagefromfiles {
  foreach (@_) {
    &updateage(&mtime($_));
  }
}

sub getage {
  return (shift @ages);
}

1;
