-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add the ability to work with MX::ConfigFromFile, just like MX::Getopt
(would be nice MX::Getopt made this part separate from new_with_options so it can be reused)
- Loading branch information
Daisuke Maki
committed
Jul 16, 2008
1 parent
fa6500a
commit b52abd9
Showing
5 changed files
with
111 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
#!perl -T | ||
|
||
use strict; | ||
use warnings; | ||
use Test::More; | ||
|
||
BEGIN | ||
{ | ||
eval { | ||
require MooseX::ConfigFromFile; | ||
require YAML; | ||
}; | ||
if ($@) { | ||
plan( skip_all => "These tests require MooseX::ConfigFromFile and YAML" ); | ||
} else { | ||
plan( tests => 2 ); | ||
} | ||
} | ||
|
||
use lib 't/lib'; | ||
use Test::ConfigFromFile; | ||
|
||
my $cmd = Test::ConfigFromFile->new; | ||
|
||
{ | ||
local @ARGV = qw(moo); | ||
eval { $cmd->run }; | ||
|
||
like( | ||
$@, | ||
qr/Required option missing/, | ||
"command died with the correct string", | ||
); | ||
} | ||
|
||
{ | ||
local @ARGV = qw(moo --configfile=t/lib/Test/ConfigFromFile/config.yaml); | ||
eval { $cmd->run }; | ||
|
||
like( | ||
$@, | ||
qr/cows go moo1 moo2 moo3/, | ||
"command died with the correct string", | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package Test::ConfigFromFile; | ||
use Moose; | ||
|
||
extends qw(MooseX::App::Cmd); | ||
|
||
1; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package Test::ConfigFromFile::Command::moo; | ||
use Moose; | ||
use YAML(); | ||
|
||
extends qw(MooseX::App::Cmd::Command); | ||
with 'MooseX::ConfigFromFile'; | ||
|
||
=head1 NAME | ||
Test::MyCmd::Command::moo - reads from config file | ||
=cut | ||
|
||
has 'moo' => ( | ||
isa => "ArrayRef", | ||
is => "ro", | ||
required => 1, | ||
auto_deref => 1, | ||
documentation => "required option field", | ||
); | ||
|
||
sub run { | ||
my ($self, $opt, $arg) =@_; | ||
|
||
die ("cows go " . join(' ', $self->moo)); | ||
} | ||
|
||
sub get_config_from_file { | ||
my ($self, $file) = @_; | ||
|
||
return YAML::LoadFile($file); | ||
} | ||
|
||
1; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
moo: | ||
- moo1 | ||
- moo2 | ||
- moo3 |