1 package MooseX::Role::Parameterized::Tutorial;
2 confess "Don't use this module, read it!";
8 MooseX::Role::Parameterized::Tutorial - why and how
12 Roles are composable units of behavior. See L<Moose::Cookbook::Roles::Recipe1>
13 for an introduction to L<Moose::Role>.
17 Roles are exceedingly useful. While combining roles affords you a great deal of
18 flexibility, individual roles have very little in the way of configurability.
19 Core Moose provides C<alias> for renaming methods to avoid conflicts, and
20 C<excludes> for ignoring methods you don't want or need (see
21 L<Moose::Cookbook::Roles::Recipe2> for more about C<alias> and C<excludes>).
32 =head1 IMPLEMENTATION NOTES
36 Ideally these will become fully-explained examples in something resembling
37 L<Moose::Cookbook>. But for now, only a braindump.
41 =item Configure a role's attributes
43 You can rename methods with core Moose, but now you can rename attributes. You
44 can now also choose type, default value, whether it's required, B<traits>, etc.
48 isa => 'ArrayRef[Str]',
49 default => sub { [] },
57 =item Inform a role of your class' attributes and methods
59 Core roles can require only methods with specific names. Now your roles can
60 require that you specify a method name you wish the role to instrument, or
61 which attributes to dump to a file.
63 parameter instrument_method => (
69 around $p->instrument_method => sub { ... };
71 =item Arbitrary execution choices
73 Your role may be able to provide configuration in how the role's methods
74 operate. For example, you can tell the role whether to save intermediate
77 parameter save_intermediate => (
83 method process => sub {
85 if ($p->save_intermediate) { ... }
89 =item Deciding a backend
91 Your role may be able to freeze and thaw your instances using L<YAML>, L<JSON>,
92 L<Storable>. Which backend to use can be a parameter.
96 isa => (enum ['Storable', 'YAML', 'JSON']),
97 default => 'Storable',
100 if ($p->format eq 'Storable') {
101 method freeze => sub { ... };
102 method thaw => sub { ... };
104 elsif ($p->format eq 'YAML') ...