6 Moose::Cookbook::Extending::Recipe1 - Providing an alternate base object class
13 extends 'Moose::Object';
15 before 'new' => sub { warn "Making a new " . $_[0] };
19 package MyApp::UseMyBase;
23 my $caller = caller();
25 return if $caller eq 'main';
27 Moose::init_meta( $caller,
31 Moose->import( { into => $caller }, @_ );
35 my $caller = caller();
37 Moose->unimport( { into => $caller }, @_ );
42 Often you find that you want to share some behavior between all your
43 classes. One way to do that is to make a base class and simply add
44 C<S<extends 'MyApp::Base'>> to every class in your
45 application. However, that can get tedious. Instead, you can simply
46 create your Moose-alike module that sets the base object class to
47 C<MyApp::Base> for you.
49 Then, instead of writing C<S<use Moose>> you can write C<S<use
52 In this particular example, our base class issues some debugging
53 output every time a new object is created, but you can surely think of
54 some more interesting things to do with your own base class.
58 Dave Rolsky E<lt>autarch@urth.orgE<gt>
60 =head1 COPYRIGHT AND LICENSE
62 Copyright 2006-2008 by Infinity Interactive, Inc.
64 L<http://www.iinteractive.com>
66 This library is free software; you can redistribute it and/or modify
67 it under the same terms as Perl itself.