use warnings tester with fewer dependencies, issues
[gitmo/MooseX-ConfigFromFile.git] / t / 03configfile_method.t
CommitLineData
0e88ec88 1use strict;
bd567467 2use warnings FATAL => 'all';
56e4351b 3
fcc2d1ec 4use Test::More tests => 7;
3736a8a9 5use Test::Warnings;
fcc2d1ec 6use Test::Fatal;
56e4351b 7
8my %config_from_file_args;
0e88ec88 9{
10 package A;
11 use Moose;
12 with qw(MooseX::ConfigFromFile);
13
56e4351b 14 sub configfile { die 'should not ever be here' }
0e88ec88 15
56e4351b 16 sub get_config_from_file {
17 my ($class, $file) = @_;
18 $config_from_file_args{$class} = $file;
19 return {};
20 }
0e88ec88 21}
22
23{
24 package B;
25 use Moose;
26 extends qw(A);
27
28 sub configfile { die; }
29 has configfile => ( is => 'bare', default => 'bar' );
56e4351b 30}
0e88ec88 31
56e4351b 32{
33 package C;
34 use Moose;
35 extends qw(A);
36
37 sub configfile { die; }
38 has configfile => (
39 is => 'bare',
40 default => sub {
41 my $class = shift;
42 $class = blessed($class) || $class;
43 '/dir/' . $class;
44 },
45 );
0e88ec88 46}
47
48is(exception { A->new_with_config() }, undef, 'A->new_with_config lives');
56e4351b 49is($config_from_file_args{A}, undef, 'there is no configfile for A');
50
0e88ec88 51is(exception { B->new_with_config() }, undef, 'B->new_with_config lives');
56e4351b 52is($config_from_file_args{B}, 'bar', 'B configfile attr default sub is called');
53
54is(exception { C->new_with_config() }, undef, 'C->new_with_config lives');
55is($config_from_file_args{C}, '/dir/C', 'C configfile attr default sub is called, with classname');
56