Kook - task automation utility like Make, Ant, or Rake
($Release: 0.0100 $)
Filename: Kookbook.pl
use strict; use warnings; ## properties my $CC = prop('CC', 'gcc'); ## default recipe $kook->{default} = 'build'; ## task recipe recipe 'build', { ingreds => ['hello.exe'], desc => 'build all files', #kind => 'task', }; ## file recipe recipe 'hello.exe', { ingreds => ['hello.o'], desc => "build 'hello' command", #kind => 'file', method => sub { my $c = shift; sys "$CC -o $c->{product} $c->{ingred}"; } }; ## rule recipe recipe '*.o', { ingreds => ['$(1).c', '$(1).h'], desc => "build '*.o' from '*.c'", method => sub { my $c = shift; sys "$CC -c $c->{ingred}"; # or $c->{ingreds}->[0] } };
Command-line example:
bash> kk -l # or plkook -l Properties: CC : "gcc" Task recipes (default=build): build : build all files File recipes: hello : build 'hello' command *.o : build '*.o' from '*.c' (Tips: ingreds=>['$(1).c', if_exists('$(1).h')] is a friend of C programmer.) bash> kk build ### *** hello.o (recipe=*.o) $ gcc -c hello.c ### ** hello (recipe=hello) $ gcc -o hello hello.o ### * build (recipe=build)
Kook (or plKook) is a task automation utility for Perl, like Make, Ant or Rake. Unix-like commands (cp, mv, rm, and so on) are also implemented in pure Perl.
## task recipe recipe 'test', { desc => "do test", method => sub { sys "prove t"; } }; ## file recipe recipe 'README', { ingreds => ['lib/Kook.pm'], # 'ingreds' means 'ingredients' desc => "create 'README'", kind => 'file', # 'file' or 'task' (optional) method => sub { my ($c) = @_; sys "pod2text $c->{ingred} > $c->{product}"; } }; ## rule recipe recipe '*.o', { ingreds => ['$(1).c', '$(1).h'], # 'ingreds' means 'ingredients' desc => "compile *.c and *.h into *.o", method => sub { my ($c) = @_; sys "gcc -c $c->{ingred}"; } };
In Kook, 'spices' means command-line options for recipes.
my @versions = ('5.8.9', '5.10.1', '5.12.4'); recipe 'test', { desc => "do test", spices => ["-a: do test with Perl ".join(", ", @versions)], method => sub { my ($c, $opts) = @_; if ($opts->{'a'}) { for (@versions) { print "##### Perl $_\n"; sys "/usr/local/perl/$_/bin/prove t"; } } else { sys 'prove t'; } } };
bash> kk test -a # or plkook test -a
Invokes OS command. sys_f returns without error even when OS command is failed.
sys 'prove t'; sys_f 'prove t'; # ignore status of 'prove' command
Same as cp, cp -p, cp -r, cp -pr commands respectively.
cp_pr $file1, $file2; cp_pr @files, $dir; cp_pr '*.jpg', '*.png', $dir;
Similar to cp command, but keeps file path.
store 'lib/**/*', 't/**/*', 'dist/hello-1.0.0';
Same as mv command in Unix.
mv 'A.html', 'B/C.html'; mv '*.jpg', '*.png', $dir;
Same as mkdir and mkdir -p commands respectively.
mkdir_p 'dist/Hello-1.0.0/lib';
Same as rm, rm -r, rm -f, and rm -rf commands respectively.
rm_rf '**/*.o', '**/*.a';
Same as rmdir command on Unix.
rmdir 'emptydir';
Change directory. If closure specified as 2nd argument, back to current directory after calling it.
cd 'dist/hello-1.0.0', sub { sys 'find . -type f > MANIFEST'; };
Echo arguments and prints "\n";
echo 'SOS';
Edit files.
my $version = '1.0.0'; edit 'dist/hello-1.0.0/**/*', sub { s/\$VERSION\$/$version/ge; $_; };
[_] User's Guide
[_] Category
[_] Import Books
[_] Meta Programming
[_] Paralellize
[_] Concatenation
makoto kuwata <kwa@kuwata-lab.com>
MIT License
To install Kook, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Kook
CPAN shell
perl -MCPAN -e shell install Kook
For more information on module installation, please visit the detailed CPAN module installation guide.