<ul>
<li><code>Moose.pm</code> provides declarative sugar</li>
+ <li>Turns on <code>strict</code> and <code>warnings</code></li>
<li>Creates metaclasses for your class: <code>Person->meta</code></li>
<li>Moose classes automatically inherit from <code>Moose::Object</code></li>
</ul>
<h2 class="wrong">WRONG</h2>
- <pre><code>package BadEmployee;
+ <pre><code>package EvilEmployee;
use Moose;
extends 'Person';
extends 'Thief';</pre></code>
<h2 class="right">RIGHT</h2>
- <pre><code>package BadEmployee;
+ <pre><code>package EvilEmployee;
use Moose;
extends 'Person', 'Thief';</pre></code>
</div>
</div>
<div class="slide">
+ <h1><code>overrides</code> and <code>super</code></h1>
+
+ <ul>
+ <li><code>overrides</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>
+
+ <pre><code>package Employee;
+use Moose;
+
+<span class="incremental current">extends 'Person';</span>
+
+<span class="incremental">overrides</span> work => sub {
+ my $self = shift;
+
+ die "Pay me first" unless $self->got_paid;
+ <span class="incremental">super();</span>
+}<span class="incremental">;</span></code></pre>
+
+<div class="slide">
+ <h1>Caveat <code>super</code></h1>
+
+ <ul>
+ <li>Mostly like <code>$self->SUPER::work(@_)</code></li>
+ <li><strong>But</strong> cannot change <code>@_</code>!</li>
+ <li>Binds the parent's method at compile time</li>
+ </ul>
+</div>
+
+<div class="slide">
+ <h1>Attributes (Part 1)</h1>
+
+ <ul>
+ <li><code>has 'foo'</code></li>
+ <li>Use <code>is => 'ro'</code> or <code>is => 'rw'</code></li>
+ <li>Attributes without "is" have no accessors</li>
+ </ul>
+</div>
+
+<div class="slide">
+ <h1>Read-write attributes</h1>
+
+ <pre><code>package Person;
+use Moose;
+
+has 'first_name' => ( <span class="highlight">is => 'rw'</span> );
+
+my $person =
+ Person->new( first_name => 'Dave' );
+
+$person->first_name('Stevan');
+print $person->first_name; # Stevan</code></pre>
+
+</div>
+
+<div class="slide">
+ <h1>Read-only attributes</h1>
+
+ <pre><code>package Person;
+use Moose;
+
+has 'first_name' => ( <span class="highlight">is => 'ro'</span> );
+
+my $person =
+ Person->new( first_name => 'Dave' );
+
+$person->first_name('Stevan');
+print $person->first_name; # Dave</code></pre>
+
+</div>
+
+<div class="slide">
+ <h1>There is More to Come</h1>
+
+ <ul>
+ <li>Attributes have a <em>lot</em> of features</li>
+ </ul>
+</div>
+
+<div class="slide">
<h1>Cleaning Up Moose Droppings</h1>
<pre><code>package Person;
<span class="highlight">__PACKAGE__->meta->make_immutable;</span></code></pre>
</div>
+<div class="slide">
+ <h1>What <code>make_immutable</code> does</h1>
+
+ <ul>
+ <li>Magic</li>
+ <li>Uses <code>eval</code> to "inline" a constructor</li>
+ <li>Memoizes a lot of meta-information</li>
+ <li>Makes loading your class slower</li>
+ <li>Makes object creation <em>much</em> faster</li>
+ </ul>
+</div>
+
+<div class="slide">
+ <h1>When to Immutabilize?</h1>
+
+ <ul>
+ <li><em>Almost</em> always</li>
+ <li>Startup time vs execution time</li>
+ </ul>
+</div>
+
</body>
</html>