- documentation corrected to demostrate how to properly override the
configfile method to provide a default from the consuming class, without
having to redefine the attribute itself
+ - if MooseX::Getopt is installed, the configfile attribute has the Getopt
+ trait applied (Karen Etheridge)
0.04 - Dec 17, 2011
- Call the configfile attribute default sub if it is a sub, not just a
test_requires 'Test::More' => '0.42';
test_requires 'Test::Fatal';
+test_requires 'Test::Requires';
+test_requires 'Test::NoWarnings' => '1.04';
+test_requires 'Test::Without::Module';
requires 'Moose' => '0.35';
requires 'MooseX::Types::Path::Class' => '0.04';
isa => File,
coerce => 1,
predicate => 'has_configfile',
+ do { try { require MooseX::Getopt; (traits => ['Getopt']) } },
);
sub new_with_config {
the config file when called - this will be used in preference to the default of
the attribute.
+If you have L<MooseX::Getopt> installed, this attribute will also have the
+C<Getopt> trait supplied, so you can also set the configfile from the
+command line.
+
=head1 Class Methods
=head2 new_with_config
--- /dev/null
+use strict;
+use warnings;
+
+use Test::More tests => 2;
+use Test::NoWarnings 1.04 ':early';
+
+use Test::Without::Module 'MooseX::Getopt';
+
+{
+ package Foo::NoOptions;
+
+ use Moose;
+ with qw(MooseX::ConfigFromFile);
+ sub get_config_from_file { }
+}
+
+ok(
+ !Foo::NoOptions->meta->find_attribute_by_name('configfile')->does('MooseX::Getopt::Meta::Attribute::Trait'),
+ 'the Getopt attr trait is not added if not installed',
+);
+
--- /dev/null
+use strict;
+use warnings;
+
+use Test::Requires 'MooseX::Getopt'; # skip all if not installed
+use Test::More tests => 3;
+use Test::NoWarnings 1.04 ':early';
+
+{
+ package Foo::Options;
+
+ use Moose;
+ with qw(MooseX::Getopt MooseX::ConfigFromFile);
+ sub get_config_from_file { }
+}
+
+{
+ package Foo::NoOptions;
+
+ use Moose;
+ with qw(MooseX::ConfigFromFile);
+ sub get_config_from_file { }
+}
+
+ok(
+ Foo::Options->meta->find_attribute_by_name('configfile')->does('MooseX::Getopt::Meta::Attribute::Trait'),
+ 'classes with MooseX::Getopt have the Getopt attr trait added',
+);
+
+ok(
+ Foo::NoOptions->meta->find_attribute_by_name('configfile')->does('MooseX::Getopt::Meta::Attribute::Trait'),
+ 'when MooseX::Getopt is loaded, the Getopt attr trait is still added',
+);
+