<ul>
<li><strong>Declarative</strong> OO sugar</li>
<li>Introspectable</li>
- <li>Extensible (177 MooseX::* on CPAN)</li>
- <li>Community approved (1222 downstream dependents on CPAN)</li>
+ <li>Extensible (188 MooseX::* on CPAN)</li>
+ <li>Community approved (1200+ downstream dependents on CPAN)</li>
</ul>
</div>
<pre><code>package Person;
use Moose;
-<span class="highlight">has first_name => ( is => 'rw' );</span></code></pre>
+<span class="highlight">has first_name => ( is => 'ro' );</span></code></pre>
</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>
<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">
<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>
+ <li>Binds the parent's method <strong>correctly</strong> at compile time</li>
<li>Parent determined by checking <code>Child->meta()->superclasses()</code></li>
</ul>
</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
<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->new(
+<pre><code>package Person;
+
+sub as_string { $_[0]->first_name() }
+
+...
+
+my $person = Person->new(
first_name => 'Kenichi',
last_name => 'Asai',
access_level => 42,
);
-print $person->full_name
- . ' has '
- . $person->can_access(42)
- ? 'great power'
- : 'little power';</code></pre>
+$person->print();</code></pre>
</div>
<div class="slide">
<pre><code>package Person;
use Moose;
-<span class="highlight">with 'Printable';</span></code></pre>
+<span class="highlight">with 'Printable';</span>
+
+sub as_string { $_[0]->first_name() }</code></pre>
</div>
<div class="slide">
<span class="delete">with 'Printable';</span>
+sub as_string { $_[0]->first_name() }
+
<span class="highlight">has has_been_printed => ( is => 'rw' );
sub print {
<h1>Real Examples</h1>
<ul>
- <li>Column and ColumnAlias both <em>do</em> ColumnLike</li>
- <li>ColumnLike things can be used in certain parts of queries</li>
<li>All queries <em>do</em> HasWhereClause</li>
<li>Select <em>does</em> Comparable and Selectable (for subselects)</li>
<li>A where clause requires its components to <em>do</em> Comparable</li>
<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>
<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>