<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>
my $person =
Person->new( first_name => 'Dave' );
-$person->first_name('Stevan');
-print $person->first_name; # Dave</code></pre>
+$person->first_name('Stevan'); # dies</code></pre>
</div>
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">
# 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>
</div>
<div class="slide">
- <h1>Hot Role-on-Role Action</h1>
+ <h1>Roles With Roles</h1>
<pre><code>package Comparable;
use Moose::Role;
</div>
<div class="slide">
- <h1>Hot Role-on-Role Action</h1>
+ <h1>Roles With Roles</h1>
<pre><code>package TestsEquality;
use Moose::Role;
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">
<div class="slide">
<h1>Delayed Conflict</h1>
- <pre><code>package StateOfTexas;
+ <pre><code>package SysadminAssassin;
with 'Killer';</code></pre>
<ul>
- <li><code>StateOfTexas</code> must implement its own <code>execute</code></li>
+ <li><code>SysadminAssassin</code> must implement its own <code>execute</code></li>
<li>But loading the <code>Killer</code> role by itself does not cause an error</li>
</ul>
</div>
<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">
has shoe_size => (
is => 'ro',
- required => 'ro',
+ required => 1,
);</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>
Num
Int
ClassName
+ RoleName
</pre>
</div>
<hr />
-<pre><code>subtype 'DateTime',
+<pre><code>subtype 'DateTime',
as 'Object',
where { $_->isa('DateTime') },
message { ... };</code></pre>
<hr />
<pre><code>subtype 'Printable',
- as 'Object',
+ as 'Object',
where
{ Moose::Util::does_role(
$_, 'Printable' ) },
<pre><code>my %ok = map { $_ => 1 }
qw( red blue green );
-subtype 'Color'
+subtype 'Color'
as 'Str',
where { $ok{$_} },
message { ... };</code></pre>
use Moose;
has _favorite_numbers => (
traits => [ 'Array' ],
- is => 'ro',
+ is => 'bare',
isa => 'ArrayRef[Int]',
default => sub { [] },
init_arg => undef,
<li>Use <code>weak_ref</code> to avoid circular references</li>
<li>Use trigger to do an action post-attribute write</li>
<li>Use delegations to hide "internal" objects</li>
+ <li>Use native delegations to treat Perl types as objects</li>
<li>Traits and metaclasses let you extend Moose's core attribute features</li>
</ul>
</div>
Iterate til this passes all its tests</pre>
</div>
+<div class="slide">
+ <h1>Questions?</h1>
+</div>
+
<div class="slide fake-slide0">
- <h1>Part 7: Introspection</h1>
+ <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="font-size:80%; white-space: nowrap">git://jules.scsys.co.uk/gitmo/moose-presentations</span></li>
+ </ul>
+</div>
+
+
<div class="slide fake-slide0">
- <h1>Part 8: A Brief Tour of MooseX</h1>
+ <h1>Bonus: A Brief Tour of MooseX</h1>
</div>
<div class="slide">
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 \
with HasCollection => { type => 'Int' };</code></pre>
</div>
-<div class="slide">
- <h1>Questions?</h1>
-</div>
-
-<div class="slide fake-slide0">
- <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="font-size:80%; white-space: nowrap">git://jules.scsys.co.uk/gitmo/moose-presentations</span></li>
- </ul>
+ <h1>The End (Really)</h1>
</div>
</div>