summaryrefslogtreecommitdiffstats
path: root/lib/MooseX/ArrayRef/Meta/Role/Class.pm
blob: 08734548f48b28f54ab506c446bc777ccfa5ce6b (plain) (blame)
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
package MooseX::ArrayRef::Meta::Role::Class;
use Moose::Role;

use List::MoreUtils qw(any);
use Data::OptList;

before superclasses => sub {
    my $self = shift;
    return if @_ == 0;

    my $supers = Data::OptList::mkopt(\@_);
    if (@$supers > 1 || any { scalar($_->meta->superclasses) > 1 } $self->linearized_isa) {
        $self->throw_error("Multiple inheritance is not supported in the inheritance hierarchy of arrayref-based instances");
    }

    my $super_meta = Class::MOP::Class->initialize($_[0]);
    if (!Moose::Util::does_role($super_meta->instance_metaclass, 'MooseX::ArrayRef::Meta::Role::Instance') && $super_meta->get_all_attributes) {
        $self->throw_error("Can't inherit from hashref-based Moose classes");
    }
};

before add_attribute => sub {
    my $self = shift;
    if ($self->subclasses) {
        $self->throw_error("Can't add attributes to a class with descendents");
    }
};

before rebless_instance => sub {
    shift->throw_error("Can't rebless arrayref-based instances");
};

before rebless_instance_back => sub {
    shift->throw_error("Can't rebless arrayref-based instances");
};

no Moose::Role;

1;