X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=moose-class%2Fslides%2Findex.html;h=df47d7da6a22df25d3ad0adb40ca39d19134259d;hb=f5cc2f3e2e4b43900ab65afe4f5289d6ea551915;hp=1a1d44f1b16823e9c319b1bfc3dfbf1a638d4ab2;hpb=23d5de7494074a62e80a935962d87689efcb9a2f;p=gitmo%2Fmoose-presentations.git
diff --git a/moose-class/slides/index.html b/moose-class/slides/index.html
index 1a1d44f..df47d7d 100644
--- a/moose-class/slides/index.html
+++ b/moose-class/slides/index.html
@@ -1107,8 +1107,7 @@ has first_name => ( is => 'ro' );
my $person =
Person->new( first_name => 'Dave' );
-$person->first_name('Stevan');
-print $person->first_name; # Dave
+$person->first_name('Stevan'); # dies
@@ -1428,69 +1427,17 @@ use Moose;
-
Method Aliasing
-
-
package FragileDancer;
-use Moose;
-
-with 'IsFragile' =>
- { -alias =>
- { break => 'break_bone' } },
- 'CanBreakdance' =>
- { -alias =>
- { break => 'break_it_down' } };
-
-
- - Renames the roles' methods
- - Still conflicts, need to
exclude
as well
-
-
-
-
-
Method Exclusion
-
-
package FragileDancer;
-use Moose;
-
-with 'IsFragile' =>
- { -alias =>
- { break => 'break_bone' },
- -excludes => 'break' },
- 'CanBreakdance' =>
- { -alias =>
- { break => 'break_it_down' },
- -excludes => 'break' };
-
-
-
-
And then ...
-
-
package FragileDancer;
-use Moose;
-
-sub break {
- my $self = shift;
-
- $self->break_it_down;
- if ( rand(1) < 0.5 ) {
- $self->break_bone;
- }
-}
-
-
-
-
Still Full of Fail
+
Conflicts Are a Smell
- - Roles are also about semantics!
- - We've fulfilled the letter and lost the spirit
+ - Roles are about semantics!
- Roles have a meaning
- - Think twice before blindly aliasing and excluding methods!
+ - Method name conflicts smell like bad design
-
Hot Role-on-Role Action
+
Roles With Roles
package Comparable;
use Moose::Role;
@@ -1499,7 +1446,7 @@ requires 'compare';
-
Hot Role-on-Role Action
+
Roles With Roles
package TestsEquality;
use Moose::Role;
@@ -1546,11 +1493,11 @@ with 'HasSubProcess';
Delayed Conflict
-
package StateOfTexas;
+ package SysadminAssassin;
with 'Killer';
- StateOfTexas
must implement its own execute
+ SysadminAssassin
must implement its own execute
- But loading the
Killer
role by itself does not cause an error
@@ -1970,7 +1917,7 @@ use Moose;
has shoe_size => (
is => 'ro',
- required => 'ro',
+ required => 1,
);
@@ -2470,19 +2417,21 @@ around run => sub {
Augment and Inner
-
package Document;
+ package Document;
sub xml { '<doc>' . inner() . '</doc>' }
package Report;
extends 'Document';
augment xml =>
- sub { title() . inner() . summary() };
+ sub { my $self = shift;
+ $self->title() . inner() . $self->summary() };
package TPSReport;
extends 'Report';
augment xml =>
- sub { tps_xml() . inner() };
+ sub { my $self = shift;
+ $self->tps_xml() . inner() };
@@ -2608,6 +2557,7 @@ Item
Num
Int
ClassName
+ RoleName
@@ -2761,7 +2711,7 @@ class_type 'DateTime';
-subtype 'DateTime',
+subtype 'DateTime',
as 'Object',
where { $_->isa('DateTime') },
message { ... };
@@ -2776,7 +2726,7 @@ role_type 'Printable';
subtype 'Printable',
- as 'Object',
+ as 'Object',
where
{ Moose::Util::does_role(
$_, 'Printable' ) },
@@ -2802,14 +2752,14 @@ duck_type Car => qw( run break_down );
Subtype Shortcuts - enum
use Moose::Util::TypeConstraints;
-enum Color => qw( red blue green ) );
+enum Color => qw( red blue green );
my %ok = map { $_ => 1 }
qw( red blue green );
-subtype 'Color'
+subtype 'Color'
as 'Str',
where { $ok{$_} },
message { ... };
@@ -2925,6 +2875,19 @@ no Moose;
+
Questions So Far?
+
+
+
+
Exercises
+
+
# cd exercises
+# perl bin/prove -lv t/05-types.t
+
+Iterate til this passes all its tests
+
+
+
Typed Methods (Low-tech)
package Person;
@@ -3101,15 +3064,6 @@ has transaction_history => (
Questions?
-
-
Exercises
-
-
# cd exercises
-# perl bin/prove -lv t/05-types.t
-
-Iterate til this passes all its tests
-
-
Part 6: Advanced Attributes
@@ -3414,7 +3368,7 @@ has history => (
use Moose;
has _favorite_numbers => (
traits => [ 'Array' ],
- is => 'ro',
+ is => 'bare',
isa => 'ArrayRef[Int]',
default => sub { [] },
init_arg => undef,
@@ -3575,6 +3529,7 @@ print Person->meta
Use weak_ref
to avoid circular references
Use trigger to do an action post-attribute write
Use delegations to hide "internal" objects
+ Use native delegations to treat Perl types as objects
Traits and metaclasses let you extend Moose's core attribute features
@@ -3593,12 +3548,31 @@ print Person->meta
Iterate til this passes all its tests
+
+
Questions?
+
+
-
Part 7: Introspection
+ The End
+
+
+
+
-
Part 8: A Brief Tour of MooseX
+ Bonus: A Brief Tour of MooseX
@@ -3788,30 +3762,8 @@ use Moose;
with HasCollection => { type => 'Int' };
-
-
Questions?
-
-
-
-
Part 9: Writing Moose Extensions
-
-
-
The End
-
-
-
-
More Information
-
-
+
The End (Really)