File: compat.t

package info (click to toggle)
libmoosex-util-perl 0.006-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 256 kB
  • sloc: perl: 101; makefile: 2
file content (103 lines) | stat: -rw-r--r-- 2,961 bytes parent folder | download | duplicates (3)
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
use strict;
use warnings;

use Test::More;
use Test::Moose::More 0.016;

use Test::Requires 'Reindeer';

use aliased 'MooseX::TraitFor::Meta::Class::BetterAnonClassNames'
    => 'MetaTrait';
use aliased 'MooseX::Util::Meta::Class'
    => 'MetaClass';

# this is a rather sideways test; we're checking for metaclass compatibility
# between anon classes we create with our class metaclass subclass and
# packages already known to not be using an unadulterated Moose::Meta::Class
# metaclass.  This needs some work, but it's OK as a parakeet in the
# proverbial metaclass tunnel (for now).
#
# we do have a weird issue w.r.t. the metaclass instance for our last
# generated class claiming to not be anonymous, but I might be getting the
# metaness jumbled here.

{ package Zombie::Catcher;                              use Reindeer;    }
{ package Zombie::Catcher::Tools::Machete;              use Moose::Role; }
{ package Zombie::Catcher::Tools::TracyChapmansFastCar; use Reindeer::Role; }

my $catcher = MooseX::Util::Meta::Class->create_anon_class(
    superclasses => [ 'Zombie::Catcher' ],
    weaken => 0,
    roles => [ qw{
        Zombie::Catcher::Tools::Machete
    } ],
);

# created anon classname like: Zombie::Catcher::__ANON__::SERIAL::42
note $catcher->name;

validate_class $catcher->name => (
    anonymous => 1,
    isa       => [ 'Zombie::Catcher' ],
    does      => [ qw{
        Zombie::Catcher::Tools::Machete
    }],
);

like $catcher->name, qr/^Zombie::Catcher::__ANON__::SERIAL::\d+$/, 'named as expected';

my $fast_catcher = MooseX::Util::Meta::Class->create_anon_class(
    superclasses => [ $catcher->name ],
    weaken => 0,
    roles => [ qw{
        Zombie::Catcher::Tools::TracyChapmansFastCar
    } ],
);

subtest q{validate $fast_catcher's metaclass} => sub {

    validate_class $fast_catcher => (
        anonymous => 1,
        # a trait we know Reindeer uses, and ours
        does => [
            'MooseX::StrictConstructor::Trait::Class',
            MetaTrait,
        ],
        attributes => [
            'is_anon',
        ],
        methods => [ 'is_anon' ],
    );

    is_anon $fast_catcher;
    is $fast_catcher->meta->is_anon, 1, 'is_anon is set correctly (true)';
};

subtest q{validate $fast_catcher} => sub {


    validate_class $fast_catcher->name => (
        # see TODO, below
        #anonymous => 1,
        isa  => [ $catcher->name ],
        does => [ qw{
            Zombie::Catcher::Tools::TracyChapmansFastCar
        }],
    );

    is $fast_catcher->is_anon, 1, 'is_anon is set correctly (true)';
    is
        $fast_catcher->anon_package_prefix,
        'Zombie::Catcher::__ANON__::SERIAL::',
        'anon_package_prefix correct',
        ;

    {
        local $TODO = 'known issue -- metaclass compat weirdness with is_anon fail';
        is_anon $fast_catcher->name;
    }

    like $fast_catcher->name, qr/^Zombie::Catcher::__ANON__::SERIAL::\d+$/, 'named as expected';
};

done_testing;