We don't call DEMOLISH, Perl does
[gitmo/moose-presentations.git] / moose-class / slides / index.html
index 672f055..63baef5 100644 (file)
@@ -52,7 +52,7 @@ img#me05 {top: 43px;left: 36px;}
 
 <div class="slide">
   <h1>Introduction to Moose</h1>
-  <h2><a href="git://git.moose.perl.org/moose-presentations.git"><tt>git://git.moose.perl.org/moose-presentations.git</tt></a></h2>
+  <h2>Dave Rolsky</a>
 </div>
 
 <div class="slide">
@@ -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 (177 MooseX::* on CPAN)</li>
+    <li>Community approved (1222 downstream dependents on CPAN)</li>
   </ul>
 </div>
 
@@ -218,7 +219,7 @@ use Moose;
   <ul>
     <li>AKA advice</li>
     <li>&quot;<strong>Before</strong> foo(), do this first&quot;</li>
-    <li>&quot;Do this <strong>after</strong> foo()</li>
+    <li>&quot;Do this <strong>after</strong> foo()&quot;</li>
     <li>&quot;Put this code <strong>around</strong> foo()&quot;</li>
   </ul>
 </div>
@@ -300,8 +301,8 @@ has blog_uri =&gt; (
     <span class="highlight">handles =&gt; { 'blog_host' =&gt; 'host' },</span>
 );
 
-<span class="highlight">$person->blog_host;</span>
-# really calls $person->blog_uri->host</code></pre>
+<span class="highlight">$person-&gt;blog_host;</span>
+# really calls $person-&gt;blog_uri-&gt;host</code></pre>
 </div>
 
 <div class="slide">
@@ -955,7 +956,7 @@ sub BUILD {
     <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>
+    <li>Calls <code>$new_object-&gt;BUILDALL($constructor_args)</code>
         <br />... which calls all <code>BUILD</code> methods</li>    
     <li>Returns the object</li>
   </ol>
@@ -976,6 +977,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 +1041,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>
 
@@ -1107,8 +1110,7 @@ has first_name =&gt; ( <span class="highlight">is =&gt; 'ro'</span> );
 my $person =
     Person-&gt;new( first_name =&gt; 'Dave' );
 
-$person-&gt;first_name('Stevan');
-print $person-&gt;first_name; # Dave</code></pre>
+$person-&gt;first_name('Stevan'); # dies</code></pre>
 
 </div>
 
@@ -1127,7 +1129,7 @@ print $person-&gt;first_name; # Dave</code></pre>
 use Moose;
 
 # true
-Person->can('extends');</code></pre>
+Person-&gt;can('extends');</code></pre>
 
   <ul>
     <li>Not very hygienic</li>
@@ -1142,10 +1144,23 @@ use Moose;
 
 ...
 
-no Moose;
+<span class="highlight">no Moose;</span>
 
 # false
-Person->can('extends');</code></pre>
+Person-&gt;can('extends');</code></pre>
+</div>
+
+<div class="slide">
+  <h1>Cleaning Up Moose Droppings</h1>
+
+  <pre><code>package Person;
+<span class="highlight">use namespace::autoclean;</span>
+use Moose;
+
+...
+
+# false
+Person-&gt;can('extends');</code></pre>
 </div>
 
 <div class="slide">
@@ -1163,13 +1178,13 @@ Person->can('extends');</code></pre>
   <h1>Immutability</h1>
 
   <ul>
-    <li><span style="font-family: URW Chancery L; font-size: 140%">Stevan's Incantation of Fleet-Footedness</span></li>
+    <li><span style="font-family: URW Chancery L; font-size: 120%">Stevan's Incantation of Fleet-Footedness</span></li>
   </ul>
 
   <pre><code>package Person;
 use Moose;
 
-<span class="highlight">__PACKAGE__->meta->make_immutable;</span></code></pre>
+<span class="highlight">__PACKAGE__-&gt;meta-&gt;make_immutable;</span></code></pre>
 </div>
 
 <div class="slide">
@@ -1355,7 +1370,7 @@ sub print {
 
 # or ...
 
-Person-&gt;meta-&gt;does('Printable')</code></pre>
+Person-&gt;meta-&gt;does_role('Printable')</code></pre>
 
 </div>
 
@@ -1415,69 +1430,17 @@ use Moose;
 </div>
 
 <div class="slide">
-  <h1>Method Aliasing</h1>
-
-  <pre><code>package FragileDancer;
-use Moose;
-
-<span class="highlight">with 'IsFragile' =>
-         { -alias =>
-               { break => 'break_bone' } },
-     'CanBreakdance' =>
-         { -alias =>
-               { break => 'break_it_down' } };</span></code></pre>
-
-  <ul>
-    <li>Renames the roles' methods</li>
-    <li>Still conflicts, need to <code>exclude</code> as well</li>
-  </ul>
-</div>
-
-<div class="slide">
-  <h1>Method Exclusion</h1>
-
-  <pre><code>package FragileDancer;
-use Moose;
-
-<span class="highlight">with 'IsFragile' =>
-         { -alias =>
-               { break => 'break_bone' },
-           -excludes => 'break' },
-     'CanBreakdance' =>
-         { -alias =>
-               { break => 'break_it_down' },
-           -excludes => 'break' };</span></code></pre>
-</div>
-
-<div class="slide">
-  <h1>And then ...</h1>
-
-  <pre><code>package FragileDancer;
-use Moose;
-
-sub break {
-    my $self = shift;
-
-    $self->break_it_down;
-    if ( rand(1) &lt; 0.5 ) {
-        $self->break_bone;
-    }
-}</code></pre>
-</div>
-
-<div class="slide">
-  <h1>Still Full of Fail</h1>
+  <h1>Conflicts Are a Smell</h1>
 
   <ul>
-    <li>Roles are also about semantics!</li>
-    <li>We've fulfilled the letter and lost the spirit</li>
+    <li>Roles are about semantics!</li>
     <li>Roles have a <em>meaning</em></li>
-    <li>Think twice before blindly aliasing and excluding methods!</li>
+    <li>Method name conflicts smell like bad design</li>
   </ul>
 </div>
 
 <div class="slide">
-  <h1>Hot Role-on-Role Action</h1>
+  <h1>Roles With Roles</h1>
 
   <pre><code>package Comparable;
 use Moose::Role;
@@ -1486,7 +1449,7 @@ requires 'compare';</code></pre>
 </div>
 
 <div class="slide">
-  <h1>Hot Role-on-Role Action</h1>
+  <h1>Roles With Roles</h1>
 
   <pre><code>package TestsEquality;
 use Moose::Role;
@@ -1495,7 +1458,7 @@ with 'Comparable';
 
 sub is_equal {
     my $self = shift;
-    return $self->compare(@_) == 0;
+    return $self-&gt;compare(@_) == 0;
 }</code></pre>
 </div>
 
@@ -1510,8 +1473,8 @@ with 'TestsEquality';
 # Satisfies the Comparable role
 sub compare { ... }
 
-Integer->does('TestsEquality'); # true
-Integer->does('Comparable'); # also true!</code></pre>
+Integer-&gt;does('TestsEquality'); # true
+Integer-&gt;does('Comparable'); # also true!</code></pre>
 </div>
 
 <div class="slide">
@@ -1533,11 +1496,11 @@ with 'HasSubProcess';
 <div class="slide">
   <h1>Delayed Conflict</h1>
 
-  <pre><code>package StateOfTexas;
+  <pre><code>package SysadminAssassin;
 with 'Killer';</code></pre>
 
   <ul>
-    <li><code>StateOfTexas</code> must implement its own <code>execute</code></li>
+    <li><code>SysadminAssassin</code> must implement its own <code>execute</code></li>
     <li>But loading the <code>Killer</code> role by itself does not cause an error</li>
   </ul>
 </div>
@@ -1618,7 +1581,7 @@ has [ 'left', 'right' ] => (
 
   <pre><code>use Moose::Util qw( apply_all_roles );
 
-my $fragile_person = Person->new( ... );
+my $fragile_person = Person-&gt;new( ... );
 apply_all_roles( $fragile_person,
                  'IsFragile' );</code></pre>
 
@@ -1774,8 +1737,8 @@ has first_name =&gt; (
     <span class="current incremental">required =&gt; 1,</span>
 );
 
-<span class="incremental">Person->new( first_name =&gt; undef ); # ok
-Person->new(); # kaboom</span></code></pre>
+<span class="incremental">Person-&gt;new( first_name =&gt; undef ); # ok
+Person-&gt;new(); # kaboom</span></code></pre>
 </div>
 
 <div class="slide">
@@ -1957,7 +1920,7 @@ use Moose;
 
 has shoe_size =&gt; (
     is       =&gt; 'ro',
-    required =&gt; 'ro',
+    required =&gt; 1,
 );</code></pre>
 </div>
 
@@ -2045,11 +2008,11 @@ has shoe_size => (
     <span class="highlight">init_arg =&gt; 'foot_size',</span>
 );
 
-Person->new( <span class="wrong">shoe_size =&gt; 13</span> );
+Person-&gt;new( <span class="wrong">shoe_size =&gt; 13</span> );
 
 my $person =
-    Person->new( <span class="right">foot_size =&gt; 13</span> );
-print $person->shoe_size;</code></pre>
+    Person-&gt;new( <span class="right">foot_size =&gt; 13</span> );
+print $person-&gt;shoe_size;</code></pre>
 </div>
 
 <div class="slide">
@@ -2063,7 +2026,7 @@ has shoes => (
     <span class="highlight">init_arg =&gt; undef,</span>
 );
 
-Person->new( <span class="wrong">shoes =&gt; Shoes-&gt;new</span> );</code></pre>
+Person-&gt;new( <span class="wrong">shoes =&gt; Shoes-&gt;new</span> );</code></pre>
 </div>
 
 <div class="slide">
@@ -2384,7 +2347,7 @@ after clear_password =&gt; sub {
         $self-&gt;$orig(
             $self-&gt;_munge_insert(@_) );
 
-    $new_user->_assign_uri;
+    $new_user-&gt;_assign_uri;
     return $new_user;
 };</code></pre>
 </div>
@@ -2457,19 +2420,21 @@ around run</span> =&gt; sub {
 <div class="slide">
   <h1>Augment and Inner</h1>
 
-  <pre><code>package Document;
+  <pre class="medium"><code>package Document;
 
 sub xml { '&lt;doc&gt;' . <span class="highlight">inner()</span> . '&lt;/doc&gt;' }
 
 package Report;
 extends 'Document';
 <span class="highlight">augment xml</span> =&gt;
-    sub { title() . <span class="highlight">inner()</span> . summary() };
+    sub { my $self = shift;
+          $self-&gt;title() . <span class="highlight">inner()</span> . $self-&gt;summary() };
 
 package TPSReport;
 extends 'Report';
 <span class="highlight">augment xml</span> =&gt;
-    sub { tps_xml() . <span class="highlight">inner()</span> };</code></pre>
+    sub { my $self = shift;
+          $self-&gt;tps_xml() . <span class="highlight">inner()</span> };</code></pre>
 </div>
 
 <div class="slide">
@@ -2595,6 +2560,7 @@ Item
                 Num
                     Int
                 ClassName
+                RoleName
 </pre>
 </div>
 
@@ -2748,7 +2714,7 @@ class_type 'DateTime';</code></pre>
 
 <hr />
 
-<pre><code>subtype 'DateTime',
+<pre><code>subtype     'DateTime',
     as      'Object',
     where   { $_-&gt;isa('DateTime') },
     message { ... };</code></pre>
@@ -2763,7 +2729,7 @@ role_type 'Printable';</coe></pre>
 <hr />
 
 <pre><code>subtype 'Printable',
-    as      'Object',
+    as  'Object',
     where
         { Moose::Util::does_role(
               $_, 'Printable' ) },
@@ -2789,14 +2755,14 @@ duck_type Car =&gt; qw( run break_down );</code></pre>
   <h1>Subtype Shortcuts - <code>enum</code></h1>
 
   <pre><code>use Moose::Util::TypeConstraints;
-enum Color =&gt; qw( red blue green ) );</code></pre>
+enum Color =&gt; qw( red blue green );</code></pre>
 
 <hr />
 
 <pre><code>my %ok = map { $_ =&gt; 1 }
              qw( red blue green );
 
-subtype 'Color'
+subtype     'Color'
     as      'Str',
     where   { $ok{$_} },
     message { ... };</code></pre>
@@ -2912,6 +2878,19 @@ no Moose;
 </div>
 
 <div class="slide">
+  <h1>Questions So Far?</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">
   <h1>Typed Methods (Low-tech)</h1>
 
   <pre class="medium"><code>package Person;
@@ -3088,15 +3067,6 @@ has transaction_history => (
   <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>
@@ -3401,7 +3371,7 @@ has history =&gt; (
 use Moose;
 has _favorite_numbers =&gt; (
     traits   =&gt; [ 'Array' ],
-    is       =&gt; 'ro',
+    is       =&gt; 'bare',
     isa      =&gt; 'ArrayRef[Int]',
     default  =&gt; sub { [] },
     init_arg =&gt; undef,
@@ -3562,15 +3532,12 @@ print <span class="highlight">Person-&gt;meta
     <li>Use <code>weak_ref</code> to avoid circular references</li>
     <li>Use trigger to do an action post-attribute write</li>
     <li>Use delegations to hide "internal" objects</li>
+    <li>Use native delegations to treat Perl types as objects</li>
     <li>Traits and metaclasses let you extend Moose's core attribute features</li>
   </ul>
 </div>
 
 <div class="slide">
-  <h1>Questions?</h1>
-</div>  
-
-<div class="slide">
   <h1>Exercises</h1>
 
   <pre># cd exercises
@@ -3580,12 +3547,20 @@ print <span class="highlight">Person-&gt;meta
 Iterate til this passes all its tests</pre>
 </div>
 
-<div class="slide fake-slide0">
-  <h1>Part 7: Introspection</h1>
+<div class="slide">
+  <h1>CYOA</h1>
+
+  <p>
+    If there is time, keep going ...
+  </p>
+
+  <p>
+    Otherwise, jump to slide 269 ...
+  </p>
 </div>
 
 <div class="slide fake-slide0">
-  <h1>Part 8: A Brief Tour of MooseX</h1>
+  <h1>Bonus: A Brief Tour of MooseX</h1>
 </div>
 
 <div class="slide">
@@ -3719,7 +3694,7 @@ sub run { ... }</code></pre>
 
 use App::CLI;
 
-<span class="highlight">App::CLI->new_with_options()</span>->run();</code></pre>
+<span class="highlight">App::CLI-&gt;new_with_options()</span>-&gt;run();</code></pre>
 
 <pre>$ myapp-cli \
    --file foo \
@@ -3779,12 +3754,21 @@ with HasCollection =&gt; { type =&gt; 'Int' };</code></pre>
   <h1>Questions?</h1>
 </div>  
 
-<div class="slide fake-slide0">
-  <h1>Part 9: Writing Moose Extensions</h1>
-</div>
+<div class="slide">
+  <h1>Moose-using Modules</h1>
 
-<div class="slide fake-slide0">
-  <h1>The End</h1>
+  <p>
+    For further reading, a few modules which use Moose ...
+  </p>
+
+  <ul>
+    <li><a href="http://search.cpan.org/dist/Catalyst-Runtime">Catalyst</a></li>
+    <li><a href="http://search.cpan.org/dist/CHI">CHI</a></li>
+    <li><a href="http://search.cpan.org/dist/Devel-REPL">Devel::REPL</a></li>
+    <li><a href="http://search.cpan.org/dist/Email-Sender">Email::Sender</a></li>
+    <li><a href="http://search.cpan.org/dist/Fey">Fey</a></li>
+    <li><a href="http://search.cpan.org/dist/Net-Twitter">Net::Twitter</a></li>
+  </ul>
 </div>
 
 <div class="slide">
@@ -3801,6 +3785,10 @@ with HasCollection =&gt; { type =&gt; 'Int' };</code></pre>
   </ul>
 </div>
 
+<div class="slide fake-slide0">
+  <h1>The End</h1>
+</div>
+
 </div> 
 </body>
 </html>