4 use Test::More tests => 20;
6 use Test::Deep '!blessed';
7 use Test::NoWarnings 1.04 ':early';
8 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 that we must continue to support
35 package OverriddenDefault;
37 with 'MooseX::SimpleConfig';
38 sub get_config_from_file
40 my ($class, $file) = @_;
41 $loaded_file{$file}++;
44 has '+configfile' => (
45 default => 'OverriddenDefault file',
51 my $obj = OverriddenDefault->new_with_config;
52 is($obj->configfile, 'OverriddenDefault file', 'configfile set via overridden default');
53 is($loaded_file{'OverriddenDefault file'}, 1, 'correct file was loaded from');
60 # legacy usecase, and configfile init_arg has been changed
62 package OverriddenDefaultAndChangedName;
64 with 'MooseX::SimpleConfig';
65 sub get_config_from_file
67 my ($class, $file) = @_;
68 $loaded_file{$file}++;
71 has '+configfile' => (
72 init_arg => 'my_configfile',
73 default => 'OverriddenDefaultAndChangedName file',
75 around BUILDARGS => sub {
76 my ($orig, $class) = (shift, shift);
77 my $args = $class->$orig(@_);
78 $constructor_args{$class} = $args;
84 my $obj = OverriddenDefaultAndChangedName->new_with_config;
85 is($obj->configfile, blessed($obj) . ' file', 'configfile set via overridden default');
87 $constructor_args{blessed($obj)},
88 { my_configfile => blessed($obj) . ' file' },
89 'correct constructor args passed',
91 is($loaded_file{blessed($obj) . ' file'}, 1, 'correct file was loaded from');
98 # newly-supported overridable method for configfile default
102 with 'MooseX::SimpleConfig';
103 sub get_config_from_file
105 my ($class, $file) = @_;
106 $loaded_file{$file}++;
110 sub _get_default_configfile {
112 $default_sub{$class}++;
116 around BUILDARGS => sub {
117 my ($orig, $class) = (shift, shift);
118 my $args = $class->$orig(@_);
119 $constructor_args{$class} = $args;
125 my $obj = WrapperSub->new_with_config;
126 is($obj->configfile, blessed($obj) . ' file', 'configfile set via overridden sub');
128 $constructor_args{blessed($obj)},
129 { configfile => blessed($obj) . ' file' },
130 'correct constructor args passed',
132 is($default_sub{blessed($obj)}, 1, 'default sub called just once');
133 is($loaded_file{blessed($obj) . ' file'}, 1, 'correct file was loaded from');
140 # newly-supported overridable method for configfile default, and configfile
141 # init_arg has been changed
143 package WrapperSubAndChangedName;
145 with 'MooseX::SimpleConfig';
146 has '+configfile' => (
147 init_arg => 'my_configfile',
149 sub get_config_from_file
151 my ($class, $file) = @_;
152 $loaded_file{$file}++;
156 sub _get_default_configfile {
158 $default_sub{$class}++;
162 around BUILDARGS => sub {
163 my ($orig, $class) = (shift, shift);
164 my $args = $class->$orig(@_);
165 $constructor_args{$class} = $args;
171 my $obj = WrapperSubAndChangedName->new_with_config;
172 is($obj->configfile, blessed($obj) . ' file', 'configfile set via overridden sub');
174 $constructor_args{blessed($obj)},
175 { my_configfile => blessed($obj) . ' file' },
176 'correct constructor args passed',
178 is($default_sub{blessed($obj)}, 1, 'default sub called just once');
179 is($loaded_file{blessed($obj) . ' file'}, 1, 'correct file was loaded from');