Revision history for Perl extension MooseX::SimpleConfig
+0.03 - Jan 23, 2008
+ - Mostly just added pod and tests for configfile
+ defaulting
+
0.02 - Dec 19, 2007
- Skip the tests if neither of YAML or YAML::Syck is
installed (but don't make it a test requirement,
README
t/01use.t
t/10simple.t
+t/11default.t
+t/lib/MXDefaultConfigTest.pm
t/lib/MXSimpleConfigTest.pm
test_requires 'Test::More' => '0.42';
-requires 'Moose' => '0';
-requires 'MooseX::ConfigFromFile' => '0';
-requires 'Config::Any' => '0';
+requires 'Moose' => '0.35';
+requires 'MooseX::ConfigFromFile' => '0.02';
+requires 'Config::Any' => '0.10';
# Rebuild README for maintainers
system("pod2text lib/MooseX/SimpleConfig.pm >README") if -e 'MANIFEST.SKIP';
ATTRIBUTES
configfile
- Provided by the base role MooseX::ConfigFromFile.
+ Provided by the base role MooseX::ConfigFromFile. You can provide a
+ default configfile pathname like so:
+
+ has +configfile ( default => '/etc/myapp.yaml' );
CLASS METHODS
new_with_config
use Moose::Role;
with 'MooseX::ConfigFromFile';
-our $VERSION = '0.02';
+our $VERSION = '0.03';
use Config::Any ();
=head2 configfile
-Provided by the base role L<MooseX::ConfigFromFile>.
+Provided by the base role L<MooseX::ConfigFromFile>. You can
+provide a default configfile pathname like so:
+
+ has +configfile ( default => '/etc/myapp.yaml' );
=head1 CLASS METHODS
--- /dev/null
+#!/usr/bin/perl
+
+use strict;
+use warnings;
+
+use lib 't/lib';
+use lib '../t/lib';
+
+BEGIN {
+ use Test::More;
+
+ eval "use YAML::Syck ()";
+ if($@) {
+ eval "use YAML ()";
+ if($@) {
+ plan skip_all => "YAML or YAML::Syck required for this test";
+ }
+ }
+
+ plan tests => 5;
+
+ use_ok('MXDefaultConfigTest');
+}
+
+# Can it load a simple YAML file with the options
+# based on a default in the configfile attr
+{
+ open(my $test_yaml, '>', 'test.yaml')
+ or die "Cannot create test.yaml: $!";
+ print $test_yaml "direct_attr: 123\ninherited_ro_attr: asdf\nreq_attr: foo\n";
+ close($test_yaml);
+
+ my $foo = eval {
+ MXDefaultConfigTest->new_with_config();
+ };
+ ok(!$@, 'Did not die with good YAML configfile')
+ or diag $@;
+
+ is($foo->req_attr, 'foo', 'req_attr works');
+ is($foo->direct_attr, 123, 'direct_attr works');
+ is($foo->inherited_ro_attr, 'asdf', 'inherited_ro_attr works');
+}
+
+END { unlink('test.yaml') }
--- /dev/null
+package MXDefaultConfigTestBase;
+use Moose;
+
+has 'inherited_ro_attr' => (is => 'ro', isa => 'Str');
+
+no Moose;
+1;
+
+package MXDefaultConfigTest;
+use Moose;
+use Path::Class::File;
+extends 'MXDefaultConfigTestBase';
+with 'MooseX::SimpleConfig';
+
+has 'direct_attr' => (is => 'ro', isa => 'Int');
+
+has 'req_attr' => (is => 'rw', isa => 'Str', required => 1);
+
+has '+configfile' => ( default => 'test.yaml' );
+
+no Moose;
+1;