Small formatting and typo fixes
[gitmo/moose-presentations.git] / moose-class / slides / index.html
index cbbf3a1..3266122 100644 (file)
@@ -40,7 +40,7 @@ img#me05 {top: 43px;left: 36px;}
 <div id="header"></div>
 <div id="footer">
   <div id="license">
-    <a rel="license" href="http://creativecommons.org/licenses/by-sa/3.0/us/"><img alt="Creative Commons License" style="border-width:0" src="http://i.creativecommons.org/l/by-sa/3.0/us/88x31.png" /></a>
+    <a rel="license" href="http://creativecommons.org/licenses/by-sa/3.0/us/"><img alt="Creative Commons License" style="border-width:0" src="ui/creative-commons.png" /></a>
     <br /><span xmlns:dc="http://purl.org/dc/elements/1.1/" href="http://purl.org/dc/dcmitype/Text" property="dc:title" rel="dc:type">Introduction to Moose</span> by <span xmlns:cc="http://creativecommons.org/ns#" property="cc:attributionName">David Rolsky</span> is licensed under a <a rel="license" href="http://creativecommons.org/licenses/by-sa/3.0/us/">Creative Commons Attribution-Share Alike 3.0 United States License</a>.
   </div>
 
@@ -52,7 +52,17 @@ img#me05 {top: 43px;left: 36px;}
 
 <div class="slide">
   <h1>Introduction to Moose</h1>
-  <h2>YAPC 2009</h2>
+  <h2><a href="git://git.moose.perl.org/moose-presentations.git"><tt>git://git.moose.perl.org/moose-presentations.git</tt></a></h2>
+</div>
+
+<div class="slide">
+  <h1>Introduce Yourselves</h1>
+
+  <ul>
+    <li>Your name</li>
+    <li>What you do with Perl</li>
+    <li>Why you're here today (optional)</li>
+  </ul>
 </div>
 
 <div class="slide">
@@ -126,7 +136,7 @@ img#me05 {top: 43px;left: 36px;}
     <li>
       Attributes have ...
       <ul>
-        <li>Access-control (read-only vs read-write)</li>
+        <li>Mutability (read-only vs read-write)</li>
         <li>An optional type</li>
         <li>Accessor methods</li>
         <li>Delegation methods</li>
@@ -235,7 +245,10 @@ after  'foo'
     my @return =
         $self-&gt;$real_foo( @_, bar =&gt; 42 );
 
-    return ( @return, 'modify return values' );
+    return (
+        @return,
+        'modify return values'
+    );
 };</code></pre>
 </div>
 
@@ -262,7 +275,7 @@ has weight =&gt; (
 );
 
 # kaboom
-Person-&gt;new( weight =&gt; 'fat' );</code></pre>
+Person-&gt;new( weight =&gt; 'heavy' );</code></pre>
 </div>
 
 <div class="slide">
@@ -284,10 +297,10 @@ use Moose;
 has blog_uri =&gt; (
     is      =&gt; 'rw',
     isa     =&gt; 'URI',
-    <span class="highlight">handles =&gt; { 'blog_hostname' =&gt; 'host' },</span>
+    <span class="highlight">handles =&gt; { 'blog_host' =&gt; 'host' },</span>
 );
 
-<span class="highlight">$person->blog_hostname;</span>
+<span class="highlight">$person->blog_host;</span>
 # really calls $person->blog_uri->host</code></pre>
 </div>
 
@@ -341,7 +354,7 @@ has blog_uri =&gt; (
   <h1>Why Moose?</h1>
 
   <ul>
-    <li>A quick bit of propoganda ...</li>
+    <li>A quick bit of propaganda ...</li>
   </ul>
 </div>
 
@@ -829,6 +842,16 @@ has last_name =&gt; (
 );</code></pre>
 </div>
 
+<div class="slide">
+    <h1>More Why Moose?</h1>
+
+    <ul>
+      <li>Less code == fewer bugs</li>
+      <li>Moose is well-tested, test your own code, not Moose</li>
+      <li>Focus on <strong>what</strong>, not <strong>how</strong></li>
+    </ul>
+</div>
+
 <div class="slide fake-slide0">
   <h1>Part 1: Moose Classes</h1>
 </div>
@@ -885,10 +908,9 @@ use Moose;
 sub BUILDARGS {
     my $class = shift;
 
-    if ( @_ == 1 && ! ref $_[0] ) {
+    if ( @_ == 1 &amp;&amp; ! ref $_[0] ) {
         <span class="highlight">return { ssn =&gt; $_[0] };</span>
     }
-
     <span class="highlight">return $class-&gt;SUPER::BUILDARGS(@_)</span>;
 }
 
@@ -925,6 +947,30 @@ sub BUILD {
 </div>
 
 <div class="slide">
+  <h1>Object Construction a la Moose</h1>
+
+  <pre><code>Person-&gt;new(@_)</code></pre>
+
+  <ol>
+    <li>Calls <code>Person-&gt;BUILDARGS(@_)</code> to turn <code>@_</code> into a hashref</li>
+    <li>Blesses a reference</li>
+    <li>Populates attributes based on the hashref from #1</li>
+    <li>Calls <code>$new_object->BUILDALL($constructor_args)</code>
+        <br />... which calls all <code>BUILD</code> methods</li>    
+    <li>Returns the object</li>
+  </ol>
+</div>
+
+<div class="slide">
+  <h1>The Object is Opaque</h1>
+
+  <ul>
+    <li>Technically it's a hash reference</li>
+    <li><span class="wrong">If you <em>ever</em> treat it as one <strong>you are doing it wrong!</strong></span></li>
+  </ul>
+</div>
+
+<div class="slide">
   <h1>DEMOLISH</h1>
 
   <ul>
@@ -938,6 +984,8 @@ sub BUILD {
 
   <ul>
     <li><code>extends</code> is sugar for declaring parent classes</li>
+    <li>Also ensures metaclass compatibility between parent and child</li>
+    <li>Do not <code>use base</code></li>
   </ul>
 
   <pre><code>package Employee;
@@ -986,26 +1034,27 @@ extends 'LWP';</code></pre>
 </div>  
 
 <div class="slide">
-  <h1><code>overrides</code> and <code>super</code></h1>
+  <h1><code>override</code> and <code>super</code></h1>
 
   <ul>
-    <li><code>overrides</code> is another method modifier</li>
+    <li><code>override</code> is another method modifier</li>
     <li>An alternative to Perl's <code>SUPER::</code></li>
   </ul>
 </div>
 
 <div class="slide">
-  <h1><code>overrides</code> and <code>super</code></h1>
+  <h1><code>override</code> and <code>super</code></h1>
 
   <pre><code>package Employee;
 use Moose;
 
 <span class="current incremental">extends 'Person';</span>
 
-<span class="incremental">overrides</span> work =&gt; sub {
+<span class="incremental">override</span> work =&gt; sub {
     my $self = shift;
 
-    die "Pay me first" unless $self-&gt;got_paid;
+    die "Pay me first"
+        unless $self-&gt;got_paid;
     <span class="incremental">super();</span>
 }<span class="incremental">;</span></code></pre>
 </div>
@@ -1103,6 +1152,7 @@ Person->can('extends');</code></pre>
 
   <ul>
     <li><code>no Moose</code> at the end of a package is a best practice</li>
+    <li>Or <code>use namespace::autoclean</code> at the top</li>
     <li>Just do it</li>
   </ul>
 </div>
@@ -1148,7 +1198,7 @@ use Moose;
     <li><code>use Moose</code></li>
     <li><code>Class-&gt;meta</code></li>
     <li><code>Moose::Object</code> base class</li>
-    <li><code>extends</code>, <code>overrides</code>, and <code>super</code></li>
+    <li><code>extends</code>, <code>override</code>, and <code>super</code></li>
     <li>Simple attributes: <code>has</code>, <code>is&nbsp;=&gt;&nbsp;'ro'</code>, &amp; <code>is&nbsp;=&gt;&nbsp;'rw'</code></li>
     <li><code>no Moose</code></li>
     <li><code>__PACKAGE__-&gt;meta-&gt;make_immutable</code></li>
@@ -1163,12 +1213,15 @@ use Moose;
   <h1>Exercises</h1>
 
   <pre># cd exercises
-$ perl bin/prove -lv t/00-prereq.t
 
-Missing anything? Install it. (see tarballs/)
+# perl bin/prove -lv t/00-prereq.t
+
+# perl install-moose (if needed)
 
 # perl bin/prove -lv t/01-classes.t
 
+# edit lib/Person.pm and lib/Employee.pm
+
 Iterate til this passes all its tests</pre>
 </div>
 
@@ -1186,11 +1239,10 @@ Iterate til this passes all its tests</pre>
 </div>
 
 <div class="slide">
-  <h1>Roles Can Have State <strong>and</strong> Behavior</h1>
+  <h1>Roles - State <strong>and</strong> Behavior</h1>
 
   <pre><code>package HasPermissions;
 use Moose::Role;
-
 <span class="current incremental"># state
 has access_level =&gt; ( is =&gt; 'rw' );</span>
 
@@ -1199,7 +1251,8 @@ sub can_access {
     my $self     = shift;
     my $required = shift;
 
-    return $self-&gt;access_level &gt;= $required;
+    return $self-&gt;access_level
+             &gt;= $required;
 }</span></code></pre>
 
 </div>
@@ -1243,8 +1296,8 @@ with 'HasPermissions';</code></pre>
   <h1>Classes Consume Roles</h1>
 
 <pre><code>my $person = Person-&gt;new(
-    first_name => 'Kenichi',
-    last_name => 'Asai',
+    first_name   =&gt; 'Kenichi',
+    last_name    =&gt; 'Asai',
     access_level =&gt; 42,
 );
 
@@ -1300,7 +1353,7 @@ sub print {
 
 # or ...
 
-if ( Person-&gt;meta-&gt;does('Printable') ) { ... }</code></pre>
+Person-&gt;meta-&gt;does('Printable')</code></pre>
 
 </div>
 
@@ -1354,7 +1407,7 @@ use Moose;
   <h1>Conflict Resolution</h1>
 
   <ul>
-    <li>The consuming class must resolve the conflict by implementing th emethod</li>
+    <li>The consuming class must resolve the conflict by implementing the method</li>
     <li>Can use some combination of method exclusion and aliasing</li>
   </ul>
 </div>
@@ -1366,10 +1419,10 @@ use Moose;
 use Moose;
 
 <span class="highlight">with 'IsFragile' =>
-         { alias =>
+         { -alias =>
                { break => 'break_bone' } },
      'CanBreakdance' =>
-         { alias =>
+         { -alias =>
                { break => 'break_it_down' } };</span></code></pre>
 
   <ul>
@@ -1385,13 +1438,13 @@ use Moose;
 use Moose;
 
 <span class="highlight">with 'IsFragile' =>
-         { alias =>
+         { -alias =>
                { break => 'break_bone' },
-           exclude => 'break' },
+           -excludes => 'break' },
      'CanBreakdance' =>
-         { alias =>
-               { break => 'break_dance' },
-           exclude => 'break' };</span></code></pre>
+         { -alias =>
+               { break => 'break_it_down' },
+           -excludes => 'break' };</span></code></pre>
 </div>
 
 <div class="slide">
@@ -1403,7 +1456,7 @@ use Moose;
 sub break {
     my $self = shift;
 
-    $self->break_dance;
+    $self->break_it_down;
     if ( rand(1) &lt; 0.5 ) {
         $self->break_bone;
     }
@@ -1564,7 +1617,8 @@ has [ 'left', 'right' ] => (
   <pre><code>use Moose::Util qw( apply_all_roles );
 
 my $fragile_person = Person->new( ... );
-apply_all_roles( $fragile_person, 'IsFragile' );</code></pre>
+apply_all_roles( $fragile_person,
+                 'IsFragile' );</code></pre>
 
   <ul>
     <li>Does not change the <code>Person</code> class</li>
@@ -1727,7 +1781,7 @@ Person->new(); # kaboom</span></code></pre>
 
   <ul>
     <li>Attributes can have defaults</li>
-    <li>Simple non-referecne scalars (number, string)</li>
+    <li>Simple non-reference scalars (number, string)</li>
     <li>Subroutine reference</li>
     <li>A builder method</li>
   </ul>
@@ -1768,7 +1822,7 @@ has bank =&gt; (
 </div>
 
 <div class="slide">
-  <h1>Default as a Subroutine Reference</h1>
+  <h1>Subroutine Reference Default</h1>
 
   <ul>
     <li>Called as a method on the object</li>
@@ -1841,7 +1895,8 @@ has bank =&gt; (
 
 sub _build_bank {
     my $self = shift;
-    return Bank-&gt;new( name => 'Spire FCU' );
+    return Bank-&gt;new(
+        name => 'Spire FCU' );
 }</code></pre>
 </div>
 
@@ -1880,7 +1935,7 @@ has bank =&gt; (
 </div>
 
 <div class="slide">
-  <h1>Lazy, Good for Nothing Attributes</h1>
+  <h1>Lazy, Good for Nothin' Attributes</h1>
 
   <ul>
     <li>Normally, defaults are generated during object construction</li>
@@ -1914,7 +1969,7 @@ sub _build_shoes {
     my $self = shift;
 
     return Shoes-&gt;new(
-        size =&gt; <span class="highlight">$_[0]-&gt;shoe_size</span> );
+        size =&gt; <span class="highlight">$self-&gt;shoe_size</span> );
 }</code></pre>
 </div>
 
@@ -2064,8 +2119,7 @@ has '<span class="highlight">+first_name</span>' =&gt; (
 use Moose;
 
 has first_name =&gt; (
-    <span class="highlight">reader</span> =&gt; 'first_name',
-    <span class="highlight">writer</span> =&gt; 'first_name',
+    <span class="highlight">accessor</span> =&gt; 'first_name',
 );</code></pre>
 
   <ul>
@@ -2098,7 +2152,7 @@ use Moose;
 
 has first_name =&gt; (
     <span class="highlight">reader</span> =&gt; 'get_first_name',
-    <span class="highlight">writer</span> =&gt; 'set_first_name,
+    <span class="highlight">writer</span> =&gt; 'set_first_name',
 );</code></pre>
 </div>
 
@@ -2114,7 +2168,7 @@ has first_name =&gt; (
 );</code></pre>
 
   <ul>
-    <li>Can also mix-and-match</li>
+    <li>Can also mix-and-match <code>is</code> and explicit names</li>
   </ul>
 </div>
 
@@ -2165,7 +2219,8 @@ has first_name =&gt; (
   <h1>Exercises</h1>
 
   <pre># cd exercises
-# perl bin/prove -lv t/03-basic-attributes.t
+# perl bin/prove -lv \
+      t/03-basic-attributes.t
 
 Iterate til this passes all its tests</pre>
 </div>
@@ -2234,7 +2289,8 @@ before work =&gt; sub {
     my $self = shift;
     return unless $DEBUG;
 
-    warn "Called work on ", $self->full_name,
+    warn "Called work on ",
+         $self-&gt;full_name,
          "with the arguments: [@_]\n";
 };</code></pre>
 </div>    
@@ -2266,19 +2322,17 @@ after work =&gt; sub {
 </div>
 
 <div class="slide">
-  <h1>Other Uses Example</h1>
+  <h1>More Modifier Examples</h1>
 
   <pre><code>has password =&gt; (
      is      =&gt; 'rw',
      clearer =&gt; 'clear_password',
 );
-
 has hashed_password =&gt; (
      is      =&gt; 'ro',
      builder =&gt; '_build_hashed_password',
      clearer =&gt; '_clear_hashed_password',
 );
-
 after clear_password =&gt; sub {
     my $self = shift;
     $self-&gt;_clear_hashed_password;
@@ -2319,7 +2373,6 @@ after clear_password =&gt; sub {
             $self-&gt;_munge_insert(@_) );
 
     $new_user->_assign_uri;
-
     return $new_user;
 };</code></pre>
 </div>
@@ -2328,7 +2381,7 @@ after clear_password =&gt; sub {
   <h1>Modifier Order</h1>
 
   <ul>
-    <li>Before runs order from last to first</li>
+    <li>Before runs in order from last to first</li>
     <li>After runs in order from first to last</li>
     <li>Around runs in order from last to first</li>
   </ul>
@@ -2397,13 +2450,13 @@ sub xml { '&lt;doc&gt;' . <span class="highlight">inner()</span> . '&lt;/doc&gt;
 
 package Report;
 extends 'Document';
-
-<span class="highlight">augment xml</span> =&gt; { title() . <span class="highlight">inner()</span> . summary() };
+<span class="highlight">augment xml</span> =&gt;
+    sub { title() . <span class="highlight">inner()</span> . summary() };
 
 package TPSReport;
 extends 'Report';
-
-<span class="highlight">augment xml</span> =&gt; { tps_xml() . <span class="highlight">inner()</span> };</code></pre>
+<span class="highlight">augment xml</span> =&gt;
+    sub { tps_xml() . <span class="highlight">inner()</span> };</code></pre>
 </div>
 
 <div class="slide">
@@ -2482,7 +2535,8 @@ extends 'Report';
   <h1>Exercises</h1>
 
   <pre># cd exercises
-# perl bin/prove -lv t/04-method-modifiers.t
+# perl bin/prove -lv \
+      t/04-method-modifiers.t
 
 Iterate til this passes all its tests</pre>
 </div>
@@ -2491,6 +2545,538 @@ Iterate til this passes all its tests</pre>
   <h1>Part 5: Types</h1>
 </div>
 
+<div class="slide">
+  <h1>A Type System for Perl</h1>
+
+  <ul>
+    <li>Sort of ...</li>
+    <li><em>Variables</em> are not typed</li>
+    <li>Attributes can have types</li>
+    <li>MooseX modules let you define method signatures</li>
+  </ul>
+</div>
+
+<div class="slide">
+  <h1>Components of a Moose Type</h1>
+
+  <ul>
+    <li>A type is a name and a constraint</li>
+    <li>Types have a hierarchy</li>
+    <li>Constraints are cumulative from parents</li>
+    <li>Types can have associated coercions</li>
+  </ul>
+</div>
+
+<div class="slide">
+  <h1>Built-in Type Hierarchy</h1>
+
+  <pre>
+Any
+Item
+    Bool
+    Maybe[`a]
+    Undef
+    Defined
+        Value
+           Str
+             Num
+               Int
+             ClassName
+             RoleName
+</pre>
+</div>
+
+<div class="slide">
+  <h1>Built-in Type Hierarchy</h1>
+
+<pre>
+(Item)
+    (Defined)
+        (Value)
+        Ref
+            ScalarRef
+            ArrayRef[`a]
+            HashRef[`a]
+            CodeRef
+            RegexpRef
+            GlobRef
+              FileHandle
+            Object
+</pre>
+</div>
+
+<div class="slide">
+  <h1>Bool</h1>
+
+  <h2>True</h2>
+  <pre><code>1
+924.1
+'true'
+{}</code></pre>
+
+  <h2>False</h2>
+  <pre><code>0
+0.0
+'0'
+undef</code></pre>
+
+  <ul>
+    <li>Like Perl's <code>if ($foo)</code></li>
+  </ul>
+</div>
+
+<div class="slide">
+  <h1>Value (and subtypes)</h1>
+
+  <ul>
+    <li><code>Value</code> is true when <code>! ref $thing</code></li>
+    <li><code>Value</code> and <code>Str</code> are effectively the same, but <code>Str</code> is more expressive</li>
+    <li><code>Num</code> is true when a <code>$scalar</code> looks like a number</li>
+    <li>An overloaded object which numifies does not pass the <code>Num</code> constraint!</li>
+    <li>Perl 5's overloading is hopelessly broken</li>
+  </ul>
+</div>
+
+<div class="slide">
+  <h1>ClassName and RoleName</h1>
+
+  <ul>
+    <li>A string with a package name</li>
+    <li>The package <strong>must already be loaded</strong></li>
+  </ul>
+</div>
+
+<div class="slide">
+  <h1>Parameterizable Types</h1>
+
+  <ul>
+    <li>What does <code>ArrayRef[`a]</code> mean?</li>
+    <li><code>s/`a/Int/</code> (or <code>Str</code> or ...)</li>
+    <li>When you use it you can write ...
+      <ul>
+        <li><code>ArrayRef</code> (== <code>ArrayRef[Item]</code>)</li>
+        <li><code>ArrayRef[Str]</code></li>
+        <li><code>ArrayRef[MyTypeName]</code></li>
+        <li><code>ArrayRef[HashRef[Maybe[Int]]]</code></li>
+      </ul>
+    </li>
+  </ul>
+</div>
+
+<div class="slide">
+  <h1>Maybe[`a]</h1>
+
+  <ul>
+    <li>Maybe means either the named type or <code>undef</code></li>
+    <li><code>Maybe[Int]</code> accepts integers or <code>undef</code></li>
+  </ul>
+</div>
+
+<div class="slide">
+  <h1>Type Union</h1>
+
+  <ul>
+    <li>This or that (or that or ...)</li>
+    <li><code>Int | ArrayRef[Int]</code></li>
+    <li>But use a coercion instead when possible</li>
+    <li>Or use a <code>role_type</code>,  <code>duck_type</code>, or anything not a union</li>
+    <li>A union is often a code smell</li>
+  </ul>
+</div>
+
+<div class="slide">
+  <h1>Making Your Own Types</h1>
+
+  <pre><code>use Moose::Util::TypeConstraints;
+
+<span class="incremental current">subtype 'PositiveInt',</span>
+    <span class="incremental">as      'Int',</span>
+    <span class="incremental">where   { $_ &gt; 0 },</span>
+    <span class="incremental">message
+        { "The value you provided ($_)"
+          . " was not a positive int." };</span>
+
+has size =&gt; (
+    is  =&gt; 'ro',
+    <span class="incremental">isa =&gt; 'PositiveInt',</span>
+);</code></pre>
+</div>
+
+<div class="slide">
+  <h1>Automatic Types</h1>
+
+  <ul>
+    <li>Moose creates a type for every Moose class and role</li>
+    <li>Unknown names are assumed to be classes</li>
+  </ul>
+</div>
+
+<div class="slide">
+  <h1>Automatic Types</h1>
+
+  <pre><code>package Employee;
+use Moose;
+
+has manager =&gt; (
+    is  =&gt; 'rw',
+    <span class="highlight">isa =&gt; 'Employee',</span>
+);
+
+has start_date =&gt; (
+    is  =&gt; 'ro',
+    <span class="highlight">isa =&gt; 'DateTime',</span>
+);</code></pre>
+</div>
+
+<div class="slide">
+  <h1>Subtype Shortcuts - <code>class_type</code></h1>
+
+  <pre><code>use Moose::Util::TypeConstraints;
+class_type 'DateTime';
+
+subtype 'DateTime',
+    as      'Object',
+    where   { $_-&gt;isa('DateTime') },
+    message { ... };</code></pre>
+</div>
+
+<div class="slide">
+  <h1>Subtype Shortcuts - <code>role_type</code></h1>
+
+  <pre><code>use Moose::Util::TypeConstraints;
+role_type 'Printable';
+
+subtype 'Printable',
+    as      'Object',
+    where
+        { Moose::Util::does_role(
+              $_, 'Printable' ) },
+    message { ... };</code></pre>
+</div>
+
+<div class="slide">
+  <h1>Subtype Shortcuts - <code>duck_type</code></h1>
+
+  <pre><code>use Moose::Util::TypeConstraints;
+duck_type Car =&gt; qw( run break_down );
+
+subtype 'Car',
+    as      'Object',
+    where   { all { $_-&gt;can($_) }
+              qw( run break_down ) },
+    message { ... };</code></pre>
+</div>
+
+<div class="slide">
+  <h1>Subtype Shortcuts - <code>enum</code></h1>
+
+  <pre><code>use Moose::Util::TypeConstraints;
+enum Color =&gt; qw( red blue green ) );
+
+my %ok = map { $_ =&gt; 1 }
+             qw( red blue green );
+
+subtype 'Color'
+    as      'Str',
+    where   { $ok{$_} },
+    message { ... };</code></pre>
+</div>
+
+<div class="slide">
+  <h1>Anonymous Subtypes</h1>
+
+  <pre><code>package Person;
+
+<span class="highlight">my $posint =
+    subtype as 'Int', where { $_ &gt; 0 };</span>
+
+has size =&gt; (
+    is  =&gt; 'ro',
+    <span class="highlight">isa =&gt; $posint,</span>
+);</code></pre>
+
+  <ul>
+    <li>Shortcuts have anonymous forms as well</li>
+  </ul>
+</div>
+
+<div class="slide">
+  <h1>Coercions</h1>
+
+  <pre><code>use Moose::Util::TypeConstraints;
+
+subtype 'UCStr',
+    as    'Str',
+    where { ! /[a-z]/ };</code></pre>
+</div>
+
+<div class="slide">
+  <h1>Coercions</h1>
+
+  <pre><code><span class="incremental current">coerce 'UCStr',</span>
+    <span class="incremental">from 'Str',</span>
+    <span class="incremental">via  { uc };</span>
+
+has shouty_name =&gt; (
+    is     =&gt; 'ro',
+    isa    =&gt; 'UCStr',
+    <span class="incremental">coerce =&gt; 1,</span>
+);</code></pre>
+</div>
+
+<div class="slide">
+  <h1>Coercion Examples</h1>
+
+  <pre><code>subtype 'My::DateTime',
+    as class_type 'DateTime';
+
+coerce 'My::DateTime',
+    from 'HashRef',
+    via  { DateTime-&gt;new( %{$_} ) };
+
+coerce 'My::DateTime',
+    from 'Int',
+    via  { DateTime-&gt;from_epoch(
+               epoch =&gt; $_ ) };</code></pre>
+
+  <ul>
+    <li>Use coercion to inflate a value</li>
+  </ul>
+</div>
+
+<div class="slide">
+  <h1>Coercion Examples</h1>
+
+  <pre><code>coerce 'ArrayRef[Int]',
+    from 'Int',
+    via  { [ $_ ] };</code></pre>
+
+  <ul>
+    <li>Instead of union - <code style="white-space: nowrap">Int | ArrayRef[Int]</code></li>
+  </ul>
+</div>
+
+<div class="slide">
+  <h1>Using Types with Attributes</h1>
+
+  <pre><code>package Person;
+
+has height =&gt; (
+    is  =&gt; 'rw',
+    <span class="highlight">isa =&gt; 'Num',</span>
+);
+
+has favorite_numbers =&gt; (
+    is     =&gt; 'rw',
+    <span class="highlight">isa    =&gt; 'ArrayRef[Int]',
+    coerce =&gt; 1,</span>
+);</code></pre>
+</div>
+
+<div class="slide">
+  <h1>More Droppings</h1>
+
+  <ul>
+    <li><code>Moose::Util::TypeConstraints</code> also needs cleanup</li>
+  </ul>
+
+  <pre><code>package Person;
+
+use Moose;
+use Moose::Util::TypeConstraints;
+
+subtype ...;
+
+no Moose;
+<span class="highlight">no Moose::Util::TypeConstraints;</span></code></pre>
+</div>
+
+<div class="slide">
+  <h1>Typed Methods (Low-tech)</h1>
+
+  <pre class="medium"><code>package Person;
+<span class="highlight">use MooseX::Params::Validate qw( validated_list );</span>
+
+sub work {
+    my $self = shift;
+    <span class="highlight">my ( $tasks, $can_rest ) =
+        validated_list(
+            \@_,
+            tasks    =&gt;
+                { isa    =&gt; 'ArrayRef[Task]',
+                  coerce =&gt; 1 },
+            can_rest =&gt;
+                { isa     =&gt; 'Bool',
+                  default =&gt; 0 },
+        );</span>
+    ...
+}</code></pre>
+</div>
+
+<div class="slide">
+  <h1>Typed Methods (High-tech)</h1>
+
+  <pre class="medium"><code>package Person;
+
+<span class="highlight">use MooseX::Method::Signatures;</span>
+
+<span class="highlight">method work ( ArrayRef[Task] :$tasks,
+                        Bool :$can_rest = 0 )</span> {
+    my $self = shift;
+
+    ...
+}</code></pre>
+</div>
+
+<div class="slide">
+  <h1>Digression: The Type Registry</h1>
+
+  <ul>
+    <li>Types are actually <code>Moose::Meta::TypeConstraints</code> <em>objects</em></li>
+    <li>Stored in an interpreter-global registry mapping names to objects</li>
+  </ul>
+</div>
+
+<div class="slide">
+  <h1>Danger!</h1>
+
+  <ul>
+    <li>Coercions are attached to type objects</li>
+    <li>Therefore also global</li>
+    <li>Name conflicts between modules!</li>
+    <li>Coercion conflicts between modules!</li>
+  </ul>
+</div>
+
+<div class="slide">
+  <h1>Namespace Fix</h1>
+
+  <ul>
+    <li>Use some sort of pseudo-namespacing scheme</li>
+    <li>Never coerce directly to a class name, or <em>to</em> built-in types</li>
+  </ul>
+</div>
+
+<div class="slide">
+  <h1>Namespace Fix</h1>
+
+  <pre><code>use Moose::Util::TypeConstraints;
+subtype <span class="highlight">'MyApp::Type::DateTime',</span>
+    as 'DateTime';
+
+<span class="highlight">coerce 'MyApp::Type::DateTime',</span>
+    from 'HashRef',
+    via  { DateTime-&gt;new( %{$_} ) }
+
+has creation_date =&gt; (
+    is     =&gt; 'ro',
+    <span class="highlight">isa    =&gt; 'MyApp::Type::DateTime',</span>
+    coerce =&gt; 1,
+);</code></pre>
+</div>
+
+<div class="slide">
+  <h1>Namespace Fix</h1>
+
+  <pre><code>subtype 'MyApp::Type::ArrayOfInt',
+    as 'ArrayRef[Int]';
+
+coerce 'MyApp::Type::ArrayOfInt',
+    from 'Int',
+    via  { [ $_ ] };</code></pre>
+</div>
+
+<div class="slide">
+  <h1>Namespace Fix Pros and Cons</h1>
+
+  <ul>
+    <li><span class="right">Relatively simple</span></li>
+    <li><span class="right">Already built into Moose</span></li>
+    <li><span class="wrong">Conflates type and module namespaces</span></li>
+    <li><span class="wrong">Type names are strings, so typos are easy to make and may be hard to find</span></li>
+  </ul>
+</div>
+
+<div class="slide">
+  <h1>MooseX::Types</h1>
+
+  <pre><code>package MyApp::Types;
+
+use MooseX::Types
+    <span class="highlight">-declare =&gt; [ qw( ArrayOfInt ) ]</span>;
+use MooseX::Types::Moose
+    qw( ArrayRef Int );
+
+subtype <span class="highlight">ArrayOfInt</span>,
+    as ArrayRef[Int];
+
+coerce <span class="highlight">ArrayOfInt</span>
+    from Int,
+    via  { [ $_ ] };</code></pre>
+</div>
+
+<div class="slide">
+  <h1>MooseX::Types</h1>
+
+  <pre><code>package MyApp::Account;
+
+use MyApp::Types qw( ArrayOfInt );
+
+has transaction_history => (
+    is  => 'rw',
+    isa => ArrayOfInt,
+);</code></pre>
+</div>
+
+<div class="slide">
+  <h1>MooseX::Types</h1>
+
+  <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>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>
+</div>
+
+<div class="slide">
+  <h1>MooseX::Types Pros and Cons</h1>
+
+  <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">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>
+</div>
+
+<div class="slide">
+  <h1>Recommendation</h1>
+
+  <ul>
+    <li>Use <code>MooseX::Types</code></li>
+    <li>Compile time error catching and automatic namespacing are huge wins</li>
+    <li>Docs from <code>Moose::Util::TypeConstraints</code> are 98% compatible with <code>MooseX::Types</code> anyway</li>
+    <li>A function exported by a type library works wherever a type name would</li>
+  </ul>
+</div>
+
+<div class="slide">
+  <h1>Questions?</h1>
+</div>  
+
+<div class="slide">
+  <h1>Exercises</h1>
+
+  <pre># cd exercises
+# perl bin/prove -lv t/05-types.t
+
+Iterate til this passes all its tests</pre>
+</div>
+
 <div class="slide fake-slide0">
   <h1>Part 6: Advanced Attributes</h1>
 </div>
@@ -2554,7 +3140,8 @@ $alice-&gt;friend($bob);</code></pre>
 use Moose;
 
 has name   =&gt; ( is =&gt; 'ro' );
-has friend =&gt; ( is =&gt; 'rw', <span class="highlight">weak_ref =&gt; 1</span> );
+has friend =&gt; ( is       =&gt; 'rw',
+                <span class="highlight">weak_ref =&gt; 1</span> );
 
 my $alice = Person-&gt;new( name =&gt; 'Alice' );
 my $bob   = Person-&gt;new( name =&gt; 'Bob' );
@@ -2673,7 +3260,6 @@ has lungs =&gt; (
 
   <pre><code>package Person;
 use Moose;
-
 has account =&gt; (
     is      =&gt; 'ro',
     isa     =&gt; 'BankAccount',
@@ -2721,7 +3307,6 @@ has name =&gt; (
 
   <pre><code>package Auditor;
 use Moose::Role;
-
 sub record_change  { ... }
 sub change_history { ... }
 
@@ -2749,6 +3334,120 @@ has history =&gt; (
 </div>
 
 <div class="slide">
+  <h1>Native Delegation</h1>
+
+  <ul>
+    <li>Delegate to <em>unblessed</em> Perl types</li>
+    <li>Scalar, array or hash ref, etc</li>
+    <li>Treat Perl types as objects</li>
+    <li>Still uses <code>handles</code></li>
+    <li>Pretend that native Perl types have methods</li>
+  </ul>
+</div>
+
+<div class="slide">
+  <h1>Native Delegation - Array(Ref)</h1>
+
+  <ul>
+    <li>Methods include:
+      <ul>
+        <li><code>push</code></li>
+        <li><code>shift</code></li>
+        <li><code>elements</code> - returns all elements</li>
+        <li><code>count</code></li>
+        <li><code>is_empty</code></li>
+        <li>quite a few more</li>
+      </ul>
+    </li>
+  </ul>
+</div>
+
+<div class="slide">
+  <h1>Native Delegation - Array(Ref)</h1>
+
+  <pre><code>package Person;
+use Moose;
+has _favorite_numbers =&gt; (
+    traits   =&gt; [ 'Array' ],
+    is       =&gt; 'ro',
+    isa      =&gt; 'ArrayRef[Int]',
+    default  =&gt; sub { [] },
+    init_arg =&gt; undef,
+    <span class="highlight">handles  =&gt;
+      { favorite_numbers    =&gt; 'elements',
+        add_favorite_number =&gt; 'push',
+      },</span>
+);</code></pre>
+</div>
+
+<div class="slide">
+  <h1>Native Delegation - Array(Ref)</h1>
+
+  <pre><code>my $person = Person-&gt;new();
+
+$person-&gt;add_favorite_number(7);
+$person-&gt;add_favorite_number(42);
+
+print "$_\n"
+    for $person-&gt;favorite_numbers;
+
+# 7
+# 42</code></pre>
+</div>
+
+<div class="slide">
+  <h1>Native Delegation</h1>
+
+  <ul>
+    <li>Native types are ...
+      <ul>
+        <li>Number - <code>add</code>, <code>mul</code>, ...</li>
+        <li>String - <code>append</code>, <code>chop</code>, ...</li>
+        <li>Counter - <code>inc</code>, <code>dec</code>, ...</li>
+        <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>
+      </ul>
+    </li>
+  </ul>
+</div>
+
+<div class="slide">
+  <h1>Curried Delegation</h1>
+
+  <ul>
+    <li>A delegation with some preset arguments</li>
+    <li>Works with object or Native delegation</li>
+  </ul>
+</div>
+
+<div class="slide">
+  <h1>Curried Delegation</h1>
+
+  <pre><code>package Person;
+use Moose;
+has account =&gt; (
+    is      =&gt; 'ro',
+    isa     =&gt; 'BankAccount',
+    handles =&gt; {
+        receive_100 =&gt;
+            <span class="highlight">[ 'deposit', 100 ]</span>
+        give_100    =&gt;
+            <span class="highlight">[ 'withdraw', 100 ]</span>
+    },
+);</code></pre>
+</div>
+
+<div class="slide">
+  <h1>Curried Delegation</h1>
+
+  <pre><code>$person-&gt;receive_100;
+# really is
+$person-&gt;account-&gt;deposit(100);</code></pre>
+</div>
+
+<div class="slide">
   <h1>Traits and Metaclasses</h1>
 
   <ul>
@@ -2791,7 +3490,6 @@ has ssn =&gt; (
     isa    =&gt; 'Str',
     <span class="highlight">label  =&gt; 'Social Security Number',</span>
 );
-
 print <span class="highlight">Person-&gt;meta
             -&gt;get_attribute('ssn')-&gt;label;</span></code></pre>
 </div>
@@ -2810,7 +3508,6 @@ has ssn =&gt; (
     isa       =&gt; 'Str',
     <span class="highlight">label     =&gt; 'Social Security Number',</span>
 );
-
 print <span class="highlight">Person-&gt;meta
             -&gt;get_attribute('ssn')-&gt;label;</span></code></pre>
 </div>
@@ -2845,7 +3542,8 @@ print <span class="highlight">Person-&gt;meta
   <h1>Exercises</h1>
 
   <pre># cd exercises
-# perl bin/prove -lv t/06-advanced-attributes.t
+# perl bin/prove -lv \
+      t/06-advanced-attributes.t
 
 Iterate til this passes all its tests</pre>
 </div>
@@ -2855,13 +3553,222 @@ Iterate til this passes all its tests</pre>
 </div>
 
 <div class="slide fake-slide0">
-  <h1>Part 8: A Tour of MooseX</h1>
+  <h1>Part 8: A Brief Tour of MooseX</h1>
+</div>
+
+<div class="slide">
+  <h1>Notable MX Modules on CPAN</h1>
+
+  <ul>
+    <li><strong>Not comprehensive</strong></li>
+    <li>128 MooseX distributions on CPAN as of 09/24/2009</li>
+    <li>Some of them are crap</li>
+  </ul>
+</div>
+
+<div class="slide">
+  <h1>Already Mentioned Several</h1>
+
+  <ul>
+    <li><code>MooseX::NonMoose</code> - best solution for subclassing non-Moose parents</li>
+    <li><code>MooseX::Declare</code> - <em>real</em> Perl 5 OO</li>
+    <li><code>MooseX::FollowPBP</code> and <code>MooseX::SemiAffordanceAccessor</code></li>
+    <li><code>MooseX::Params::Validate</code> and <code>MooseX::Method::Signatures</code></li>
+    <li><code>MooseX::Types</code></li>
+  </ul>
+</div>    
+
+<div class="slide">
+  <h1>MooseX::Declare</h1>
+
+<pre><code>use MooseX::Declare;
+use 5.10.0; # for say
+
+class Person {
+    has greeting =&gt;
+        ( is =&gt; 'ro', isa =&gt; 'Str' );
+
+    method speak {
+        say $self-&gt;greeting;
+    }
+}</code></pre>
+</div>
+
+<div class="slide">
+  <h1>MooseX::Declare</h1>
+
+  <ul>
+    <li>Still experimental-ish, but seeing more and more use</li>
+    <li><strong>Not</strong> a source filter!</li>
+    <li>Hooks into the Perl parser rather than filtering all your code</li>
+    <li>But not supported by <code>PPI</code>, <code>perltidy</code>, etc.</li> (yet?)
+  </ul>
+</div>
+
+<div class="slide">
+  <h1>MooseX::StrictConstructor</h1>
+
+  <ul>
+    <li>By default, unknown constructor arguments are ignored</li>
+    <li>MX::StrictConstructor turns these into an error</li>
+  </ul>
+</div>
+
+<div class="slide">
+  <h1>MooseX::StrictConstructor</h1>
+
+  <pre><code>package Person;
+
+use Moose;
+<span class="highlight">use MooseX::StrictConstructor;</span>
+
+has name =&gt; ( is =&gt; 'ro' );
+
+Person-&gt;new
+    ( na<span class="wrong">n</span>e =&gt; 'Ringo Shiina' ); # kaboom</code></pre>
+</div>
+
+<div class="slide">
+  <h1>MooseX::Traits</h1>
+
+  <ul>
+    <li>Combines object construction and role application</li>
+    <li>Makes it easy to create one-off customized objects</li>
+  </ul>
+</div>
+
+<div class="slide">
+  <h1>MooseX::Traits</h1>
+
+  <pre><code>package MyApp::Thingy;
+use Moose;
+
+<span class="highlight">with 'MooseX::Traits';</span>
+
+my $thing =
+    MyApp::Thingy-&gt;<span class="highlight">new_with_traits</span>
+        ( <span class="highlight">traits =&gt; [ 'Foo', 'Bar' ],</span>
+          size   =&gt; 42 );</code></pre>
+</div>
+
+<div class="slide">
+  <h1>MooseX::Getopt</h1>
+
+  <ul>
+    <li>Makes command-line interface programs easy!</li>
+    <li>Construct an object from CLI arguments</li>
+  </ul>
+</div>
+
+<div class="slide">
+  <h1>MooseX::Getopt</h1>
+
+  <pre><code>package App::CLI;
+use Moose;
+
+<span class="highlight">with 'MooseX::Getopt';</span>
+
+has file    =&gt;
+    ( is =&gt; 'ro', required =&gt; 1 );
+has filters =&gt;
+    ( is =&gt; 'ro', isa =&gt; 'Str' );
+
+sub run { ... }</code></pre>
+</div>
+
+<div class="slide">
+  <h1>MooseX::Getopt</h1>
+
+  <ul>
+    <li>Then call it like this:</li>
+  </ul>
+
+<pre><code>#!/usr/bin/perl
+
+use App::CLI;
+
+<span class="highlight">App::CLI->new_with_options()</span>->run();</code></pre>
+
+<pre>$ myapp-cli \
+   --file foo \
+   --filters compress \
+   --filters sanitize</pre>
+</div>
+
+<div class="slide">
+  <h1>MooseX::Clone</h1>
+
+  <pre><code>package Person;
+
+use Moose;
+<span class="highlight">with 'MooseX::Clone';</span>
+
+my $person = Person-&gt;new;
+my $clone  = <span class="highlight">$person-&gt;clone;</span></code></pre>
+</div>
+
+<div class="slide">
+  <h1>MooseX::NonMoose</h1>
+
+  <ul>
+    <li>Highly recommended for subclassing non-Moose parents</li>
+    <li>Gets all the little annoying details right</li>
+  </ul>
+</div>
+
+<div class="slide">
+  <h1>MooseX::Role::Parameterized</h1>
+
+  <pre><code>package HasCollection;
+<span class="current incremental">use MooseX::Role::Parameterized;</span>
+<span class="incremental">parameter type =&gt; ( isa     =&gt; 'Str',
+                    default =&gt; 'Item' );</span>
+<span class="incremental">role {
+    my $p = shift;
+
+    my $type =
+        'ArrayRef[' . $p-&gt;type() . ']';
+    has collection =&gt;
+        ( is  =&gt; 'ro',
+          isa =&gt; $type );
+};</span></code></pre>
+</div>
+
+<div class="slide">
+  <h1>MooseX::Role::Parameterized</h1>
+
+  <pre><code>package Person;
+
+use Moose;
+with HasCollection =&gt; { type =&gt; 'Int' };</code></pre>
 </div>
 
+<div class="slide">
+  <h1>Questions?</h1>
+</div>  
+
 <div class="slide fake-slide0">
   <h1>Part 9: Writing Moose Extensions</h1>
 </div>
 
+<div class="slide fake-slide0">
+  <h1>The End</h1>
+</div>
+
+<div class="slide">
+  <h1>More Information</h1>
+
+  <ul>
+    <li><a href="http://moose.perl.org/">http://moose.perl.org/</a></li>
+    <li><a href="http://search.cpan.org/dist/Moose/lib/Moose/Manual.pod">Moose::Manual</a> and <a href="http://search.cpan.org/dist/Moose/lib/Moose/Cookbook.pod">Moose::Cookbook</a></li>
+    <li><a href="irc://irc.perl.org/#moose">irc://irc.perl.org/#moose</a></li>
+    <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>
+  </ul>
+</div>
+
 </div> 
 </body>
 </html>