| 1 | package App::Validation::Automation::Purging; | ||||||||||||||||||||
| 2 | |||||||||||||||||||||
| 3 | 6 | ▶ | use Carp; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 4 | 6 | ▶ | use English qw(-no_match_vars); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 5 | 6 | ▶ | use Moose::Role; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 6 | |||||||||||||||||||||
| 7 | =head1 NAME | ||||||||||||||||||||
| 8 | |||||||||||||||||||||
| 9 | App::Validation::Automation::Purging - Role App::Validation::Automation | ||||||||||||||||||||
| 10 | |||||||||||||||||||||
| 11 | Delete old log files as per retention period | ||||||||||||||||||||
| 12 | |||||||||||||||||||||
| 13 | =head1 Attributes | ||||||||||||||||||||
| 14 | |||||||||||||||||||||
| 15 | =cut | ||||||||||||||||||||
| 16 | |||||||||||||||||||||
| 17 | 6 | requires qw( config ); | |||||||||||||||||||
| 18 | |||||||||||||||||||||
| 19 | 6 | has 'purge_msg' => ( | |||||||||||||||||||
| 20 | is => 'rw', | ||||||||||||||||||||
| 21 | isa => 'Str', | ||||||||||||||||||||
| 22 | clearer => 'clear_purge_msg', | ||||||||||||||||||||
| 23 | ); | ||||||||||||||||||||
| 24 | |||||||||||||||||||||
| 25 | =head1 METHODS | ||||||||||||||||||||
| 26 | |||||||||||||||||||||
| 27 | =head2 purge | ||||||||||||||||||||
| 28 | |||||||||||||||||||||
| 29 | Delete log files(log file extention can be changed from config) older than retention period | ||||||||||||||||||||
| 30 | |||||||||||||||||||||
| 31 | =cut | ||||||||||||||||||||
| 32 | |||||||||||||||||||||
| 33 | 0 | ▶ | sub purge { | ||||||||||||||||||
|
Subroutine
purge: not called CC=8 SCAR=42.8
Pod
documented
| |||||||||||||||||||||
| 34 | 0 | my $self = shift; | |||||||||||||||||||
| 35 | 0 | my ($msg, @log_files, @log_files_purge , $count, $log_dir, $log_extn, | |||||||||||||||||||
| 36 | $log_ret_period); | ||||||||||||||||||||
| 37 | 0 | ▶ | $log_dir = shift || $self->config->{'COMMON.LOG_DIR'}; | ||||||||||||||||||
|
Condition0%0/3
shift() || $self->config->{'COMMON.LOG_DIR'}
MC/DC0%0/2
shift() || $self->config->{'COMMON.LOG_DIR'}
shift()
$self->config->{'COMMON.LOG_DIR'}
Truth table0%0/3
A || B
A= shift()B= $self->config->{'COMMON.LOG_DIR'}
| |||||||||||||||||||||
| 38 | 0 | ▶ | $log_extn = shift || $self->config->{'COMMON.LOG_EXTN'}; | ||||||||||||||||||
|
Condition0%0/3
shift() || $self->config->{'COMMON.LOG_EXTN'}
MC/DC0%0/2
shift() || $self->config->{'COMMON.LOG_EXTN'}
shift()
$self->config->{'COMMON.LOG_EXTN'}
Truth table0%0/3
A || B
A= shift()B= $self->config->{'COMMON.LOG_EXTN'}
| |||||||||||||||||||||
| 39 | 0 | ▶ | $log_ret_period = shift || $self->config->{'COMMON.RET_PERIOD'}; | ||||||||||||||||||
|
Condition0%0/3
shift() || $self->config->{'COMMON.RET_PERIOD'}
MC/DC0%0/2
shift() || $self->config->{'COMMON.RET_PERIOD'}
shift()
$self->config->{'COMMON.RET_PERIOD'}
Truth table0%0/3
A || B
A= shift()B= $self->config->{'COMMON.RET_PERIOD'}
| |||||||||||||||||||||
| 40 | |||||||||||||||||||||
| 41 | 0 | ▶ | chdir $log_dir | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 42 | || confess "Couldn't Change to $log_dir to remove old logs : $OS_ERROR"; | ||||||||||||||||||||
| 43 | 0 | @log_files = <*.$log_extn>; | |||||||||||||||||||
| 44 | @log_files_purge | ||||||||||||||||||||
| 45 | = grep { | ||||||||||||||||||||
| 46 | 0 | (time - (stat($_))[9])/(24 * 3600) > $log_ret_period | |||||||||||||||||||
| 47 | } @log_files; | ||||||||||||||||||||
| 48 | |||||||||||||||||||||
| 49 | 0 | ▶ | if ( @log_files_purge ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 50 | 0 | $msg = "Log files in $log_dir older than $log_ret_period days:\n"; | |||||||||||||||||||
| 51 | 0 | $msg .= join "\n", @log_files_purge; | |||||||||||||||||||
| 52 | |||||||||||||||||||||
| 53 | 0 | ▶ | $count = unlink @log_files_purge | ||||||||||||||||||
|
Condition0%0/2
@log_files_purge || confess("Couldn't delete Log Files : $App::Validation::Automation::Purging::OS_ERROR")
MC/DC0%0/1
@log_files_purge || confess("Couldn't delete Log Files : $App::Validation::Automation::Purging::OS_ERROR")
@log_files_purge
Truth table0%0/2
A
A= @log_files_purge
| |||||||||||||||||||||
| 54 | || confess "Couldn't delete Log Files : $OS_ERROR"; | ||||||||||||||||||||
| 55 | 0 | ▶ | $self->purge_msg( $msg ) if($count); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 56 | 0 | return 1; | |||||||||||||||||||
| 57 | } | ||||||||||||||||||||
| 58 | |||||||||||||||||||||
| 59 | 0 | return 0; | |||||||||||||||||||
| 60 | |||||||||||||||||||||
| 61 | } | ||||||||||||||||||||
| 62 | |||||||||||||||||||||
| 63 | 6 | 1; | |||||||||||||||||||