4 use Test::More tests => 10;
6 use Test::Deep '!blessed';
7 use Test::NoWarnings 1.04 ':early';
8 use Scalar::Util 'blessed';
14 # nothing special going on here
18 with 'MooseX::SimpleConfig';
19 sub get_config_from_file { }
24 my $obj = Generic->new_with_config;
25 is($obj->configfile, undef, 'no configfile set');
32 # this is a classic legacy usecase from old documentation that we must
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, blessed($obj) . ' file', 'configfile set via overridden default');
53 is($loaded_file{blessed($obj) . ' file'}, 1, 'correct file was loaded from');
60 # "reader" method is overridden to provide for configfile default
62 package OverriddenMethod;
64 with 'MooseX::SimpleConfig';
65 sub get_config_from_file {
66 my ($class, $file) = @_;
67 $loaded_file{$file}++;
71 around configfile => sub {
72 my $class = blessed($_[1]) || $_[1];
73 $default_sub{$class}++;
80 my $obj = OverriddenMethod->new_with_config;
81 is($obj->configfile, blessed($obj) . ' file', 'configfile set via overridden sub');
82 ok($default_sub{blessed($obj)}, 'default sub was called');
83 is($loaded_file{blessed($obj) . ' file'}, 1, 'correct file was loaded from');