$drive = Coles_Backup_Drive->new( \$disk, SPACE_THRESHOLD ); #### package Backup_Drive; use strict; use constant LAST_MODIFIED => 0; use constant FILE_SIZE => 1; use constant TRANSACTION_LOG => 'trn'; use constant FULL_BACKUP => 'bak'; # make database backups private my %_last_full_backups = (); my @_full_backup_files = []; my %_trn_backups =(); my $_space_threshold; sub new{ my ( $class, @arg ) = @_; my $self = bless $arg[0], $class; $_space_threshold = $arg[1]; return $self; } sub add_file{ ### THIS IS THE PROBLEM WHEN PASSING DETAIL FROM THIS METHOD TO add_full_backup ### # add the file to the relevant file type data my( $self, $database_name, $file ) = @_; if( lc( $file->Extension ) eq FULL_BACKUP ){ add_full_backup( $self, $database_name, $file ); } else { add_trn_log( $self, $database_name, $file ); } print "wait\n"; } sub add_full_backup{ my( $self, $database_name, $file ) = @_; # capture the last backup details if( exists $_last_full_backups{ $database_name } ){ # record the file size only if the database backup is more recent the the one recorded if( $_last_full_backups{ $database_name }->[ LAST_MODIFIED ] < $file->LastModified ){ # one file I found returned an undefined value for its size. So I defaulted the size to zero. $_last_full_backups{ $database_name } = [ $file->LastModified, defined $file->FileSize ? $file->FileSize : 0 ]; } } else { # add new details $_last_full_backups{ $database_name } = [ $file->LastModified, defined $file->FileSize ? $file->FileSize : 0 ]; } # add file to file list push ( @_full_backup_files, $file ); print "test\n"; } sub add_trn_log{ my( $self, $database_name, $file ) = @_; if( exists $_trn_backups{ $database_name } ){ $_trn_backups{ $database_name } = [ \$file ]; } else { push( @{ $_trn_backups{ $database_name } }, \$file ); } } sub get_last_backup_modified{ # return the last modified date for the passed in database my( $self, $database_name ) = @_; $_last_full_backups{ $database_name }->[ LAST_MODIFIED ]; } sub get_last_backup_file_size{ # return the last modified date for the passed in database my( $self, $database_name ) = @_; $_last_full_backups{ $database_name }->[ FILE_SIZE ]; } sub need_drive_space{ # return whether the drive needs space to keep it above the space warning threshold. my $self = shift; if( _database_space_required() > $$self->FreeSpace ){ return 1; } return 0; } sub _database_space_required{ my $self = shift; my $total = 0; my $key; for $key ( keys %_last_full_backups ){ $total += get_last_backup_file_size( $key ); } $total += $_space_threshold; # keep above threshold warning size return $total; } #__END__ 1;