4 use Test::Requires 'MooseX::SimpleConfig'; # skip all if not reuqired
5 use Test::More tests => 10;
7 use Test::Deep '!blessed';
8 use Test::NoWarnings 1.04 ':early';
9 use Scalar::Util 'blessed';
15 # nothing special going on here
19 with 'MooseX::SimpleConfig';
20 sub get_config_from_file { }
25 my $obj = Generic->new_with_config;
26 is($obj->configfile, undef, 'no configfile set');
33 # this is a classic legacy usecase from old documentation that we must
36 package OverriddenDefault;
38 with 'MooseX::SimpleConfig';
39 sub get_config_from_file
41 my ($class, $file) = @_;
42 $loaded_file{$file}++;
45 has '+configfile' => (
46 default => 'OverriddenDefault file',
52 my $obj = OverriddenDefault->new_with_config;
53 is($obj->configfile, blessed($obj) . ' file', 'configfile set via overridden default');
54 is($loaded_file{blessed($obj) . ' file'}, 1, 'correct file was loaded from');
61 # "reader" method is overridden to provide for configfile default
63 package OverriddenMethod;
65 with 'MooseX::SimpleConfig';
66 sub get_config_from_file {
67 my ($class, $file) = @_;
68 $loaded_file{$file}++;
72 around configfile => sub {
73 my $class = blessed($_[1]) || $_[1];
74 $default_sub{$class}++;
81 my $obj = OverriddenMethod->new_with_config;
82 is($obj->configfile, blessed($obj) . ' file', 'configfile set via overridden sub');
83 ok($default_sub{blessed($obj)}, 'default sub was called');
84 is($loaded_file{blessed($obj) . ' file'}, 1, 'correct file was loaded from');