1 package Moose::Cookbook::Basics::DateTime_ExtendingNonMooseParent;
3 # ABSTRACT: Extending a non-Moose parent class
14 'DateTime::Calendar::Mayan' => '0',
15 'MooseX::NonMoose' => '0',
26 use DateTime::Calendar::Mayan;
27 extends qw( DateTime );
31 isa => 'DateTime::Calendar::Mayan',
34 builder => '_build_mayan_date',
35 clearer => '_clear_mayan_date',
36 predicate => 'has_mayan_date',
40 $_[0]->_clear_mayan_date;
43 sub _build_mayan_date {
44 DateTime::Calendar::Mayan->from_object( object => $_[0] );
49 This recipe demonstrates how to use Moose to subclass a parent which
50 is not Moose based. This recipe only works if the parent class uses a
51 blessed hash reference for object instances. If your parent is doing
52 something funkier, you should check out L<MooseX::NonMoose::InsideOut> and L<MooseX::InsideOut>.
54 The meat of this recipe is contained in L<MooseX::NonMoose>, which does all
55 the grunt work for you.
59 my $dt = My::DateTime->new( year => 1970, month => 2, day => 24 );
61 can_ok( $dt, 'mayan_date' );
62 isa_ok( $dt->mayan_date, 'DateTime::Calendar::Mayan' );
63 is( $dt->mayan_date->date, '12.17.16.9.19', 'got expected mayan date' );
65 $dt->set( year => 2009 );
66 ok( ! $dt->has_mayan_date, 'mayan_date is cleared after call to ->set' );