coolio
[gitmo/Moose.git] / t / 060_moose_for_meta.t
CommitLineData
d500266f 1#!/usr/bin/perl
2
3use strict;
4use warnings;
5
6use Test::More tests => 16;
7use Test::Exception;
8
9BEGIN {
10 use_ok('Moose');
11}
12
13{
14 package My::Meta::Class;
15 use strict;
16 use warnings;
17 use Moose;
18
19 extends 'Moose::Meta::Class';
20}
21
22my $anon = My::Meta::Class->create_anon_class();
23isa_ok($anon, 'My::Meta::Class');
24isa_ok($anon, 'Moose::Meta::Class');
25isa_ok($anon, 'Class::MOP::Class');
26
27{
28 package My::Meta::Attribute::DefaultReadOnly;
29 use strict;
30 use warnings;
31 use Moose;
32
33 extends 'Moose::Meta::Attribute';
34
35 around 'new' => sub {
36 my $next = shift;
37 my $self = shift;
38 my $name = shift;
39 $next->($self, $name, (is => 'ro'), @_);
40 };
41}
42
43{
44 my $attr = My::Meta::Attribute::DefaultReadOnly->new('foo');
45 isa_ok($attr, 'My::Meta::Attribute::DefaultReadOnly');
46 isa_ok($attr, 'Moose::Meta::Attribute');
47 isa_ok($attr, 'Class::MOP::Attribute');
48
49 ok($attr->has_reader, '... the attribute has a reader (as expected)');
50 ok(!$attr->has_writer, '... the attribute does not have a writer (as expected)');
51 ok(!$attr->has_accessor, '... the attribute does not have an accessor (as expected)');
52}
53
54{
55 my $attr = My::Meta::Attribute::DefaultReadOnly->new('foo', (is => 'rw'));
56 isa_ok($attr, 'My::Meta::Attribute::DefaultReadOnly');
57 isa_ok($attr, 'Moose::Meta::Attribute');
58 isa_ok($attr, 'Class::MOP::Attribute');
59
60 ok(!$attr->has_reader, '... the attribute does not have a reader (as expected)');
61 ok(!$attr->has_writer, '... the attribute does not have a writer (as expected)');
62 ok($attr->has_accessor, '... the attribute does have an accessor (as expected)');
63}
64