Reputation: 1711
I'm Trying to extend a non-moose class, and when I call an accessor defined by moose for my extended class I'm getting the following error:
Not a HASH reference at accessor MyGraph::weight (defined at MyGraph.pm line 8) line 8
This is the simplified code:
package MyGraph;
use Moose;
use MooseX::NonMoose;
extends 'Graph';
has 'weight' => (
is => 'ro',
isa => 'Num',
);
no Moose;
__PACKAGE__->meta->make_immutable;
package main;
my $g = MyGraph->new;
$g->weight();
Upvotes: 2
Views: 373
Reputation: 1384
I've never done this but this looks like it might be what you want. http://metacpan.org/pod/MooseX::NonMoose
Upvotes: -1
Reputation: 2520
The reference that the non-Moose class uses as its instance type must match the instance type that Moose is using. Moose's default instance type is a hashref.
Graph
uses ARRAYREF
as its instance type. MooseX::InsideOut
is the solution.
package MyGraph;
use Moose;
use MooseX::InsideOut;
use MooseX::NonMoose;
extends 'Graph';
Upvotes: 2
Reputation: 239980
MooseX::NonMoose doesn't, out of the box, enable you to subclass a non-hashref class, and Graph uses an arrayref for its instances. The docs mention this, and suggest using MooseX::InsideOut to enable compatibility with non-moose classes that have other instance types.
Upvotes: 3