Perltidy this code a bit.
[gitmo/Moose.git] / lib / Moose / Cookbook / Extending / Recipe1.pod
CommitLineData
d5e84b86 1
2=pod
3
4=head1 NAME
5
6Moose::Cookbook::Extending::Recipe1 - Providing an alternate base object class
7
8=head1 SYNOPSIS
9
10 package MyApp::Base;
11 use Moose;
12
13 extends 'Moose::Object';
14
15 before 'new' => sub { warn "Making a new " . $_[0] };
16
17 no Moose;
18
19 package MyApp::UseMyBase;
20 use Moose ();
21
22 sub import {
23 my $caller = caller();
24
25 return if $caller eq 'main';
26
27 Moose::init_meta( $caller,
28 'MyApp::Object',
29 );
30
31 Moose->import( { into => $caller }, @_ );
32 }
33
34 sub unimport {
35 my $caller = caller();
36
37 Moose->unimport( { into => $caller }, @_ );
38 }
39
40=head1 DESCRIPTION
41
42Often you find that you want to share some behavior between all your
43classes. One way to do that is to make a base class and simply add
44C<S<extends 'MyApp::Base'>> to every class in your
45application. However, that can get tedious. Instead, you can simply
46create your Moose-alike module that sets the base object class to
47C<MyApp::Base> for you.
48
49Then, instead of writing C<S<use Moose>> you can write C<S<use
50MyApp::UseMyBase>>.
51
52In this particular example, our base class issues some debugging
53output every time a new object is created, but you can surely think of
54some more interesting things to do with your own base class.
55
56=head1 AUTHOR
57
58Dave Rolsky E<lt>autarch@urth.orgE<gt>
59
60=head1 COPYRIGHT AND LICENSE
61
62Copyright 2006-2008 by Infinity Interactive, Inc.
63
64L<http://www.iinteractive.com>
65
66This library is free software; you can redistribute it and/or modify
67it under the same terms as Perl itself.
68
69=cut