<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 (1222 downstream dependents on CPAN)</li>
</ul>
</div>
<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->SUPER::BUILDARGS(@_)</code> as a fallback!</li>
</ul>
<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>
<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>
<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>
<span class="current incremental">extends 'Person';</span>
-<span class="incremental">override</span> work => sub {
+<span class="incremental">override</span> <span class="incremental">work</span> <span class="incremental">=> sub {
my $self = shift;
die "Pay me first"
unless $self->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">
my $person =
Person->new( first_name => 'Dave' );
-$person->first_name('Stevan');
-print $person->first_name; # Dave</code></pre>
+$person->first_name('Stevan'); # dies</code></pre>
</div>
# 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
</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) < 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>
<span class="incremental">with 'HasSize';
-has size => ( is => 'ro' );</span></code></pre>
+has size => ( is => 'ro' );</span></code></pre>
</div>
<div class="slide">
package Shirt;
use Moose;
-has size => ( is => 'ro' );
+has size => ( is => 'ro' );
with 'HasSize';</code></pre>
</div>
<pre><code>package Comparison;
use Moose;
-has [ 'left', 'right' ] => (
- is => 'ro',
- <span class="highlight">does => 'Comparable',</span>
+has [ 'left', 'right' ] => (
+ is => 'ro',
+ <span class="highlight">does => 'Comparable',</span>
);
</code></pre>
sub _build_bank {
my $self = shift;
return Bank->new(
- name => 'Spire FCU' );
+ name => 'Spire FCU' );
}</code></pre>
</div>
<pre><code>has shoes => (
is => 'ro',
<span class="highlight">lazy => 1,</span>
- builder => '_build_shoes',
+ builder => '_build_shoes',
);
sub _build_shoes {
<pre><code>package Person;
use Moose;
-has shoe_size => (
+has shoe_size => (
is => 'ro',
<span class="highlight">init_arg => 'foot_size',</span>
);
<pre><code>package Person;
use Moose;
-has shoes => (
+has shoes => (
is => 'ro',
<span class="highlight">init_arg => undef,</span>
);
<div class="slide">
<h1>Augment and Inner</h1>
- <pre><code>package Document;
+ <pre class="medium"><code>package Document;
sub xml { '<doc>' . <span class="highlight">inner()</span> . '</doc>' }
package Report;
extends 'Document';
<span class="highlight">augment xml</span> =>
- sub { title() . <span class="highlight">inner()</span> . summary() };
+ sub { my $self = shift;
+ $self->title() . <span class="highlight">inner()</span> . $self->summary() };
package TPSReport;
extends 'Report';
<span class="highlight">augment xml</span> =>
- sub { tps_xml() . <span class="highlight">inner()</span> };</code></pre>
+ sub { my $self = shift;
+ $self->tps_xml() . <span class="highlight">inner()</span> };</code></pre>
</div>
<div class="slide">
<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>
<h1>Subtype Shortcuts - <code>enum</code></h1>
<pre><code>use Moose::Util::TypeConstraints;
-enum Color => qw( red blue green ) );</code></pre>
+enum Color => qw( red blue green );</code></pre>
<hr />
</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;
use MyApp::Types qw( ArrayOfInt );
-has transaction_history => (
- is => 'rw',
- isa => ArrayOfInt,
+has transaction_history => (
+ is => 'rw',
+ isa => ArrayOfInt,
);</code></pre>
</div>
<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>
has lungs => (
is => 'ro',
- isa => 'Lungs',
+ isa => 'Lungs',
<span class="highlight">handles => [ 'inhale', 'exhale' ],</span>
);</code></pre>
</div>
<div class="slide">
- <h1>Questions?</h1>
-</div>
-
-<div class="slide">
<h1>Exercises</h1>
<pre># cd exercises
Iterate til this passes all its tests</pre>
</div>
+<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 7: A Brief Tour of MooseX</h1>
+ <h1>Bonus: A Brief Tour of MooseX</h1>
</div>
<div class="slide">
<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>
<h1>Questions?</h1>
</div>
-<!--
-<div class="slide fake-slide0">
- <h1>Part 8: Introspection</h1>
-</div>
+<div class="slide">
+ <h1>Moose-using Modules</h1>
-<div class="slide fake-slide0">
- <h1>Part 9: Writing Moose Extensions</h1>
-</div>
--->
+ <p>
+ For further reading, a few modules which use Moose ...
+ </p>
-<div class="slide fake-slide0">
- <h1>The End</h1>
+ <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">
</ul>
</div>
+<div class="slide fake-slide0">
+ <h1>The End</h1>
+</div>
+
</div>
</body>
</html>