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