</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>
<ul>
<li>Moose creates <code>new()</code> for you</li>
- <li>Provide an optional <code>BUIDARGS()</code> and <code>BUILD()</code></li>
+ <li>Provide an optional <code>BUILDARGS()</code> and <code>BUILD()</code></li>
</ul>
</div>
<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;
# perl bin/prove -lv t/01-classes.t
+# edit lib/Person.pm and lib/Employee.pm
+
Iterate til this passes all its tests</pre>
</div>
-excludes => 'break' },
'CanBreakdance' =>
{ -alias =>
- { break => 'break_dance' },
+ { break => 'break_it_down' },
-excludes => 'break' };</span></code></pre>
</div>
sub break {
my $self = shift;
- $self->break_dance;
+ $self->break_it_down;
if ( rand(1) < 0.5 ) {
$self->break_bone;
}
<ul>
<li>Attributes can have defaults</li>
- <li>Simple non-referecne scalars (number, string)</li>
+ <li>Simple non-reference scalars (number, string)</li>
<li>Subroutine reference</li>
<li>A builder method</li>
</ul>
<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>
<pre>
(Item)
(Defined)
+ (Value)
Ref
ScalarRef
ArrayRef[`a]
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>
<h1>More Droppings</h1>
<ul>
- <li><code>Moose::Util::TypeConstraint</code> also needs cleanup</li>
+ <li><code>Moose::Util::TypeConstraints</code> also needs cleanup</li>
</ul>
<pre><code>package Person;
\@_,
tasks =>
{ isa => 'ArrayRef[Task]',
- coerce =>1 },
+ coerce => 1 },
can_rest =>
{ isa => 'Bool',
default => 0 },
<h1>Digression: The Type Registry</h1>
<ul>
- <li>Types are actually <code>Moose::Meta::TypeConstraint</code> <em>objects</em></li>
+ <li>Types are actually <code>Moose::Meta::TypeConstraints</code> <em>objects</em></li>
<li>Stored in an interpreter-global registry mapping names to objects</li>
</ul>
</div>
<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;
</div>
<div class="slide">
- <h1>Native Delegation - Counter</h1>
+ <h1>Native Delegation - Array(Ref)</h1>
+
+ <pre><code>my $person = Person->new();
+
+$person->add_favorite_number(7);
+$person->add_favorite_number(42);
+
+print "$_\n"
+ for $person->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 Stack;
+ <pre><code>package Person;
use Moose;
-has depth => (
- traits => [ 'Counter' ],
- is => 'ro',
- isa => 'Int',
- default => 0,
- init_arg => undef,
- <span class="highlight">handles =>
- { _inc_depth => 'inc',
- _dec_depth => 'dec',
- },</span>
+has account => (
+ is => 'ro',
+ isa => 'BankAccount',
+ handles => {
+ receive_100 =>
+ <span class="highlight">[ 'deposit', 100 ]</span>
+ give_100 =>
+ <span class="highlight">[ 'withdraw', 100 ]</span>
+ },</span>
);</code></pre>
</div>
-
<div class="slide">
<h1>Traits and Metaclasses</h1>