bin/mail_simplelist_purge.pl

filter: Statementstmt 100% 33 / 33 Branchbran 50.0% 4 / 8 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 6 / 6 Podpod n/a totaltotal 91.4% 43 / 47 CC 2 SCAR 2.5
CC
2
Cov
90%
list_aliases
2.0
BEGIN
1.0
BEGIN
1.0
CRAP 1.3
« blib/script/mail_tempaddress_purge.pl ↑ Summary bin/mail_tempaddress_purge.pl »
1 #!/usr/bin/perl -w
2 #
3  
4 =head1 NAME
5  
6 mail_tempaddress_purge.pl - purge Mail::SimpleList::Alias object when
7 they expire
8  
9 =head1 SYNOPSIS
10  
11 mail_tempaddress_purge.pl directory [min_age] [-v]
12  
13 =cut
14  
15 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
16  
17 # apply roles
18 1 ▶use Mail::SimpleList::Aliases;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 1 ▶use Mail::Action::Role::Purge;
Subroutine BEGIN: called CC=1 SCAR=0.0
20 use Class::Roles
21 1 ▶ apply => {
Subroutine BEGIN: called CC=1 SCAR=0.0
22 role => 'Purge',
23 to => 'Mail::SimpleList::Aliases'
24 1 };
25  
26 # parse command line
27 1 ▶use Getopt::Long;
Subroutine BEGIN: called CC=1 SCAR=0.0
28 1 my $verbose;
29 1 GetOptions( "verbose" => \$verbose );
30 1 my $dir = shift;
31 1 my $min_age = shift;
32 1 ▶die( "usage: $0 address_dir [min_age]\n" ) unless $dir;
Branch: 1 branch
BranchTrueFalseTotal
unless $dir 0 1 1
33  
34 # create a tempaddr object
35 1 my $aliases = Mail::SimpleList::Aliases->new( $dir );
36  
37 # report how many aliases exist
38 1 print "$dir contains ", $aliases->num_objects, " aliases\n";
39  
40 # if verbose, list the aliases
41 1 ▶list_aliases() if $verbose;
Branch: 1 branch
BranchTrueFalseTotal
if $verbose 1 0 1
42  
43 # run the purge routine
44 1 my $purged = 0;
45 1 $purged = $aliases->purge($min_age);
46  
47 # report how many aliases were purged;
48 1 my $justone = (1 == $purged);
49 1 ▶print $purged . ($justone ? " address was"
Branch: 1 branch
BranchTrueFalseTotal
$justone ? : 0 1 1
50 : " aliases were") . " purged\n";
51  
52 # if verbose, list the aliases
53 1 ▶list_aliases() if $verbose;
Branch: 1 branch
BranchTrueFalseTotal
if $verbose 1 0 1
54  
55 # all done!
56 1 exit(0);
57  
58 sub list_aliases
59 2 ▶{
Subroutine list_aliases: called CC=2 SCAR=6.9
60  
61 2 my $i = 0;
62 2 for( @{ $aliases->object_names } ) {
63 15 print $i++ . " $_\n";
64 }
65  
66 }
67  
68  
69 __END__
« blib/script/mail_tempaddress_purge.pl ↑ Summary bin/mail_tempaddress_purge.pl »