Search code examples
perlmoose

Extending a Non-Moose Class: Not a HASH reference at accessor


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();

Solution

  • 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.