Skip to content

Commit

Permalink
new option -I to modify @inc
Browse files Browse the repository at this point in the history
  • Loading branch information
nichtich committed Jan 17, 2014
1 parent eef3ba7 commit 033d096
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 4 deletions.
9 changes: 7 additions & 2 deletions bin/catmandu
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,13 @@ Display the help screen.
=item -L PATH
Search upwards from this path for configuration files and lib directories.
This option is repeatable.
Search upwards from this path for configuration files. This option is repeatable.
=item --lib-path PATH
=item -I
Try to load Catmandu modules from this library path. This option is repeatable.
=back
Expand Down
5 changes: 4 additions & 1 deletion lib/Catmandu/CLI.pm
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ sub plugin_search_path { 'Catmandu::Cmd' }
sub global_opt_spec {
(
['load_path|L=s@', ""],
['lib_path|I=s@', ""],
);
}

Expand All @@ -26,7 +27,9 @@ sub run {
my $load_path = $global_opts->{load_path};
Catmandu->load(@$load_path);

my $self = $class->new;
unshift @INC, @{ $global_opts->{lib_path} || [ ] };

my $self = ref $class ? $class : $class->new;
$self->set_global_options($global_opts);
my ($cmd, $opts, @args) = $self->prepare_command(@$argv);
$self->execute_command($cmd, $opts, @args);
Expand Down
14 changes: 13 additions & 1 deletion t/Catmandu-CLI.t
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use strict;
use warnings;
use Test::More;
use Test::Exception;
use App::Cmd::Tester;

my $pkg;
BEGIN {
Expand All @@ -12,5 +13,16 @@ BEGIN {
}
require_ok $pkg;

done_testing 2;
use Carp::Always;

# check -I / --lib_path
if ($^O ne 'MSWin32') { # /dev/null required
# FIXME: Catmandu dies if testing with output to STDOUT
my $result = test_app( 'Catmandu::CLI' => [qw(
-I /dev/null -I t/lib convert Values --values 1;2;8 to JSON -file /dev/null
)] );
ok !$result->error;
}

done_testing;

19 changes: 19 additions & 0 deletions t/lib/Catmandu/Importer/Values.pm
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package Catmandu::Importer::Values;

use namespace::clean;
use Catmandu::Sane;
use Moo;

with 'Catmandu::Importer';

has values => (is => 'ro', default => sub { '' });

sub generator {
my ($self) = @_;
sub {
state $values = [ split /;/, $self->values ];
return @$values ? { value => shift(@$values) } : undef;
};
}

1;

0 comments on commit 033d096

Please sign in to comment.