1 package Moose::Cookbook::Basics::Recipe11;
3 # ABSTRACT: Extending a non-Moose base class
14 'DateTime::Calendar::Mayan' => '0',
15 'MooseX::NonMoose' => '0',
26 extends qw( DateTime );
30 isa => 'DateTime::Calendar::Mayan',
33 builder => '_build_mayan_date',
34 clearer => '_clear_mayan_date',
35 predicate => 'has_mayan_date',
41 my $obj = $class->SUPER::new(@_);
43 return $class->meta->new_object(
50 $_[0]->_clear_mayan_date;
53 sub _build_mayan_date {
54 DateTime::Calendar::Mayan->from_object( object => $_[0] );
59 This recipe demonstrates how to use Moose to subclass a parent which
60 is not Moose based. This recipe only works if the parent class uses a
61 blessed hash reference for object instances. If your parent is doing
62 something funkier, you should check out L<MooseX::NonMoose::InsideOut> and L<MooseX::InsideOut>.
64 The meat of this recipe is contained in L<MooseX::NonMoose>, which does all
65 the grunt work for you.
69 my $dt = My::DateTime->new( year => 1970, month => 2, day => 24 );
71 can_ok( $dt, 'mayan_date' );
72 isa_ok( $dt->mayan_date, 'DateTime::Calendar::Mayan' );
73 is( $dt->mayan_date->date, '12.17.16.9.19', 'got expected mayan date' );
75 $dt->set( year => 2009 );
76 ok( ! $dt->has_mayan_date, 'mayan_date is cleared after call to ->set' );