Convert a Moose Object into a Subtype

Date: 03 June 2011

Categories: Moose, perl

Have you ever had the situation where you had a parent class but you find out later in the code that you really want a subclass? With perl Moose, it’s really easy to do. Consider the classic point example described in Moose::Cookbook::Basics::Recipe1. Suppose I start with a Point but I decide later that I need that point to shift into 3D. I don’t want to change the values for x and y, I just want to add the new z point.