<h1>Why Moose?</h1>
<ul>
- <li>A quick bit of propoganda ...</li>
+ <li>A quick bit of propaganda ...</li>
</ul>
</div>
</div>
<div class="slide">
+ <h1>BUILDARGS</h1>
+
+ <ul>
+ <li>Takes <code>@_</code>, returns a hash reference of attribute names/value</li>
+ <li>Accepts a hash or hashref; throws 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>
+</div>
+
+<div class="slide">
+ <h1>BUILDARGS Example</h1>
+
+ <pre><code>package Person;
+use Moose;
+
+sub BUILDARGS {
+ my $class = shift;
+
+ if ( @_ == 1 && ! ref $_[0] ) {
+ <span class="highlight">return { ssn => $_[0] };</span>
+ }
+
+ <span class="highlight">return $class->SUPER::BUILDARGS(@_)</span>;
+}
+
+<span class="highlight">Person->new('123-45-6789')</span></code></pre>
+</div>
+
+<div class="slide">
+ <h1>BUILD</h1>
+
+ <ul>
+ <li>Called after object is created, before <code>new</code> returns</li>
+ <li>Chance to do more complex validation, set complex attributes</li>
+ <li>Called in reverse inheritance order, parents to children</li>
+ <li>Return value is ignored</li>
+ </ul>
+</div>
+
+<div class="slide">
+ <h1>BUILD Example</h1>
+
+ <pre><code>package Person;
+use Moose;
+
+sub BUILD {
+ my $self = shift;
+
+ if ( $self->country_of_residence
+ eq 'USA' ) {
+ die 'All US residents'
+ . ' must have an SSN'
+ unless $self->has_ssn;
+ }
+}</code></pre>
+</div>
+
+<div class="slide">
+ <h1>Object Construction a la Moose</h1>
+
+ <pre><code>Person->new(@_)</code></pre>
+
+ <ol>
+ <li>Calls <code>Person->BUILDARGS(@_)</code> to turn <code>@_</code> into a hashref</li>
+ <li>Blesses a reference</li>
+ <li>Populates attributes based on the hashref from #1</li>
+ <li>Calls <code>$new_object->BUILDALL($constructor_args)</code>
+ <br />... which calls all <code>BUILD</code> methods</li>
+ <li>Returns the object</li>
+ </ol>
+</div>
+
+<div class="slide">
+ <h1>The Object is Oqaque</h1>
+
+ <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>
+ </ul>
+</div>
+
+<div class="slide">
+ <h1>DEMOLISH</h1>
+
+ <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>
+ </ul>
+</div>
+
+<div class="slide">
<h1>extends</h1>
<ul>
</div>
<div class="slide">
- <h1><code>overrides</code> and <code>super</code></h1>
+ <h1><code>override</code> and <code>super</code></h1>
<ul>
- <li><code>overrides</code> is another method modifier</li>
+ <li><code>override</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>
+ <h1><code>override</code> and <code>super</code></h1>
<pre><code>package Employee;
use Moose;
<span class="current incremental">extends 'Person';</span>
-<span class="incremental">overrides</span> work => sub {
+<span class="incremental">override</span> work => sub {
my $self = shift;
die "Pay me first" unless $self->got_paid;
<li><code>use Moose</code></li>
<li><code>Class->meta</code></li>
<li><code>Moose::Object</code> base class</li>
- <li><code>extends</code>, <code>overrides</code>, and <code>super</code></li>
+ <li><code>extends</code>, <code>override</code>, and <code>super</code></li>
<li>Simple attributes: <code>has</code>, <code>is => 'ro'</code>, & <code>is => 'rw'</code></li>
<li><code>no Moose</code></li>
<li><code>__PACKAGE__->meta->make_immutable</code></li>
<h1>Conflict Resolution</h1>
<ul>
- <li>The consuming class must resolve the conflict by implementing th emethod</li>
+ <li>The consuming class must resolve the conflict by implementing the method</li>
<li>Can use some combination of method exclusion and aliasing</li>
</ul>
</div>
my $self = shift;
return Shoes->new(
- size => <span class="highlight">$_[0]->shoe_size</span> );
+ size => <span class="highlight">$self->shoe_size</span> );
}</code></pre>
</div>
use Moose;
has first_name => (
- <span class="highlight">reader</span> => 'first_name',
- <span class="highlight">writer</span> => 'first_name',
+ <span class="highlight">accessor</span> => 'first_name',
);</code></pre>
<ul>
has first_name => (
<span class="highlight">reader</span> => 'get_first_name',
- <span class="highlight">writer</span> => 'set_first_name,
+ <span class="highlight">writer</span> => 'set_first_name',
);</code></pre>
</div>
);</code></pre>
<ul>
- <li>Can also mix-and-match</li>
+ <li>Can also mix-and-match <code>is</code> and explicit names</li>
</ul>
</div>
package Report;
extends 'Document';
-<span class="highlight">augment xml</span> => { title() . <span class="highlight">inner()</span> . summary() };
+<span class="highlight">augment xml</span> =>
+ sub { title() . <span class="highlight">inner()</span> . summary() };
package TPSReport;
extends 'Report';
-<span class="highlight">augment xml</span> => { tps_xml() . <span class="highlight">inner()</span> };</code></pre>
+<span class="highlight">augment xml</span> =>
+ sub { tps_xml() . <span class="highlight">inner()</span> };</code></pre>
</div>
<div class="slide">
<h1>Part 9: Writing Moose Extensions</h1>
</div>
+<div class="slide fake-slide0">
+ <h1>The End</h1>
+</div>
+
+<div class="slide">
+ <h1>More Information</h1>
+
+ <ul>
+ <li><a href="http://moose.perl.org/">http://moose.perl.org/</a></li>
+ <li><a href="http://search.cpan.org/dist/Moose/lib/Moose/Manual.pod">Moose::Manual</a> and <a href="http://search.cpan.org/dist/Moose/lib/Moose/Cookbook.pod">Moose::Cookbook</a></li>
+ <li><a href="irc://irc.perl.org/#moose">irc://irc.perl.org/#moose</a></li>
+ <li>mailing list - <a href="mailto:moose@perl.org">moose@perl.org</a></li>
+ <li>Slides and exercises are in Moose's git repo:
+ <br />
+ <span style="white-space: nowrap">git://jules.scsys.co.uk/gitmo/moose-presentations</span></li>
+ </ul>
+</div>
+
</div>
</body>
</html>