aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authordakkar <dakkar@thenautilus.net>2016-12-28 17:46:34 +0000
committerdakkar <dakkar@thenautilus.net>2016-12-28 17:46:34 +0000
commit22480aff9a02cfba3e11694a1180ad18cf57ccf2 (patch)
tree3343a6f908824fa6da7ce4b3bb55407c3d879b8e /lib
parentmake example executable (diff)
downloadSietima-22480aff9a02cfba3e11694a1180ad18cf57ccf2.tar.gz
Sietima-22480aff9a02cfba3e11694a1180ad18cf57ccf2.tar.bz2
Sietima-22480aff9a02cfba3e11694a1180ad18cf57ccf2.zip
simpler command-line script
Diffstat (limited to 'lib')
-rw-r--r--lib/Sietima/CmdLine.pm25
-rw-r--r--lib/Sietima/Role/WithMailStore.pm3
-rw-r--r--lib/Sietima/Types.pm13
3 files changed, 37 insertions, 4 deletions
diff --git a/lib/Sietima/CmdLine.pm b/lib/Sietima/CmdLine.pm
index 57d796f..3d78be2 100644
--- a/lib/Sietima/CmdLine.pm
+++ b/lib/Sietima/CmdLine.pm
@@ -1,18 +1,41 @@
package Sietima::CmdLine;
use Moo;
use Sietima::Policy;
+use Sietima::Types qw(SietimaObj);
+use Types::Standard qw(HashRef);
+use Sietima;
use App::Spec;
use Sietima::Runner;
has sietima => (
is => 'ro',
required => 1,
+ isa => SietimaObj,
);
+has extra_spec => (
+ is => 'ro',
+ isa => HashRef,
+ default => sub { +{} },
+);
+
+sub BUILDARGS($class,@args) {
+ my $args = $class->next::method(@args);
+ $args->{sietima} //= do {
+ my $traits = delete $args->{traits} // [];
+ my $constructor_args = delete $args->{args} // {};
+ Sietima->with_traits($traits->@*)->new($constructor_args);
+ };
+ return $args;
+}
+
sub run($self) {
my $spec_data = $self->sietima->command_line_spec();
- my $app_spec = App::Spec->read($spec_data);
+ my $app_spec = App::Spec->read({
+ $spec_data->%*,
+ $self->extra_spec->%*,
+ });
my $runner = Sietima::Runner->new({
spec => $app_spec,
diff --git a/lib/Sietima/Role/WithMailStore.pm b/lib/Sietima/Role/WithMailStore.pm
index 9d3a8bd..58fa731 100644
--- a/lib/Sietima/Role/WithMailStore.pm
+++ b/lib/Sietima/Role/WithMailStore.pm
@@ -1,13 +1,14 @@
package Sietima::Role::WithMailStore;
use Moo::Role;
use Sietima::Policy;
-use Sietima::Types qw(MailStore);
+use Sietima::Types qw(MailStore MailStoreFromHashRef);
use namespace::clean;
has mail_store => (
is => 'ro',
isa => MailStore,
required => 1,
+ coerce => MailStoreFromHashRef,
);
1;
diff --git a/lib/Sietima/Types.pm b/lib/Sietima/Types.pm
index 27a3e17..3addf46 100644
--- a/lib/Sietima/Types.pm
+++ b/lib/Sietima/Types.pm
@@ -5,15 +5,24 @@ use Types::Standard qw(Str HashRef);
use namespace::clean;
use Type::Library
-base,
- -declare => qw(Address AddressFromStr
+ -declare => qw(SietimaObj
+ Address AddressFromStr
EmailMIME Message
Subscriber SubscriberFromAddress SubscriberFromStr SubscriberFromHashRef
- Transport MailStore);
+ Transport MailStore MailStoreFromHashRef);
+
+class_type SietimaObj, { class => 'Sietima' };
class_type EmailMIME, { class => 'Email::MIME' };
role_type Transport, { role => 'Email::Sender::Transport' };
role_type MailStore, { role => 'Sietima::MailStore' };
+declare_coercion MailStoreFromHashRef,
+ to_type MailStore, from HashRef,
+ q{ require Module::Runtime;
+ Module::Runtime::use_module(delete $_->{class})->new($_);
+ };
+
class_type Address, { class => 'Email::Address' };
declare_coercion AddressFromStr,
to_type Address, from Str,