File: 03configfile_method.t

package info (click to toggle)
libmoosex-configfromfile-perl 0.14-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster, sid, stretch
  • size: 316 kB
  • ctags: 2
  • sloc: perl: 252; makefile: 2
file content (57 lines) | stat: -rw-r--r-- 1,314 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
use strict;
use warnings;

use Test::More;
use if $ENV{AUTHOR_TESTING}, 'Test::Warnings';
use Test::Fatal;

my %config_from_file_args;
{
    package A;
    use Moose;
    with qw(MooseX::ConfigFromFile);

    sub configfile { die 'should not ever be here' }

    sub get_config_from_file {
        my ($class, $file) = @_;
        $config_from_file_args{$class} = $file;
        return {};
    }
}

{
    package B;
    use Moose;
    extends qw(A);

    sub configfile { die; }
    has configfile => ( is => 'bare', default => 'bar' );
}

{
    package C;
    use Moose;
    extends qw(A);

    sub configfile { die; }
    has configfile => (
        is => 'bare',
        default => sub {
            my $class = shift;
            $class = blessed($class) || $class;
            '/dir/' . $class;
        },
    );
}

is(exception { A->new_with_config() }, undef, 'A->new_with_config lives');
is($config_from_file_args{A}, undef, 'there is no configfile for A');

is(exception { B->new_with_config() }, undef, 'B->new_with_config lives');
is($config_from_file_args{B}, 'bar', 'B configfile attr default sub is called');

is(exception { C->new_with_config() }, undef, 'C->new_with_config lives');
is($config_from_file_args{C}, '/dir/C', 'C configfile attr default sub is called, with classname');

done_testing;