Some small tweaks to grammar and add an inline style to make a slide fit vertically
[gitmo/moose-presentations.git] / moose-class / slides / index.html
index dc3da22..973b825 100644 (file)
@@ -56,6 +56,16 @@ img#me05 {top: 43px;left: 36px;}
 </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">
   <h1>Moose Summed Up</h1>
 
   <ul>
@@ -265,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">
@@ -832,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>
@@ -872,7 +892,7 @@ use Moose;</code></pre>
   <h1>BUILDARGS</h1>
 
   <ul>
-    <li>Takes <code>@_</code>, returns a hash reference of attribute names/value</li>
+    <li>Takes <code>@_</code>, returns a hash reference of attribute name/value pairs</li>
     <li>Accepts a hash or hashref; throws otherwise</li>
     <li>Provide your own for other cases</li>
     <li><strong>Always</strong> call <code>$class-&gt;SUPER::BUILDARGS(@_)</code> as a fallback!</li>
@@ -931,7 +951,7 @@ sub BUILD {
 
   <pre><code>Person-&gt;new(@_)</code></pre>
 
-  <ol>
+  <ol style="margin-top: 0">
     <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>
@@ -964,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;
@@ -2359,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>
@@ -2556,9 +2578,9 @@ Item
     Undef
     Defined
         Value
-           Num
-             Int
            Str
+             Num
+               Int
              ClassName
              RoleName
 </pre>
@@ -2570,6 +2592,7 @@ Item
 <pre>
 (Item)
     (Defined)
+        (Value)
         Ref
             ScalarRef
             ArrayRef[`a]
@@ -2608,6 +2631,7 @@ undef</code></pre>
   <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>
@@ -2828,7 +2852,7 @@ coerce 'My::DateTime',
     via  { [ $_ ] };</code></pre>
 
   <ul>
-    <li>Coerce instead of a union like <code style="white-space: nowrap">Int | ArrayRef[Int]</code></li>
+    <li>Instead of union - <code style="white-space: nowrap">Int | ArrayRef[Int]</code></li>
   </ul>
 </div>
 
@@ -2880,7 +2904,7 @@ sub work {
             \@_,
             tasks    =&gt;
                 { isa    =&gt; 'ArrayRef[Task]',
-                  coerce =&gt;1 },
+                  coerce =&gt; 1 },
             can_rest =&gt;
                 { isa     =&gt; 'Bool',
                   default =&gt; 0 },
@@ -3315,11 +3339,31 @@ has history =&gt; (
   <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</h1>
+  <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;
@@ -3337,23 +3381,71 @@ has _favorite_numbers =&gt; (
 </div>
 
 <div class="slide">
-  <h1>Native Delegation - Counter</h1>
+  <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);
 
-  <pre><code>package Stack;
+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 depth =&gt; (
-    traits   =&gt; [ 'Counter' ],
-    is       =&gt; 'ro',
-    isa      =&gt; 'Int',
-    default  =&gt; 0,
-    init_arg =&gt; undef,
-    <span class="highlight">handles  =&gt;
-      { _inc_depth =&gt; 'inc',
-        _dec_depth =&gt; 'dec',
-      },</span>
+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>
@@ -3461,9 +3553,200 @@ 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>