App-Dothe
view release on metacpan or search on metacpan
lib/App/Dothe.pm view on Meta::CPAN
return $self->{tasks}{$name} ||= App::Dothe::Task->new(
name => $name, tasks => $self, $self->config->{tasks}{$name}->%* );
}
option file => (
is => 'ro',
documentation => 'configuration file',
isa => 'Str',
default => './Dothe.yml',
);
has config => (
is => 'ro',
lazy => 1,
default => sub($self) { LoadFile( $self->file ) },
);
sub run( $self ) {
if ( my $code = $self->config->{code} ) {
eval join '', 'package App::Dothe::Sandbox;', @$code;
}
$self->task($self->target)->run;
}
sub template ($self,$source) {
return Text::Template->new( TYPE => 'STRING', DELIMITERS => [ '{{', '}}' ],
SOURCE => $source );
}
1;
__END__
=pod
=encoding UTF-8
=head1 NAME
App::Dothe - YAML-based task runner
=head1 VERSION
version 0.0.1
=head1 DESCRIPTION
Task runner heavily inspired by Task (L<https://github.com/go-task/task>).
Basically, I wanted C<Task>, but with a C<foreach> construct.
See C<perldoc App::DoThe> for the syntax of the F<Dothe.yml> file.
=head1 DOTHE SYNTAX
The configuration file is in YAML. It follows, by and large, the
format used by Task.
By default, `dothe` looks for the file `Dothe.yml`.
Where entries can be templates, they are evaluated via L<Text::Template>.
Basically, that means that in a template all that is surrounded by double curley braces
is evaluated as Perl code. Those code snippets are evaluated within the
C<App::Dothe::Sandbox> namespace, and have all the C<vars> variables
accessible to them.
=head2 C<code> section
Takes an array. Each item will be eval'ed in the namespace
used by the template code.
For example, to have access to L<Path::Tiny>'s
C<path>:
code:
- use Path::Tiny;
tasks:
import-all:
sources:
- /home/yanick/work/blog_entries/**/entry
foreach: sources
cmds:
- task: import
vars: { dir: '{{ path($item)->parent }}' }
=head2 C<vars> section
Takes a hash of variable names and values. Those are variables that will be accessible to all
tasks.
E.g.,
vars:
entries_file: ./content/_shared/entries.md
blog_entries_root: /home/yanick/work/blog_entries
=head2 C<tasks> section
Takes a hash of task names and their definitions.
E.g.,
tasks:
something:
sources: [ ./src/foo.source ]
generates: [ ./dest/foo.dest ]
foreach: sources
cmds:
- ./tools/process_entry.pl {{$item}}
=head3 C<task>
Defines a specific task.
=head4 C<vars>
Hash of variable names and values to be made accessible to the
( run in 2.985 seconds using v1.01-cache-2.11-cpan-39bf76dae61 )