From: Dave Rolsky Date: Tue, 2 Feb 2010 19:52:45 +0000 (-0600) Subject: Many small tweaks and fixes X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=78c5b76a4c64e9693ad841efc562d7ab4257ac3c;p=gitmo%2Fmoose-presentations.git Many small tweaks and fixes --- diff --git a/moose-class/slides/index.html b/moose-class/slides/index.html index f0bea94..6bcad03 100644 --- a/moose-class/slides/index.html +++ b/moose-class/slides/index.html @@ -1152,7 +1152,8 @@ Person->can('extends');

No Moose

@@ -1867,7 +1868,8 @@ has packages => ( use Moose; my $highlander_bank = - Bank->new( name => 'Spire FCU' ); + Bank->new( + name => 'Clan MacLeod Trust' ); has bank => ( is => 'rw', @@ -1879,7 +1881,8 @@ has bank => (

Builder

@@ -2206,6 +2209,13 @@ has first_name => (
  • Attributes can have a default or builder
  • Attributes with a default or builder can be lazy
  • Attributes can have a clearer and/or predicate
  • + + + +
    +

    Basic Attributes Summary

    + +
    -

    What is a Method Modifier

    +

    What Are Method Modifiers For?

    @@ -2437,6 +2447,7 @@ around run => sub { @@ -2579,11 +2590,10 @@ Item Undef Defined Value - Str - Num - Int - ClassName - RoleName + Str + Num + Int + ClassName @@ -2601,7 +2611,7 @@ Item CodeRef RegexpRef GlobRef - FileHandle + FileHandle Object @@ -2733,9 +2743,11 @@ 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 { ... };
    @@ -2745,9 +2757,11 @@ subtype 'DateTime',

    Subtype Shortcuts - role_type

    use Moose::Util::TypeConstraints;
    -role_type 'Printable';
    +role_type 'Printable';
    -subtype 'Printable', +
    + +
    subtype 'Printable',
         as      'Object',
         where
             { Moose::Util::does_role(
    @@ -2759,9 +2773,11 @@ subtype '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 ) },
    @@ -2772,9 +2788,11 @@ subtype 'Car',
       

    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'
    @@ -3035,7 +3053,7 @@ has transaction_history => (
       
    • Type names are exported functions, catches typos early
    • Types must be pre-declared
    • -
    • Types are stored with namespaces internally, but externally are short
    • +
    • Types are stored with namespaces internally, but you use short names
    • Import existing Moose types as functions from MooseX::Types::Moose
    • Still need string names for things like ArrayRef['Email::Address']
    @@ -3048,7 +3066,7 @@ has transaction_history => (
  • Catches typos at compile time
  • Automatic namespacing
  • One more thing to install and learn
  • -
  • Every name gets types twice (declared and then defined)
  • +
  • Every name is typed twice (declared and then defined)
  • Still stuck with strings when referring to class or role names
  • Coercion gotcha from earlier still applies to types exported from MooseX::Types::Moose
  • @@ -3175,7 +3193,7 @@ $alice->friend($bob);
    after salary_level => {
         my $self = shift;
    -    return unless @_;
    +    return unless @_;
         $self->clear_salary;
     };
    @@ -3187,7 +3205,8 @@ $alice->friend($bob);
    has salary_level => (
         is      => 'rw',
    -    trigger => sub { $_[0]->clear_salary },
    +    trigger =>
    +        sub { $_[0]->clear_salary },
     );
    @@ -3248,6 +3267,7 @@ has lungs => (

    Array Reference

      +
    • 1-to-1 mapping
    • Takes each method name and creates a simple delegation from the delegating class to the delegatee attribute
    @@ -3408,7 +3428,7 @@ print "$_\n"
  • Bool - set, toggle, ...
  • Hash - get, set, ...
  • Array - already saw it
  • -
  • Code - execute, that's it
  • +
  • Code - execute and execute_method
  • @@ -3473,7 +3493,7 @@ $person->account->deposit(100);

    Traits and Metaclasses

    @@ -3562,7 +3582,7 @@ Iterate til this passes all its tests @@ -3672,7 +3692,7 @@ use Moose; has file => ( is => 'ro', required => 1 ); has filters => - ( is => 'ro', isa => 'Str' ); + ( is => 'ro', isa => 'ArrayRef[Str]' ); sub run { ... }
    @@ -3766,7 +3786,7 @@ with HasCollection => { type => 'Int' };
  • mailing list - moose@perl.org
  • Slides and exercises are in Moose's git repo:
    - git://jules.scsys.co.uk/gitmo/moose-presentations
  • + git://jules.scsys.co.uk/gitmo/moose-presentations