Beam-Runner
view release on metacpan or search on metacpan
lib/Beam/Runner.pm view on Meta::CPAN
package Beam::Runner;
our $VERSION = '0.016';
# ABSTRACT: Configure, list, document, and execute runnable task objects
#pod =head1 SYNOPSIS
#pod
#pod beam run <container> <task> [<args...>]
#pod beam list
#pod beam list <container>
#pod beam help <container> <task>
#pod beam help
#pod
#pod =head1 DESCRIPTION
#pod
#pod This distribution is an execution and organization system for runnable
#pod objects (tasks). This allows you to prepare a list of runnable tasks in
#pod configuration files and then execute them. This also allows easy
#pod discovery of configuration files and objects, and allows you to document
#pod your objects for your users.
#pod
#pod =head2 Tasks
#pod
#pod A task is an object that consumes the L<Beam::Runnable> role. This role
#pod requires only a C<run()> method be implemented in the class. This
#pod C<run()> method should accept all the arguments given on the command
#pod line. It can parse GNU-style options out of this array using
#pod L<Getopt::Long/GetOptionsFromArray>.
#pod
#pod Task modules can compose additional roles to easily add more features,
#pod like adding a timeout with L<Beam::Runnable::Timeout::Alarm>.
#pod
#pod Task modules are expected to have documentation that will be displayed
#pod by the C<beam list> and C<beam help> commands. The C<beam list> command
#pod will display the C<NAME> section of the documentation, and the C<beam
#pod help> command will display the C<NAME>, C<SYNOPSIS>, C<DESCRIPTION>,
#pod C<ARGUMENTS>, C<OPTIONS>, C<ENVIRONMENT>, and C<SEE ALSO> sections of
#pod the documentation.
#pod
#pod =head2 Configuration Files
#pod
#pod The configuration file is a L<Beam::Wire> container file that describes
#pod objects. Some of these objects are marked as executable tasks by
#pod consuming the L<Beam::Runnable> role.
#pod
#pod The container file can have a special entry called C<$summary> which
#pod has a short summary that will be displayed when using the C<beam list>
#pod command.
#pod
#pod Here's an example container file that has a summary, configures
#pod a L<DBIx::Class> schema (using the schema class for CPAN Testers:
#pod L<CPAN::Testers::Schema>), and configures a runnable task called
#pod C<to_metabase> located in the class
#pod C<CPAN::Testers::Backend::Migrate::ToMetabase>:
#pod
#pod # migrate.yml
#pod $summary: Migrate data between databases
#pod
#pod _schema:
#pod $class: CPAN::Testers::Schema
#pod $method: connect_from_config
#pod
#pod to_metabase:
#pod $class: CPAN::Testers::Backend::Migrate::ToMetabase
#pod schema:
#pod $ref: _schema
#pod
#pod For more information about container files, see L<the Beam::Wire
#pod documentation|Beam::Wire>.
#pod
#pod =head1 QUICKSTART
#pod
#pod Here's a short tutorial for getting started with C<Beam::Runner>. If you
#pod want to try it yourself, start with an empty directory.
#pod
#pod =head2 Create a Task
#pod
#pod To create a task, make a Perl module that uses the L<Beam::Runnable> role
#pod and implements a C<run> method. For an example, let's create a task that
#pod prints C<Hello, World!> to the screen.
#pod
#pod package My::Runnable::Greeting;
#pod use Moo;
#pod with 'Beam::Runnable';
#pod sub run {
#pod my ( $self, @args ) = @_;
#pod print "Hello, World!\n";
#pod }
#pod 1;
#pod
#pod If you're following along, save this in the
lib/Beam/Runner.pm view on Meta::CPAN
#pod
#pod =head2 Going Further
#pod
#pod For more information on how to use the configuration file to create more
#pod complex objects like database connections, see
#pod L<Beam::Wire::Help::Config>.
#pod
#pod To learn how to run your tasks using a distributed job queue to
#pod parallelize and improve performance, see L<Beam::Minion>.
#pod
#pod =head1 SEE ALSO
#pod
#pod L<beam>, L<Beam::Runnable>, L<Beam::Wire>
#pod
#pod =cut
use strict;
use warnings;
1;
__END__
=pod
=head1 NAME
Beam::Runner - Configure, list, document, and execute runnable task objects
=head1 VERSION
version 0.016
=head1 SYNOPSIS
beam run <container> <task> [<args...>]
beam list
beam list <container>
beam help <container> <task>
beam help
=head1 DESCRIPTION
This distribution is an execution and organization system for runnable
objects (tasks). This allows you to prepare a list of runnable tasks in
configuration files and then execute them. This also allows easy
discovery of configuration files and objects, and allows you to document
your objects for your users.
=head2 Tasks
A task is an object that consumes the L<Beam::Runnable> role. This role
requires only a C<run()> method be implemented in the class. This
C<run()> method should accept all the arguments given on the command
line. It can parse GNU-style options out of this array using
L<Getopt::Long/GetOptionsFromArray>.
Task modules can compose additional roles to easily add more features,
like adding a timeout with L<Beam::Runnable::Timeout::Alarm>.
Task modules are expected to have documentation that will be displayed
by the C<beam list> and C<beam help> commands. The C<beam list> command
will display the C<NAME> section of the documentation, and the C<beam
help> command will display the C<NAME>, C<SYNOPSIS>, C<DESCRIPTION>,
C<ARGUMENTS>, C<OPTIONS>, C<ENVIRONMENT>, and C<SEE ALSO> sections of
the documentation.
=head2 Configuration Files
The configuration file is a L<Beam::Wire> container file that describes
objects. Some of these objects are marked as executable tasks by
consuming the L<Beam::Runnable> role.
The container file can have a special entry called C<$summary> which
has a short summary that will be displayed when using the C<beam list>
command.
Here's an example container file that has a summary, configures
a L<DBIx::Class> schema (using the schema class for CPAN Testers:
L<CPAN::Testers::Schema>), and configures a runnable task called
C<to_metabase> located in the class
C<CPAN::Testers::Backend::Migrate::ToMetabase>:
# migrate.yml
$summary: Migrate data between databases
_schema:
$class: CPAN::Testers::Schema
$method: connect_from_config
to_metabase:
$class: CPAN::Testers::Backend::Migrate::ToMetabase
schema:
$ref: _schema
For more information about container files, see L<the Beam::Wire
documentation|Beam::Wire>.
=head1 QUICKSTART
Here's a short tutorial for getting started with C<Beam::Runner>. If you
want to try it yourself, start with an empty directory.
=head2 Create a Task
To create a task, make a Perl module that uses the L<Beam::Runnable> role
and implements a C<run> method. For an example, let's create a task that
prints C<Hello, World!> to the screen.
package My::Runnable::Greeting;
use Moo;
with 'Beam::Runnable';
sub run {
my ( $self, @args ) = @_;
print "Hello, World!\n";
}
1;
If you're following along, save this in the
( run in 0.701 second using v1.01-cache-2.11-cpan-8f98c5d2c55 )