<div class="slide">
<h1>Introduction to Moose</h1>
- <h2>Dave Rolsky</a>
+ <h2>Dave Rolsky</h2>
</div>
<div class="slide">
<li><strong>Declarative</strong> OO sugar</li>
<li>Introspectable</li>
<li>Extensible (188 MooseX::* on CPAN)</li>
- <li>Community approved (1222 downstream dependents on CPAN)</li>
+ <li>Community approved (1200+ downstream dependents on CPAN)</li>
</ul>
</div>
<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>
<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>
has bank => (
is => 'rw',
+ # THIS WILL NOT WORK
<span class="wrong">default => Bank->new(
name => 'Spire FCU' ),</span>
);</code></pre>
</div>
<div class="slide">
- <h1>What if I Want to Share?</h1>
-
- <pre><code>package Person;
-use Moose;
-
-my $highlander_bank =
- Bank->new(
- name => 'Clan MacLeod Trust' );
-
-has bank => (
- is => 'rw',
- default => sub { $highlander_bank },
-);</code></pre>
-</div>
-
-<div class="slide">
<h1>Builder</h1>
<ul>
<ul>
<li>By default, subclasses inherit attribute as-is</li>
- <li>Can change some attribute parameters in subclasses
- <ul>
- <li>default</li>
- <li>builder</li>
- <li>required</li>
- <li>lazy</li>
- <li>others we've not yet covered</li>
- </ul>
- </li>
+ <li>Can change attribute parameters in subclasses</li>
</ul>
</div>
</div>
<div class="slide">
- <h1>Augment and Inner</h1>
-
- <ul>
- <li>Inverted <code>super</code></li>
- <li>From least- to most-specific</li>
- <li>Like Mason's autohandler feature</li>
- <li>Grandparent to parent to child</li>
- <li>Not allowed in roles</li>
- </ul>
-</div>
-
-<div class="slide">
- <h1>Augment and Inner</h1>
-
- <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 { my $self = shift;
- $self->title() . <span class="highlight">inner()</span> . $self->summary() };
-
-package TPSReport;
-extends 'Report';
-<span class="highlight">augment xml</span> =>
- sub { my $self = shift;
- $self->tps_xml() . <span class="highlight">inner()</span> };</code></pre>
-</div>
-
-<div class="slide">
- <h1>Augment and Inner</h1>
-
- <ul>
- <li>When we call <code>$tps->xml</code> ...
- <ul>
- <li><code>Document->xml</code></li>
- <li><code>Report->xml</code></li>
- <li><code>TPSReport->xml</code></li>
- </ul>
- </li>
- </ul>
-</div>
-
-<div class="slide">
- <h1>Augment and Inner Usage</h1>
-
- <ul>
- <li>Call <code>inner()</code> to "fill in the blank"</li>
- <li>Requires designing for subclassing</li>
- <li>Call <code>inner()</code> in the terminal class, just in case</li>
- </ul>
-</div>
-
-<div class="slide">
<h1>Method Modifiers Summary</h1>
<ul>
<li>alter parameters passed to the original method</li>
<li>alter the return value of the original method</li>
<li>not call the original method at all (or call a <em>different</em> method)</li>
+ <li>When using modifiers in a role, require the modified method</li>
</ul>
</li>
</ul>
</div>
<div class="slide">
- <h1>Method Modifiers Summary</h1>
-
- <ul>
- <li>When using modifiers in a role, require the modified method</li>
- <li>Use <code>augment</code> and <code>inner</code> to invert the normal subclassing flow ...
- <ul>
- <li>Least- to most-specific (parents to children)</li>
- <li>Build in "insertability" (stick more stuff in the "middle")</li>
- </ul>
- </li>
- <li>Always call <code>inner</code> in the most specific subclass to allow for future extension</li>
- </ul>
-</div>
-
-<div class="slide">
<h1>Questions?</h1>
</div>
<h1>Subtype Shortcuts - <code>role_type</code></h1>
<pre><code>use Moose::Util::TypeConstraints;
-role_type 'Printable';</coe></pre>
+role_type 'Printable';</code></pre>
<hr />
isa => 'BankAccount',
handles => {
receive_100 =>
- <span class="highlight">[ 'deposit', 100 ]</span>
+ <span class="highlight">[ 'deposit', 100 ]</span>,
give_100 =>
<span class="highlight">[ 'withdraw', 100 ]</span>
},
<ul>
<li><strong>Not comprehensive</strong></li>
- <li>177 MooseX distributions on CPAN as of 09/21/2010</li>
+ <li>188 MooseX distributions on CPAN as of 02/03/2011</li>
<li>Some of them are crap</li>
</ul>
</div>
<h1>MooseX::Declare</h1>
<pre><code>use MooseX::Declare;
-use 5.10.0; # for say
+use 5.12.0; # for say
class Person {
has greeting =>
<li>Still experimental-ish, but seeing more and more use</li>
<li><strong>Not</strong> a source filter!</li>
<li>Hooks into the Perl parser rather than filtering all your code</li>
- <li>But not supported by <code>PPI</code>, <code>perltidy</code>, etc.</li> (yet?)
+ <li>But not supported by <code>PPI</code>, <code>perltidy</code>, etc. (yet?)</li>
</ul>
</div>