<h1>No Moose</h1>
<ul>
- <li><code>no Moose</code> at the end of a package is a best practice</li>
+ <li>Cleaning up is a best practice</li>
+ <li>Say <code>no Moose</code> at the end of a package</li>
<li>Or <code>use namespace::autoclean</code> at the top</li>
<li>Just do it</li>
</ul>
use Moose;
my $highlander_bank =
- Bank->new( name => 'Spire FCU' );
+ Bank->new(
+ name => 'Clan MacLeod Trust' );
has bank => (
is => 'rw',
<h1>Builder</h1>
<ul>
- <li>A method <em>name</em> which returns the default</li>
+ <li>A method <em>name</em></li>
+ <li>When called, this methods returns the default value</li>
</ul>
</div>
<li>Attributes can have a <code>default</code> or <code>builder</code></li>
<li>Attributes with a default or builder can be <code>lazy</code></li>
<li>Attributes can have a <code>clearer</code> and/or <code>predicate</code></li>
+ </ul>
+</div>
+
+<div class="slide">
+ <h1>Basic Attributes Summary</h1>
+
+ <ul>
<li>An attribute's constructor name can be changed with <code>init_arg</code></li>
<li>A subclass can alter its parents' attributes</li>
<li>Attribute accessor names can be changed</li>
<ul>
<li>Apply to an existing method</li>
- <li>... from a parent class, the current class, or a role</li>
+ <li>... that comes from a parent class, the current class, or a role</li>
<li>Roles can provide modifiers that are applied at composition time</li>
</ul>
</div>
<div class="slide">
- <h1>What is a Method Modifier</h1>
+ <h1>What Are Method Modifiers For?</h1>
<ul>
<li>"Inject" behavior</li>
<li>Add behavior to generated methods (accessors, delegations)</li>
- <li>Provide roles which modify existing behavior</li>
+ <li>Added from a role, can modify existing behavior</li>
</ul>
</div>
<ul>
<li>Inverted <code>super</code></li>
<li>From least- to most-specific</li>
+ <li>Like Mason's autohandler feature</li>
<li>Grandparent to parent to child</li>
<li>Not allowed in roles</li>
</ul>
Undef
Defined
Value
- Str
- Num
- Int
- ClassName
- RoleName
+ Str
+ Num
+ Int
+ ClassName
</pre>
</div>
CodeRef
RegexpRef
GlobRef
- FileHandle
+ FileHandle
Object
</pre>
</div>
<h1>Subtype Shortcuts - <code>class_type</code></h1>
<pre><code>use Moose::Util::TypeConstraints;
-class_type 'DateTime';
+class_type 'DateTime';</code></pre>
+
+<hr />
-subtype 'DateTime',
+<pre><code>subtype 'DateTime',
as 'Object',
where { $_->isa('DateTime') },
message { ... };</code></pre>
<h1>Subtype Shortcuts - <code>role_type</code></h1>
<pre><code>use Moose::Util::TypeConstraints;
-role_type 'Printable';
+role_type 'Printable';</coe></pre>
-subtype 'Printable',
+<hr />
+
+<pre><code>subtype 'Printable',
as 'Object',
where
{ Moose::Util::does_role(
<h1>Subtype Shortcuts - <code>duck_type</code></h1>
<pre><code>use Moose::Util::TypeConstraints;
-duck_type Car => qw( run break_down );
+duck_type Car => qw( run break_down );</code></pre>
+
+<hr />
-subtype 'Car',
+<pre><code>subtype 'Car',
as 'Object',
where { all { $_->can($_) }
qw( run break_down ) },
<h1>Subtype Shortcuts - <code>enum</code></h1>
<pre><code>use Moose::Util::TypeConstraints;
-enum Color => qw( red blue green ) );
+enum Color => qw( red blue green ) );</code></pre>
+
+<hr />
-my %ok = map { $_ => 1 }
+<pre><code>my %ok = map { $_ => 1 }
qw( red blue green );
subtype 'Color'
<ul>
<li>Type names are exported functions, catches typos early</li>
<li>Types must be pre-declared</li>
- <li>Types are stored with namespaces internally, but externally are short</li>
+ <li>Types are stored with namespaces internally, but you use short names</li>
<li>Import existing Moose types as functions from <code>MooseX::Types::Moose</code></li>
<li>Still need string names for things like <code>ArrayRef['Email::Address']</code></li>
</ul>
<li><span class="right">Catches typos at compile time</span></li>
<li><span class="right">Automatic namespacing</span></li>
<li><span class="wrong">One more thing to install and learn</span></li>
- <li><span class="wrong">Every name gets types twice (declared and then defined)</span></li>
+ <li><span class="wrong">Every name is typed twice (declared and then defined)</span></li>
<li><span class="wrong">Still stuck with strings when referring to class or role names</span></li>
<li><span class="wrong">Coercion gotcha from earlier still applies to types exported from <code>MooseX::Types::Moose</code></span></li>
</ul>
<pre><code>after salary_level => {
my $self = shift;
- return unless @_;
+ <span class="highlight">return unless @_;</span>
$self->clear_salary;
};</code></pre>
</div>
<pre><code>has salary_level => (
is => 'rw',
- trigger => sub { $_[0]->clear_salary },
+ trigger =>
+ sub { $_[0]->clear_salary },
);</code></pre>
</div>
<h1>Array Reference</h1>
<ul>
+ <li>1-to-1 mapping</li>
<li>Takes each method name and creates a simple delegation from the delegating class to the delegatee attribute</li>
</ul>
</div>
<li>Bool - <code>set</code>, <code>toggle</code>, ...</li>
<li>Hash - <code>get</code>, <code>set</code>, ...</li>
<li>Array - already saw it</li>
- <li>Code - <code>execute</code>, that's it</li>
+ <li>Code - <code>execute</code> and <code>execute_method</code></li>
</ul>
</li>
</ul>
<h1>Traits and Metaclasses</h1>
<ul>
- <li>Can add/alter/remove attribute parameter (from <code>has</code>)</li>
+ <li>Can add/alter/remove an attribute parameter (from <code>has</code>)</li>
<li>Can change behavior of created attribute</li>
</ul>
</div>
<ul>
<li><strong>Not comprehensive</strong></li>
- <li>128 MooseX distributions on CPAN as of 09/24/2009</li>
+ <li>152 MooseX distributions on CPAN as of 02/02/2010</li>
<li>Some of them are crap</li>
</ul>
</div>
has file =>
( is => 'ro', required => 1 );
has filters =>
- ( is => 'ro', isa => 'Str' );
+ ( is => 'ro', isa => 'ArrayRef[Str]' );
sub run { ... }</code></pre>
</div>
<li>mailing list - <a href="mailto:moose@perl.org">moose@perl.org</a></li>
<li>Slides and exercises are in Moose's git repo:
<br />
- <span style="white-space: nowrap">git://jules.scsys.co.uk/gitmo/moose-presentations</span></li>
+ <span style="font-size:80%; white-space: nowrap">git://jules.scsys.co.uk/gitmo/moose-presentations</span></li>
</ul>
</div>