Browse Source

Refactor some common code into functions we will reuse all over the place

master
Jonathan "Duke" Leto 7 years ago
parent
commit
dbfbda14b3
  1. 39
      lib/Hush/List.pm

39
lib/Hush/List.pm

@ -118,24 +118,35 @@ sub global_status {
} }
} }
sub _hushlist_exists {
my ($name) = @_;
my $list_dir = catdir($HUSHLIST_CONFIG_DIR,$name);
return (-e $list_dir) ? 1 : 0;
}
sub exit_unless_hushlist_exists {
my ($name) = @_;
if (!_hushlist_exists($name)) {
print "Hushlist $name does not exist!\n";
exit(1);
};
}
# show details about a particular hushlist # show details about a particular hushlist
sub status { sub status {
my ($self,$name) = @_; my ($self,$name) = @_;
my $list_dir = catdir($HUSHLIST_CONFIG_DIR,$name); exit_unless_hushlist_exists($name);
if (!-e $list_dir) {
barf "Hushlist $name does not exist!"; my $list_specific_conf = catfile($HUSHLIST_CONFIG_DIR,$name,'list.conf');
} else { my %list_conf = read_file( $list_specific_conf ) =~ /^(\w+)=(.*)$/mg ;
my $list_specific_conf = catfile($HUSHLIST_CONFIG_DIR,$name,'list.conf'); my $member_list = catfile($HUSHLIST_CONFIG_DIR,$name,'members.txt');
my %list_conf = read_file( $list_specific_conf ) =~ /^(\w+)=(.*)$/mg ; my @members = read_file($member_list);
my $member_list = catfile($HUSHLIST_CONFIG_DIR,$name,'members.txt'); my @nicknames = map { m/^[^ ]+(.*)/ } @members;
my @members = read_file($member_list); my $num_members = @members;
my @nicknames = map { m/^[^ ]+(.*)/ } @members; print "Hushlist '$name' has $num_members members, generated at $list_conf{generated}\n";
my $num_members = @members; #map { print "\t - $_\n" } @nicknames;
print "Hushlist '$name' has $num_members members, generated at $list_conf{generated}\n"; map { print "\t - $_" } @members;
#map { print "\t - $_\n" } @nicknames;
map { print "\t - $_" } @members;
}
} }
sub new_list { sub new_list {

Loading…
Cancel
Save