Use Printable role in example of class consuming a role
[gitmo/moose-presentations.git] / moose-class / slides / index.html
index 9166a98..b193f68 100644 (file)
@@ -71,7 +71,8 @@ img#me05 {top: 43px;left: 36px;}
   <ul>
     <li><strong>Declarative</strong> OO sugar</li>
     <li>Introspectable</li>
-    <li>Extensible (MooseX::* on CPAN)</li>
+    <li>Extensible (188 MooseX::* on CPAN)</li>
+    <li>Community approved (1200+ downstream dependents on CPAN)</li>
   </ul>
 </div>
 
@@ -154,7 +155,7 @@ img#me05 {top: 43px;left: 36px;}
   <pre><code>package Person;
 use Moose;
 
-<span class="highlight">has first_name =&gt; ( is =&gt; 'rw' );</span></code></pre>
+<span class="highlight">has first_name =&gt; ( is =&gt; 'ro' );</span></code></pre>
 
 </div>
 
@@ -892,8 +893,8 @@ use Moose;</code></pre>
   <h1>BUILDARGS</h1>
 
   <ul>
-    <li>Takes <code>@_</code>, returns a hash reference of attribute name/value pairs</li>
-    <li>Accepts a hash or hashref; throws otherwise</li>
+    <li>Processes <code>new</code>'s <code>@_</code>, returns a hash reference of attribute name/value pairs</li>
+    <li>Accepts a hash or hashref; errors 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>
   </ul>
@@ -967,6 +968,7 @@ sub BUILD {
   <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>
+    <li>Moose probably provides a feature to do what you need</li>
   </ul>
 </div>
 
@@ -976,6 +978,7 @@ sub BUILD {
   <ul>
     <li>Like <code>DESTROY</code>, but Moose makes sure all <code>DEMOLISH</code> methods in a hierarchy are called</li>
     <li>Called in normal inheritance order, children to parents</li>
+    <li><em>Never</em> called by you, only by Perl itself</li>
   </ul>
 </div>
 
@@ -1039,6 +1042,7 @@ extends 'LWP';</code></pre>
   <ul>
     <li><code>override</code> is another method modifier</li>
     <li>An alternative to Perl's <code>SUPER::</code></li>
+    <li><em>Declares</em> your intent to override a method</li>
   </ul>
 </div>
 
@@ -1050,13 +1054,13 @@ use Moose;
 
 <span class="current incremental">extends 'Person';</span>
 
-<span class="incremental">override</span> work =&gt; sub {
+<span class="incremental">override</span> <span class="incremental">work</span> <span class="incremental">=&gt; sub {
     my $self = shift;
 
     die "Pay me first"
         unless $self-&gt;got_paid;
-    <span class="incremental">super();</span>
-}<span class="incremental">;</span></code></pre>
+    super();
+}</span><span class="incremental">;</span></code></pre>
 </div>
 
 <div class="slide">
@@ -1065,7 +1069,7 @@ use Moose;
   <ul>
     <li>Mostly like <code>$self-&gt;SUPER::work(@_)</code></li>
     <li><strong>But</strong> cannot change <code>@_</code>!</li>
-    <li>Binds the parent's method at compile time</li>
+    <li>Binds the parent's method <strong>correctly</strong> at compile time</li>
     <li>Parent determined by checking <code>Child-&gt;meta()-&gt;superclasses()</code></li>
   </ul>
 </div>
@@ -1232,6 +1236,8 @@ use Moose;
 
 # perl install-moose (if needed)
 
+## Read the instructions in t/01-classes.t
+
 # perl bin/prove -lv t/01-classes.t
 
 # edit lib/Person.pm and lib/Employee.pm
@@ -1303,23 +1309,23 @@ sub print {
   <pre><code>package Person;
 use Moose;
 
-with 'HasPermissions';</code></pre>
+with 'Printable';</code></pre>
 </div>
 
 <div class="slide">
   <h1>Classes Consume Roles</h1>
 
-<pre><code>my $person = Person-&gt;new(
+<pre><code>package Person;
+
+sub as_string { $_[0]-&gt;first_name() }
+
+my $person = Person-&gt;new(
     first_name   =&gt; 'Kenichi',
     last_name    =&gt; 'Asai',
     access_level =&gt; 42,
 );
 
-print $person-&gt;full_name
-    . ' has '
-    . $person-&gt;can_access(42)
-        ? 'great power'
-        : 'little power';</code></pre>
+$person-&gt;print();</code></pre>
 </div>
 
 <div class="slide">
@@ -1525,7 +1531,7 @@ use Moose;
 
 <span class="incremental">with 'HasSize';
 
-has size => ( is => 'ro' );</span></code></pre>
+has size =&gt; ( is =&gt; 'ro' );</span></code></pre>
 </div>
 
 <div class="slide">
@@ -1539,7 +1545,7 @@ requires 'size';
 package Shirt;
 use Moose;
 
-has size => ( is => 'ro' );
+has size =&gt; ( is =&gt; 'ro' );
 
 with 'HasSize';</code></pre>
 </div>
@@ -1561,9 +1567,9 @@ with 'HasSize';</code></pre>
   <pre><code>package Comparison;
 use Moose;
 
-has [ 'left', 'right' ] => (
-    is   => 'ro',
-    <span class="highlight">does => 'Comparable',</span>
+has [ 'left', 'right' ] =&gt; (
+    is   =&gt; 'ro',
+    <span class="highlight">does =&gt; 'Comparable',</span>
 );
 </code></pre>
 
@@ -1860,7 +1866,7 @@ has bank =&gt; (
 sub _build_bank {
     my $self = shift;
     return Bank-&gt;new(
-        name => 'Spire FCU' );
+        name =&gt; 'Spire FCU' );
 }</code></pre>
 </div>
 
@@ -1927,7 +1933,7 @@ has shoe_size =&gt; (
   <pre><code>has shoes =&gt; (
     is      =&gt; 'ro',
     <span class="highlight">lazy    =&gt; 1,</span>
-    builder => '_build_shoes',
+    builder =&gt; '_build_shoes',
 );
 
 sub _build_shoes {
@@ -2000,7 +2006,7 @@ has account =&gt; (
   <pre><code>package Person;
 use Moose;
 
-has shoe_size => (
+has shoe_size =&gt; (
     is       =&gt; 'ro',
     <span class="highlight">init_arg =&gt; 'foot_size',</span>
 );
@@ -2018,7 +2024,7 @@ print $person-&gt;shoe_size;</code></pre>
 <pre><code>package Person;
 use Moose;
 
-has shoes => (
+has shoes =&gt; (
     is       =&gt; 'ro',
     <span class="highlight">init_arg =&gt; undef,</span>
 );
@@ -2584,15 +2590,12 @@ Item
   <h1>Bool</h1>
 
   <h2>True</h2>
-  <pre><code>1
-924.1
-'true'
-{}</code></pre>
+  <pre><code>1</code></pre>
 
   <h2>False</h2>
   <pre><code>0
-0.0
 '0'
+''
 undef</code></pre>
 
   <ul>
@@ -3018,9 +3021,9 @@ coerce <span class="highlight">ArrayOfInt</span>
 
 use MyApp::Types qw( ArrayOfInt );
 
-has transaction_history => (
-    is  => 'rw',
-    isa => ArrayOfInt,
+has transaction_history =&gt; (
+    is  =&gt; 'rw',
+    isa =&gt; ArrayOfInt,
 );</code></pre>
 </div>
 
@@ -3204,7 +3207,7 @@ $alice-&gt;friend($bob);</code></pre>
 
 has lungs =&gt; (
     is      =&gt; 'ro',
-    isa     => 'Lungs',
+    isa     =&gt; 'Lungs',
     <span class="highlight">handles =&gt; [ 'inhale', 'exhale' ],</span>
 );</code></pre>
 
@@ -3565,7 +3568,7 @@ Iterate til this passes all its tests</pre>
 
   <ul>
     <li><strong>Not comprehensive</strong></li>
-    <li>152 MooseX distributions on CPAN as of 02/02/2010</li>
+    <li>177 MooseX distributions on CPAN as of 09/21/2010</li>
     <li>Some of them are crap</li>
   </ul>
 </div>