<div class="slide">
<h1>Introduction to Moose</h1>
- <h2><a href="git://git.moose.perl.org/moose-presentations.git"><tt>git://git.moose.perl.org/moose-presentations.git</tt></a></h2>
+ <h2>Dave Rolsky</a>
</div>
<div class="slide">
<ul>
<li>AKA advice</li>
<li>"<strong>Before</strong> foo(), do this first"</li>
- <li>"Do this <strong>after</strong> foo()</li>
+ <li>"Do this <strong>after</strong> foo()"</li>
<li>"Put this code <strong>around</strong> foo()"</li>
</ul>
</div>
<span class="highlight">handles => { 'blog_host' => 'host' },</span>
);
-<span class="highlight">$person->blog_host;</span>
-# really calls $person->blog_uri->host</code></pre>
+<span class="highlight">$person->blog_host;</span>
+# really calls $person->blog_uri->host</code></pre>
</div>
<div class="slide">
<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>
+ <li>Calls <code>$new_object->BUILDALL($constructor_args)</code>
<br />... which calls all <code>BUILD</code> methods</li>
<li>Returns the object</li>
</ol>
use Moose;
# true
-Person->can('extends');</code></pre>
+Person->can('extends');</code></pre>
<ul>
<li>Not very hygienic</li>
...
-no Moose;
+<span class="highlight">no Moose;</span>
# false
-Person->can('extends');</code></pre>
+Person->can('extends');</code></pre>
+</div>
+
+<div class="slide">
+ <h1>Cleaning Up Moose Droppings</h1>
+
+ <pre><code>package Person;
+<span class="highlight">use namespace::autoclean;</span>
+use Moose;
+
+...
+
+# false
+Person->can('extends');</code></pre>
</div>
<div class="slide">
<h1>Immutability</h1>
<ul>
- <li><span style="font-family: URW Chancery L; font-size: 140%">Stevan's Incantation of Fleet-Footedness</span></li>
+ <li><span style="font-family: URW Chancery L; font-size: 120%">Stevan's Incantation of Fleet-Footedness</span></li>
</ul>
<pre><code>package Person;
use Moose;
-<span class="highlight">__PACKAGE__->meta->make_immutable;</span></code></pre>
+<span class="highlight">__PACKAGE__->meta->make_immutable;</span></code></pre>
</div>
<div class="slide">
<span class="delete">with 'Printable';</span>
-<span class="highlight">has has_been_printed => ( is => 'rw' );
+<span class="highlight">die '...' unless __PACKAGE__->can('as_string');
+
+has has_been_printed => ( is => 'rw' );
sub print {
my $self = shift;
# or ...
-Person->meta->does('Printable')</code></pre>
+Person->meta->does_role('Printable')</code></pre>
</div>
sub break {
my $self = shift;
- $self->break_it_down;
+ $self->break_it_down;
if ( rand(1) < 0.5 ) {
- $self->break_bone;
+ $self->break_bone;
}
}</code></pre>
</div>
sub is_equal {
my $self = shift;
- return $self->compare(@_) == 0;
+ return $self->compare(@_) == 0;
}</code></pre>
</div>
# Satisfies the Comparable role
sub compare { ... }
-Integer->does('TestsEquality'); # true
-Integer->does('Comparable'); # also true!</code></pre>
+Integer->does('TestsEquality'); # true
+Integer->does('Comparable'); # also true!</code></pre>
</div>
<div class="slide">
<pre><code>use Moose::Util qw( apply_all_roles );
-my $fragile_person = Person->new( ... );
+my $fragile_person = Person->new( ... );
apply_all_roles( $fragile_person,
'IsFragile' );</code></pre>
<span class="current incremental">required => 1,</span>
);
-<span class="incremental">Person->new( first_name => undef ); # ok
-Person->new(); # kaboom</span></code></pre>
+<span class="incremental">Person->new( first_name => undef ); # ok
+Person->new(); # kaboom</span></code></pre>
</div>
<div class="slide">
<ul>
<li>A method <em>name</em></li>
- <li>When called, this methods returns the default value</li>
+ <li>When called, this method returns the default value</li>
</ul>
</div>
use Moose;
has shoe_size => (
- is => 'ro',
+ is => 'ro',
+ required => 'ro',
);</code></pre>
</div>
<span class="highlight">init_arg => 'foot_size',</span>
);
-Person->new( <span class="wrong">shoe_size => 13</span> );
+Person->new( <span class="wrong">shoe_size => 13</span> );
my $person =
- Person->new( <span class="right">foot_size => 13</span> );
-print $person->shoe_size;</code></pre>
+ Person->new( <span class="right">foot_size => 13</span> );
+print $person->shoe_size;</code></pre>
</div>
<div class="slide">
<span class="highlight">init_arg => undef,</span>
);
-Person->new( <span class="wrong">shoes => Shoes->new</span> );</code></pre>
+Person->new( <span class="wrong">shoes => Shoes->new</span> );</code></pre>
</div>
<div class="slide">
$self->$orig(
$self->_munge_insert(@_) );
- $new_user->_assign_uri;
+ $new_user->_assign_uri;
return $new_user;
};</code></pre>
</div>
</div>
<div class="slide">
+ <h1>Trigger Arguments</h1>
+
+ <ul>
+ <li><code>$self</code></li>
+ <li><code>$new_value</code></li>
+ <li><code>$old_value</code> - if one exists</li>
+ </ul>
+</div>
+
+<div class="slide">
<h1>Delegation</h1>
<ul>
use App::CLI;
-<span class="highlight">App::CLI->new_with_options()</span>->run();</code></pre>
+<span class="highlight">App::CLI->new_with_options()</span>->run();</code></pre>
<pre>$ myapp-cli \
--file foo \