From: Brandon L Black Date: Wed, 23 Jan 2008 06:12:59 +0000 (+0000) Subject: 0.03, configfile default stuff X-Git-Tag: 0.03^0 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=a96520dd1f1563ad6c55047dea3f80e0bd125c41;p=gitmo%2FMooseX-SimpleConfig.git 0.03, configfile default stuff --- diff --git a/ChangeLog b/ChangeLog index ba6b20b..1b412e7 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,9 @@ 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, diff --git a/MANIFEST b/MANIFEST index 4b8e113..99abdc9 100644 --- a/MANIFEST +++ b/MANIFEST @@ -18,4 +18,6 @@ META.yml README t/01use.t t/10simple.t +t/11default.t +t/lib/MXDefaultConfigTest.pm t/lib/MXSimpleConfigTest.pm diff --git a/Makefile.PL b/Makefile.PL index 3f37100..342128d 100644 --- a/Makefile.PL +++ b/Makefile.PL @@ -6,9 +6,9 @@ all_from 'lib/MooseX/SimpleConfig.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'; diff --git a/README b/README index c98e52a..09c3cb8 100644 --- a/README +++ b/README @@ -65,7 +65,10 @@ DESCRIPTION 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 diff --git a/lib/MooseX/SimpleConfig.pm b/lib/MooseX/SimpleConfig.pm index 76380e5..e12b104 100644 --- a/lib/MooseX/SimpleConfig.pm +++ b/lib/MooseX/SimpleConfig.pm @@ -3,7 +3,7 @@ package MooseX::SimpleConfig; use Moose::Role; with 'MooseX::ConfigFromFile'; -our $VERSION = '0.02'; +our $VERSION = '0.03'; use Config::Any (); @@ -106,7 +106,10 @@ well, which allows specifying C<-configfile> on the commandline. =head2 configfile -Provided by the base role L. +Provided by the base role L. You can +provide a default configfile pathname like so: + + has +configfile ( default => '/etc/myapp.yaml' ); =head1 CLASS METHODS diff --git a/t/11default.t b/t/11default.t new file mode 100644 index 0000000..aaacca2 --- /dev/null +++ b/t/11default.t @@ -0,0 +1,44 @@ +#!/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') } diff --git a/t/lib/MXDefaultConfigTest.pm b/t/lib/MXDefaultConfigTest.pm new file mode 100644 index 0000000..a4afb61 --- /dev/null +++ b/t/lib/MXDefaultConfigTest.pm @@ -0,0 +1,22 @@ +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;