File: basic.t

package info (click to toggle)
libmoosex-traitfor-meta-class-betteranonclassnames-perl 0.002003-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 256 kB
  • sloc: perl: 234; makefile: 2
file content (69 lines) | stat: -rw-r--r-- 1,830 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
use strict;
use warnings;

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

use MooseX::TraitFor::Meta::Class::BetterAnonClassNames;

{
    package Zombie::Catcher;
    use Moose;
    use Moose::Util::MetaRole;

    Moose::Util::MetaRole::apply_metaroles(
        for             => __PACKAGE__,
        class_metaroles => {
            class => [ 'MooseX::TraitFor::Meta::Class::BetterAnonClassNames' ],
        },
    );
}
{ package Zombie::Catcher::Tools::Machete;              use Moose::Role; }
{ package Zombie::Catcher::Tools::TracyChapmansFastCar; use Moose::Role; }

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

# creates 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';

is $catcher->anon_package_prefix => 'Zombie::Catcher::__ANON__::SERIAL::',
    'anon_package_prefix is as expected';

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

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

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

is $fast_catcher->anon_package_prefix => 'Zombie::Catcher::__ANON__::SERIAL::',
    'anon_package_prefix is as expected';

done_testing;