X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=moose-class%2Fslides%2Findex.html;h=67fcb8e6b3fadea9b8573f8b39f92f7d58624414;hb=1847dd9ee8e1f995b293d12f2dc700b6f43092dc;hp=992d256381abc92e3ffbd02249933184b8c96856;hpb=1c32806a415472ca126fcba161ec8e15ed45540f;p=gitmo%2Fmoose-presentations.git diff --git a/moose-class/slides/index.html b/moose-class/slides/index.html index 992d256..67fcb8e 100644 --- a/moose-class/slides/index.html +++ b/moose-class/slides/index.html @@ -40,7 +40,7 @@ img#me05 {top: 43px;left: 36px;}
@@ -284,10 +287,10 @@ use Moose; has blog_uri => ( is => 'rw', isa => 'URI', - handles => { 'blog_hostname' => 'host' }, + handles => { 'blog_host' => 'host' }, ); -$person->blog_hostname; +$person->blog_host; # really calls $person->blog_uri->host @@ -888,7 +891,6 @@ sub BUILDARGS { if ( @_ == 1 && ! ref $_[0] ) { return { ssn => $_[0] }; } - return $class->SUPER::BUILDARGS(@_); } @@ -962,6 +964,8 @@ sub BUILD {extends
is sugar for declaring parent classesuse base
package Employee;
@@ -1029,7 +1033,8 @@ use Moose;
override work => sub {
my $self = shift;
- die "Pay me first" unless $self->got_paid;
+ die "Pay me first"
+ unless $self->got_paid;
super();
};
@@ -1127,7 +1132,7 @@ Person->can('extends');
no Moose
at the end of a package is a best practicenamespace::clean
at the topuse namespace::autoclean
at the topmy $person = Person->new(
- first_name => 'Kenichi',
- last_name => 'Asai',
+ first_name => 'Kenichi',
+ last_name => 'Asai',
access_level => 42,
);
@@ -1326,7 +1333,7 @@ sub print {
# or ...
-if ( Person->meta->does('Printable') ) { ... }
+Person->meta->does('Printable')
@@ -1392,10 +1399,10 @@ use Moose;
use Moose;
with 'IsFragile' =>
- { alias =>
+ { -alias =>
{ break => 'break_bone' } },
'CanBreakdance' =>
- { alias =>
+ { -alias =>
{ break => 'break_it_down' } };
# cd exercises -# perl bin/prove -lv t/04-method-modifiers.t +# perl bin/prove -lv \ + t/04-method-modifiers.t Iterate til this passes all its tests@@ -2663,8 +2670,9 @@ undef subtype 'PositiveInt', as 'Int', where { $_ > 0 }, - message { "The value you provided ($_)" - . " was not a positive number." }; + message + { "The value you provided ($_)" + . " was not a positive int." }; has size => ( is => 'ro', @@ -2743,7 +2751,9 @@ subtype 'Car',
use Moose::Util::TypeConstraints;
enum Color => qw( red blue green ) );
-my %ok = map { $_ => 1 } qw( red blue green );
+my %ok = map { $_ => 1 }
+ qw( red blue green );
+
subtype 'Color'
as 'Str',
where { $ok{$_} },
@@ -2775,9 +2785,13 @@ has size => (
subtype 'UCStr',
as 'Str',
- where { ! /[a-z]/ };
+ where { ! /[a-z]/ };
+
+
+
@@ -2899,7 +2910,7 @@ sub work {
Moose::Meta::TypeConstraint
objectsMoose::Meta::TypeConstraints
objectsuse Moose::Util::TypeConstraints;
-
subtype 'MyApp::Type::DateTime',
as 'DateTime';
@@ -3108,7 +3118,8 @@ $alice->friend($bob);
use Moose;
has name => ( is => 'ro' );
-has friend => ( is => 'rw', weak_ref => 1 );
+has friend => ( is => 'rw',
+ weak_ref => 1 );
my $alice = Person->new( name => 'Alice' );
my $bob = Person->new( name => 'Bob' );
@@ -3227,7 +3238,6 @@ has lungs => (
package Person;
use Moose;
-
has account => (
is => 'ro',
isa => 'BankAccount',
@@ -3275,7 +3285,6 @@ has name => (
package Auditor;
use Moose::Role;
-
sub record_change { ... }
sub change_history { ... }
@@ -3316,7 +3325,6 @@ has history => (
package Person;
use Moose;
-
has _favorite_numbers => (
traits => [ 'Array' ],
is => 'ro',
@@ -3328,10 +3336,6 @@ has _favorite_numbers => (
add_favorite_number => 'push',
},
);
-
-
- - Automatically defaults to
[]
-
@@ -3416,7 +3418,6 @@ has ssn => (
isa => 'Str',
label => 'Social Security Number',
);
-
print Person->meta
->get_attribute('ssn')->label;
@@ -3451,7 +3452,8 @@ print Person->meta
Exercises
# cd exercises
-# perl bin/prove -lv t/06-advanced-attributes.t
+# perl bin/prove -lv \
+ t/06-advanced-attributes.t
Iterate til this passes all its tests