--- /dev/null
+package App::Promulger::Command::newlist;
+use strict;
+use warnings;
+
+use App::Promulger -command;
+use Promulger::Schema;
+use Promulger::List;
+
+use Config::General;
+
+sub abstract {
+ return "creates a new list";
+}
+
+sub opt_spec {
+ return (
+ [ "config|c=s", "configuration file", { required => 1 } ],
+ );
+}
+
+sub validate_args {
+ my ($self, $opt, $args) = @_;
+ my $cf = $opt->{config};
+
+ unless(-e $cf) {
+ die "Config file $cf doesn't exist\n";
+ }
+ unless(-f $cf) {
+ die "Config file $cf not a file\n";
+ }
+ unless(-r $cf) {
+ die "Config file $cf not readable\n";
+ }
+
+ $self->{config} = { Config::General->new($cf)->getall };
+ @$args == 1 or die "pmg newlist needs a list name\n";
+}
+
+sub run {
+ my ($self, $opt, $args) = @_;
+ Promulger::Schema->connect($self->{config}{store});
+ my $list = Promulger::List->new(
+ listname => $args->[0],
+ );
+ $list->setup_aliases_at($self->{config});
+ Promulger::Schema->store($list);
+}
+
+1;
--- /dev/null
+package Promulger::List;
+use Moose;
+
+use Carp;
+use Dir::Self;
+use File::Slurp qw/read_file write_file/;
+
+has listname => (
+ is => 'ro',
+ isa => 'Str',
+ required => 1,
+);
+
+has active => (
+ is => 'rw',
+ isa => 'Bool',
+ required => 1,
+ default => 1,
+);
+
+sub setup_aliases_at {
+ my($self, $config) = @_;
+ my $name = $self->listname;
+ my @current_contents = read_file $config->{aliases};
+ my @aliases = ($name, "${name}-request");
+ for my $alias (@aliases) {
+ if(grep { $_ =~ /^${alias}:/ } @current_contents) {
+ croak "${alias} already in $config->{aliases}";
+ }
+ push @current_contents, qq(${alias}: "|$config->{bin_root}/pmg msg"\n);
+ }
+ write_file $config->{aliases}, @current_contents;
+}
+
+1;
--- /dev/null
+package Promulger::Schema;
+use strict;
+use warnings;
+
+use KiokuDB;
+
+my $kdb;
+my $scope;
+
+sub connect {
+ my($self, $dsn) = @_;
+ $kdb = KiokuDB->connect(
+ $dsn,
+ create => 1,
+ );
+ $scope = $kdb->new_scope;
+}
+
+sub store {
+ my($self, $obj) = @_;
+ $kdb->store($obj);
+}
+
+1;