Begin working out the tutorial
[gitmo/MooseX-Role-Parameterized.git] / lib / MooseX / Role / Parameterized / Tutorial.pm
CommitLineData
93c2fd30 1package MooseX::Role::Parameterized::Tutorial;
2confess "Don't use this module, read it!";
3
4__END__
5
6=head1 NAME
7
8MooseX::Role::Parameterized::Tutorial - why and how
9
d2abd756 10=head1 ROLES
11
12Roles are composable units of behavior. See L<Moose::Cookbook::Roles::Recipe1>
13for an introduction to L<Moose::Role>.
14
93c2fd30 15=head1 MOTIVATION
16
d2abd756 17Roles are exceedingly useful. While combining roles affords you a great deal of
18flexibility, individual roles have very little in the way of configurability.
19Core Moose provides C<alias> for renaming methods to avoid conflicts, and
20C<excludes> for ignoring methods you don't want or need (see
21L<Moose::Cookbook::Roles::Recipe2> for more about C<alias> and C<excludes>).
22
23
93c2fd30 24=head1 USAGE
25
26=head3 C<with>
27
28=head3 C<parameter>
29
30=head3 C<role>
31
32=head1 IMPLEMENTATION NOTES
33
d2abd756 34=head1 USES
35
36Ideally these will become fully-explained examples in something resembling
37L<Moose::Cookbook>. But for now, only a braindump.
38
39=over 4
40
41=item Configure a role's attributes
42
43You can rename methods with core Moose, but now you can rename attributes. You
44can now also choose type, default value, whether it's required, B<traits>, etc.
45
46 parameter traits => (
47 is => 'ro',
48 isa => 'ArrayRef[Str]',
49 default => sub { [] },
50 );
51
52 has action => (
53 traits => $p->traits,
54 ...
55 );
56
57=item Inform a role of your class' attributes and methods
58
59Core roles can require only methods with specific names. Now your roles can
60require that you specify a method name you wish the role to instrument, or
61which attributes to dump to a file.
62
63 parameter instrument_method => (
64 is => 'ro',
65 isa => 'Str',
66 required => 1,
67 );
68
69 around $p->instrument_method => sub { ... };
70
71=item Arbitrary execution choices
72
73Your role may be able to provide configuration in how the role's methods
74operate. For example, you can tell the role whether to save intermediate
75states.
76
77 parameter save_intermediate => (
78 is => 'ro',
79 isa => 'Bool',
80 default => 0,
81 );
82
83 method process => sub {
84 ...
85 if ($p->save_intermediate) { ... }
86 ...
87 };
88
89=item Deciding a backend
90
91Your role may be able to freeze and thaw your instances using L<YAML>, L<JSON>,
92L<Storable>. Which backend to use can be a parameter.
93
94 parameter format => (
95 is => 'ro',
96 isa => (enum ['Storable', 'YAML', 'JSON']),
97 default => 'Storable',
98 );
99
100 if ($p->format eq 'Storable') {
101 method freeze => sub { ... };
102 method thaw => sub { ... };
103 }
104 elsif ($p->format eq 'YAML') ...
105 ...
106
107=back
108
93c2fd30 109=cut
110