3 use Getopt::Long qw(GetOptionsFromArray :config posix_defaults bundling);
8 has options => (is => 'ro', required => 1);
9 has env => (is => 'ro', required => 1);
11 has stdin => (is => 'lazy');
12 has stdout => (is => 'lazy');
13 has stderr => (is => 'lazy');
15 sub _build_stdin { shift->env->{stdin} }
16 sub _build_stdout { shift->env->{stdout} }
17 sub _build_stderr { shift->env->{stderr} }
19 has config => (is => 'lazy');
23 Config::Settings->new->parse_file(
24 $self->options->{config} || '.tak/default.conf'
35 my ($self, $string, \@argv) = @_;
36 my @spec = split ';', $string;
40 my @argv = @{$self->env->{argv}};
41 unless (@argv && $argv[0]) {
42 return $self->local_help;
44 my $cmd = shift(@argv);
45 if (my $code = $self->can("local_$cmd")) {
46 return $self->_run($cmd, $code, @argv);
47 } elsif ($code = $self->can("each_$cmd")) {
48 return $self->_run_each($cmd, $code, @argv);
50 $self->stderr->print("No such command: ${cmd}\n");
51 return $self->local_help;
55 my ($self, $file) = @_;
56 $self->_load_file_in_my_script($file);
61 $self->stderr->print("Help unimplemented\n");
65 my ($self, $cmd, $code, @argv) = @_;
67 if (my $proto = prototype($code)) {
68 $self->_parse_options($proto, \@argv);
73 $self->$code($opt, @argv);