tidy code in pod for consistency
[gitmo/Moose.git] / lib / Moose / Cookbook / Extending / Recipe2.pod
CommitLineData
f3ce0579 1
2=pod
3
4=head1 NAME
5
6Moose::Cookbook::Extending::Recipe2 - Providing a role for the base object class
7
8=head1 SYNOPSIS
9
10 package MooseX::Debugging;
11
12 use strict;
13 use warnings;
14
15 use Moose::Exporter;
16 use Moose::Util::MetaRole;
17 use MooseX::Debugging::Role::Object;
18
19 Moose::Exporter->setup_import_methods();
20
21 sub init_meta {
22 shift;
23 my %options = @_;
24
25 Moose::Util::MetaRole::apply_base_object_roles(
26 for_class => $options{for_class},
27 role => ['MooseX::Debugging::Role::Object'],
28 );
29 }
30
f3ce0579 31 package MooseX::Debugging::Role::Object;
32
33 after 'BUILD' => sub {
34 my $self = shift;
35
36 warn "Made a new " . ref $self . " object\n";
6a7e3999 37 };
f3ce0579 38
39=head1 DESCRIPTION
40
41In this example, we provide a role for the base object class that adds
42some simple debugging output. Every time an object is created, it
43spits out a warning saying what type of object it was.
44
45Obviously, a real debugging role would do something more interesting,
46but this recipe is all about how we apply that role.
47
48In this case, with the combination of L<Moose::Exporter> and
49L<Moose::Util::MetaRole>, we ensure that when a module does "S<use
50MooseX::Debugging>", it automatically gets the debugging role applied
51to its base object class.
52
53=head1 AUTHOR
54
55Dave Rolsky E<lt>autarch@urth.orgE<gt>
56
57=head1 COPYRIGHT AND LICENSE
58
59Copyright 2008 by Infinity Interactive, Inc.
60
61L<http://www.iinteractive.com>
62
63This library is free software; you can redistribute it and/or modify
64it under the same terms as Perl itself.
65
66=cut
67