File: 004_moose_for_meta.t

package info (click to toggle)
libmouse-perl 2.6.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 2,156 kB
  • sloc: perl: 14,569; ansic: 218; makefile: 8
file content (83 lines) | stat: -rw-r--r-- 2,232 bytes parent folder | download | duplicates (4)
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
#!/usr/bin/perl
# This is automatically generated by author/import-moose-test.pl.
# DO NOT EDIT THIS FILE. ANY CHANGES WILL BE LOST!!!
use lib "t/lib";
use MooseCompat;

use strict;
use warnings;

use Test::More;
use Test::Exception;


=pod

This test demonstrates the ability to extend
Mouse meta-level classes using Mouse itself.

=cut

{
    package My::Meta::Class;
    use Mouse;

    extends 'Mouse::Meta::Class';

    around 'create_anon_class' => sub {
        my $next = shift;
        my ($self, %options) = @_;
        $options{superclasses} = [ 'Mouse::Object' ]
            unless exists $options{superclasses};
        $next->($self, %options);
    };
}

my $anon = My::Meta::Class->create_anon_class();
isa_ok($anon, 'My::Meta::Class');
isa_ok($anon, 'Mouse::Meta::Class');
isa_ok($anon, 'Mouse::Meta::Class');

is_deeply(
    [ $anon->superclasses ],
    [ 'Mouse::Object' ],
    '... got the default superclasses');

{
    package My::Meta::Attribute::DefaultReadOnly;
    use Mouse;

    extends 'Mouse::Meta::Attribute';

    around 'new' => sub {
        my $next = shift;
        my ($self, $name, %options) = @_;
        $options{is} = 'ro'
            unless exists $options{is};
        $next->($self, $name, %options);
    };
}

{
    my $attr = My::Meta::Attribute::DefaultReadOnly->new('foo');
    isa_ok($attr, 'My::Meta::Attribute::DefaultReadOnly');
    isa_ok($attr, 'Mouse::Meta::Attribute');
    isa_ok($attr, 'Mouse::Meta::Attribute');

    ok($attr->has_reader, '... the attribute has a reader (as expected)');
    ok(!$attr->has_writer, '... the attribute does not have a writer (as expected)');
    ok(!$attr->has_accessor, '... the attribute does not have an accessor (as expected)');
}

{
    my $attr = My::Meta::Attribute::DefaultReadOnly->new('foo', (is => 'rw'));
    isa_ok($attr, 'My::Meta::Attribute::DefaultReadOnly');
    isa_ok($attr, 'Mouse::Meta::Attribute');
    isa_ok($attr, 'Mouse::Meta::Attribute');

    ok(!$attr->has_reader, '... the attribute does not have a reader (as expected)');
    ok(!$attr->has_writer, '... the attribute does not have a writer (as expected)');
    ok($attr->has_accessor, '... the attribute does have an accessor (as expected)');
}

done_testing;