X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=moose-class%2Fslides%2Findex.html;h=1f2c059df5c1bc9eaddff47d5e0699b808f42890;hb=5b7f2dc1f80c19906bedd8ddc03a38db01db31d2;hp=25a7f6dada25f08d448c46ff77d1bf82f094d91b;hpb=726473c694521566a4ccd7289a22d9510dc32e56;p=gitmo%2Fmoose-presentations.git diff --git a/moose-class/slides/index.html b/moose-class/slides/index.html index 25a7f6d..1f2c059 100644 --- a/moose-class/slides/index.html +++ b/moose-class/slides/index.html @@ -52,7 +52,7 @@ img#me05 {top: 43px;left: 36px;}
@@ -154,7 +155,7 @@ img#me05 {top: 43px;left: 36px;}package Person;
use Moose;
-has first_name => ( is => 'rw' );
+has first_name => ( is => 'ro' );
@@ -892,8 +893,8 @@ use Moose;
@_
, returns a hash reference of attribute name/value pairsnew
's @_
, returns a hash reference of attribute name/value pairs$class->SUPER::BUILDARGS(@_)
as a fallback!DESTROY
, but Moose makes sure all DEMOLISH
methods in a hierarchy are calledDEMOLISH()
MooseX::NonMoose
for a workaroundMooseX::NonMoose
fixes all of thisoverride
is another method modifierSUPER::
package Person;
-use namespace::autoclean;
use Moose;
+use namespace::autoclean;
...
@@ -1230,7 +1234,7 @@ use Moose;
# perl bin/prove -lv t/00-prereq.t
-# perl install-moose (if needed)
+## Read the instructions in t/01-classes.t
# perl bin/prove -lv t/01-classes.t
@@ -1303,23 +1307,25 @@ sub print {
package Person;
use Moose;
-with 'HasPermissions';
+with 'Printable';
-
-
-
-
@@ -1561,9 +1543,9 @@ with 'HasSize';
package Comparison;
use Moose;
-has [ 'left', 'right' ] => (
- is => 'ro',
- does => 'Comparable',
+has [ 'left', 'right' ] => (
+ is => 'ro',
+ does => 'Comparable',
);
@@ -1652,8 +1634,6 @@ requires 'compare';
has shoes => (
is => 'ro',
lazy => 1,
- builder => '_build_shoes',
+ builder => '_build_shoes',
);
sub _build_shoes {
@@ -2000,7 +1974,7 @@ has account => (
package Person;
use Moose;
-has shoe_size => (
+has shoe_size => (
is => 'ro',
init_arg => 'foot_size',
);
@@ -2018,7 +1992,7 @@ print $person->shoe_size;
package Person;
use Moose;
-has shoes => (
+has shoes => (
is => 'ro',
init_arg => undef,
);
@@ -2041,16 +2015,8 @@ Person->new( shoes => Shoes->new );
Attribute Inheritance
- - By default, subclasses inherit attribute as-is
- - Can change some attribute parameters in subclasses
-
- - default
- - builder
- - required
- - lazy
- - others we've not yet covered
-
-
+ - By default, subclasses inherit attributes as-is
+ - Can change attribute parameters in subclasses
@@ -2403,60 +2369,6 @@ around run => sub {
-
-
-
-
-
-
-
-
-
-
@@ -2582,15 +2480,12 @@ Item
Bool
True
- 1
-924.1
-'true'
-{}
+ 1
False
0
-0.0
'0'
+''
undef
@@ -2705,11 +2600,15 @@ has start_date => (
Subtype Shortcuts - class_type
use Moose::Util::TypeConstraints;
-class_type 'DateTime';
+
+class_type 'DateTime';
+
+
subtype 'DateTime',
+
+subtype 'DateTime',
as 'Object',
where { $_->isa('DateTime') },
message { ... };
@@ -2719,11 +2618,15 @@ class_type 'DateTime';
role_type
use Moose::Util::TypeConstraints;
-role_type 'Printable';
+
+role_type 'Printable';
+
+
subtype 'Printable',
+
+subtype 'Printable',
as 'Object',
where
{ Moose::Util::does_role(
@@ -2735,11 +2638,15 @@ role_type 'Printable';
Subtype Shortcuts - duck_type
use Moose::Util::TypeConstraints;
-duck_type Car => qw( run break_down );
+
+duck_type Car => qw( run break_down );
+
+
subtype 'Car',
+
+subtype 'Car',
as 'Object',
where { all { $_->can($_) }
qw( run break_down ) },
@@ -2750,11 +2657,15 @@ 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 }
+
+my %ok = map { $_ => 1 }
qw( red blue green );
subtype 'Color'
@@ -2769,7 +2680,9 @@ subtype 'Color'
package Person;
my $posint =
- subtype as 'Int', where { $_ > 0 };
+ subtype
+ as 'Int',
+ where { $_ > 0 };
has size => (
is => 'ro',
@@ -2828,7 +2741,8 @@ coerce 'My::DateTime',
+
+
+
+
@@ -3003,9 +2930,9 @@ coerce ArrayOfInt
use MyApp::Types qw( ArrayOfInt );
-has transaction_history => (
- is => 'rw',
- isa => ArrayOfInt,
+has transaction_history => (
+ is => 'rw',
+ isa => ArrayOfInt,
);
@@ -3035,10 +2962,21 @@ has transaction_history => (
+
+
-
-
@@ -3198,7 +3127,7 @@ $alice->friend($bob);
has lungs => (
is => 'ro',
- isa => 'Lungs',
+ isa => 'Lungs',
handles => [ 'inhale', 'exhale' ],
);
@@ -3362,7 +3291,6 @@ has history => (
use Moose;
has _favorite_numbers => (
traits => [ 'Array' ],
- is => 'bare',
isa => 'ArrayRef[Int]',
default => sub { [] },
init_arg => undef,
@@ -3425,7 +3353,7 @@ has account => (
isa => 'BankAccount',
handles => {
receive_100 =>
- [ 'deposit', 100 ]
+ [ 'deposit', 100 ],
give_100 =>
[ 'withdraw', 100 ]
},
@@ -3543,28 +3471,17 @@ Iterate til this passes all its tests
-
-
+ use MooseX::Declare;
-use 5.10.0; # for say
+use 5.12.0; # for say
class Person {
has greeting =>
@@ -3614,7 +3531,7 @@ class Person {
Still experimental-ish, but seeing more and more use
Not a source filter!
Hooks into the Perl parser rather than filtering all your code
- But not supported by PPI
, perltidy
, etc. (yet?)
+ But not supported by PPI
, perltidy
, etc. (yet?)
@@ -3756,8 +3673,43 @@ use Moose;
with HasCollection => { type => 'Int' };
+
+
+
+
+
+
@@ -3766,7 +3718,7 @@ with HasCollection => { type => 'Int' };