X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=moose-class%2Fslides%2Findex.html;h=e2e889a1a72d032d6527ae0358e029615f2400dc;hb=d7deb8a91eda73a9252643bc0b221dd6e5d34482;hp=9ae74e48eb3775137b0ab95311c0f59e867b18ba;hpb=216ed9cb8b80e068bd29665393a341edc5b4fb9a;p=gitmo%2Fmoose-presentations.git
diff --git a/moose-class/slides/index.html b/moose-class/slides/index.html
index 9ae74e4..e2e889a 100644
--- a/moose-class/slides/index.html
+++ b/moose-class/slides/index.html
@@ -71,7 +71,8 @@ img#me05 {top: 43px;left: 36px;}
- Declarative OO sugar
- Introspectable
- - Extensible (MooseX::* on CPAN)
+ - Extensible (177 MooseX::* on CPAN)
+ - Community approved (1222 downstream dependents on CPAN)
@@ -976,6 +977,7 @@ sub BUILD {
- Like
DESTROY
, but Moose makes sure all DEMOLISH
methods in a hierarchy are called
- Called in normal inheritance order, children to parents
+ - Never called by you, only by Perl itself
@@ -1039,6 +1041,7 @@ extends 'LWP';
override
is another method modifier
- An alternative to Perl's
SUPER::
+ - Declares your intent to override a method
@@ -1107,8 +1110,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,64 +1430,12 @@ 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
@@ -1578,7 +1528,7 @@ use Moose;
with 'HasSize';
-has size => ( is => 'ro' );
+has size => ( is => 'ro' );
@@ -1592,7 +1542,7 @@ requires 'size';
package Shirt;
use Moose;
-has size => ( is => 'ro' );
+has size => ( is => 'ro' );
with 'HasSize';
@@ -1614,9 +1564,9 @@ with 'HasSize';
package Comparison;
use Moose;
-has [ 'left', 'right' ] => (
- is => 'ro',
- does => 'Comparable',
+has [ 'left', 'right' ] => (
+ is => 'ro',
+ does => 'Comparable',
);
@@ -1913,7 +1863,7 @@ has bank => (
sub _build_bank {
my $self = shift;
return Bank->new(
- name => 'Spire FCU' );
+ name => 'Spire FCU' );
}
@@ -1970,7 +1920,7 @@ use Moose;
has shoe_size => (
is => 'ro',
- required => 'ro',
+ required => 1,
);
@@ -1980,7 +1930,7 @@ has shoe_size => (
has shoes => (
is => 'ro',
lazy => 1,
- builder => '_build_shoes',
+ builder => '_build_shoes',
);
sub _build_shoes {
@@ -2053,7 +2003,7 @@ has account => (
package Person;
use Moose;
-has shoe_size => (
+has shoe_size => (
is => 'ro',
init_arg => 'foot_size',
);
@@ -2071,7 +2021,7 @@ print $person->shoe_size;
package Person;
use Moose;
-has shoes => (
+has shoes => (
is => 'ro',
init_arg => undef,
);
@@ -2470,19 +2420,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() };
@@ -2803,7 +2755,7 @@ 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 );
@@ -2926,6 +2878,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;
@@ -3056,9 +3021,9 @@ coerce ArrayOfInt
use MyApp::Types qw( ArrayOfInt );
-has transaction_history => (
- is => 'rw',
- isa => ArrayOfInt,
+has transaction_history => (
+ is => 'rw',
+ isa => ArrayOfInt,
);
@@ -3102,15 +3067,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
@@ -3251,7 +3207,7 @@ $alice->friend($bob);
has lungs => (
is => 'ro',
- isa => 'Lungs',
+ isa => 'Lungs',
handles => [ 'inhale', 'exhale' ],
);
@@ -3582,10 +3538,6 @@ print Person->meta
-
Questions?
-
-
-
Exercises
# cd exercises
@@ -3595,8 +3547,20 @@ print Person->meta
Iterate til this passes all its tests
+
+
CYOA
+
+
+ If there is time, keep going ...
+
+
+
+ Otherwise, jump to slide 269 ...
+
+
+
-
Part 7: A Brief Tour of MooseX
+ Bonus: A Brief Tour of MooseX
@@ -3790,18 +3754,21 @@ with HasCollection => { type => 'Int' };
Questions?
-
+
+ For further reading, a few modules which use Moose ...
+
-
@@ -3818,6 +3785,10 @@ with HasCollection => { type => 'Int' };
+
+
The End
+
+