From 98b6d1ba27fa2a2e1434e1fecd3479a2b4903fe7 Mon Sep 17 00:00:00 2001 From: dakkar Date: Thu, 16 Mar 2017 17:45:56 +0000 Subject: Dzil-build release 1.0.0 (from 9f1fc6d on master) --- lib/Sietima/CmdLine.pm | 156 ++++++++++++++++++++++++++++--------------------- 1 file changed, 91 insertions(+), 65 deletions(-) (limited to 'lib/Sietima/CmdLine.pm') diff --git a/lib/Sietima/CmdLine.pm b/lib/Sietima/CmdLine.pm index 6c24834..e014d48 100644 --- a/lib/Sietima/CmdLine.pm +++ b/lib/Sietima/CmdLine.pm @@ -8,9 +8,79 @@ use App::Spec; use Sietima::Runner; use namespace::clean; -# VERSION +our $VERSION = '1.0.0'; # VERSION # ABSTRACT: run Sietima as a command-line application + +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; +} + + +has app_spec => ( + is => 'lazy', + init_arg => undef, +); + +sub _build_app_spec($self) { + my $spec_data = $self->sietima->command_line_spec(); + + return App::Spec->read({ + $spec_data->%*, + $self->extra_spec->%*, + }); +} + + +has runner => ( + is => 'lazy', + init_arg => undef, + handles => [qw(run)], +); + +sub _build_runner($self) { + return Sietima::Runner->new({ + spec => $self->app_spec, + cmd => $self->sietima, + }); +} + +1; + +__END__ + +=pod + +=encoding UTF-8 + +=head1 NAME + +Sietima::CmdLine - run Sietima as a command-line application + +=head1 VERSION + +version 1.0.0 + =head1 SYNOPSIS use Sietima::CmdLine; @@ -28,35 +98,23 @@ use namespace::clean; This class simplifies the creation of a L<< C >> object, and uses L<< C >> to provide a command-line interface to it. -=attr C +=head1 ATTRIBUTES + +=head2 C Required, an instance of L<< C >>. You can either construct it yourself, or use the L. -=cut - -has sietima => ( - is => 'ro', - required => 1, - isa => SietimaObj, -); - -=attr C +=head2 C Optional hashref. Used inside L<< /C >>. If you're not familiar with L<< C >>, you probably don't want to touch this. -=cut - -has extra_spec => ( - is => 'ro', - isa => HashRef, - default => sub { +{} }, -); +=head1 METHODS -=method C +=head2 C my $cmdline = Sietima::CmdLine->new({ sietima => Sietima->with_traits(qw(SubjectTag))->new({ @@ -78,21 +136,7 @@ The constructor. In alternative to passing a L<< C >> instance, you can pass C and C, and the instance will be built for you. The two calls above are equivalent. -=for Pod::Coverage BUILDARGS - -=cut - -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; -} - -=method C +=head2 C Returns an instance of L<< C >>, built from the specification returned by calling L<< @@ -101,47 +145,29 @@ C|Sietima/command_line_spec >> on the L<< method, and the C attribute, are probably only interesting to people who are doing weird extensions. -=cut - -has app_spec => ( - is => 'lazy', - init_arg => undef, -); - -sub _build_app_spec($self) { - my $spec_data = $self->sietima->command_line_spec(); - - return App::Spec->read({ - $spec_data->%*, - $self->extra_spec->%*, - }); -} - -=method C +=head2 C Returns an instance of L<< C >>, built from the L<< /C >>. -=method C +=head2 C Delegates to the L<< /C >>'s L<< C|App::Spec::Run/run >> method. Parser the command line arguments from C<@ARGV> and executes the appropriate action. -=cut +=for Pod::Coverage BUILDARGS -has runner => ( - is => 'lazy', - init_arg => undef, - handles => [qw(run)], -); +=head1 AUTHOR -sub _build_runner($self) { - return Sietima::Runner->new({ - spec => $self->app_spec, - cmd => $self->sietima, - }); -} +Gianni Ceccarelli -1; +=head1 COPYRIGHT AND LICENSE + +This software is copyright (c) 2017 by Gianni Ceccarelli . + +This is free software; you can redistribute it and/or modify it under +the same terms as the Perl 5 programming language system itself. + +=cut -- cgit v1.2.3