summaryrefslogtreecommitdiffstats
path: root/lib/MooseX/NonMoose/Meta/Role/Constructor.pm
blob: cf7083cbaa5697359832685223648066b3ec34b8 (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
package MooseX::NonMoose::Meta::Role::Constructor;
use Moose::Role;

around can_be_inlined => sub {
    my $orig = shift;
    my $self = shift;

    my $meta = $self->associated_metaclass;
    my $super_new = $meta->find_method_by_name($self->name);
    my $super_meta = $super_new->associated_metaclass;
    if (Class::MOP::class_of($super_meta)->can('does_role')
     && Class::MOP::class_of($super_meta)->does_role('MooseX::NonMoose::Meta::Role::Class')) {
        return 1;
    }

    return $self->$orig(@_);
};

sub _generate_instance {
    my $self = shift;
    my ($var, $class_var) = @_;
    my $new = $self->name;
    my $super_new_class = $self->associated_metaclass->find_next_method_by_name($new)->package_name;
    # XXX: this should probably be taking something from the meta-instance api,
    # rather than calling bless directly, but this works fine for now, and i
    # want to wait for the whole immutablization stuff to settle down before
    # digging too deeply into it
    "my $var = bless $super_new_class->$new(\@_), $class_var;\n";
}

no Moose::Role;

1;