SlideShare a Scribd company logo
1 of 22
Trait Moose::Role
2009   5   8
: Moose::Role

            Perl              Java interface
✤




        requires                    API
    ✤




        with          API
    ✤




               Perl                            gihyo.jp
✤




                      Trait
    ✤
: Mix-in           (1)


✤


                                    3
    (   Linux 2005   7   )

        Mix-in               Lisp
    ✤
: Mix-in   (2)

    Mix-in
✤




    ✤




             Mix-in
    ✤




    Mix-in
✤




    ✤




    ✤
: Mix-in                  (3)
Ruby
                                        SuperClass
module MixinA
 def mixin1
                               MixinB
  print quot;Hello Mixin Anquot;
 end
end
                                         SubClass
module MixinC
 def mixin2
                                                         MixinA
                               MixinC
  mixin1
  print quot;Hello Mixin Cnquot;
 end
                                        SubSubClass
end

                                                                   MixinA
class SubSubClass < SubClass
 include MixinA
 include MixinC
end

                                                     SuperClass2
SubSubClass.new.mixin2
Trait



           OOP
✤




                 Mix-in
✤




    2002     Traits: Composable Units of Behavior
✤
Trait

    Perl 5(Moose) Perl 6
✤




    JavaScript(Joose)
✤




    Java(Scala)
✤




    Ruby (module Mix-in                )
✤




    Fortress       2006 sun
✤




    Smalltalk, PHP, ActionScript 3.0
✤
Trait Mix-in

    Flatten
✤




                         (Perl   Exporter     )
    ✤




                                        = Trait
    ✤




                (with, import)
✤




        Trait                       =
    ✤




    Trait                                         (   )
✤
Moose::Role Trait
                                                              (provided)
✤




                                                                           (required)
✤




                                                                               (                OK)
✤


    package TaxRole;

                                                                                   TaxRole
    use Moose::Role;

    requires 'price';
                                                                  comsumption_tax       price
    our $TAX_RATE = 0.05;
                                                                  tax_inclusive_price
    sub consumption_tax{
    
        return shift->price * $TAX_RATE;
    }

    sub tax_inclusive_price{
    
         my $self = shift;
    
         return $self->price + $self->consumption_tax;
    }

    no Moose::Role;
Moose::Role Trait

                  Trait
✤




    required
✤




                                                Goods
    package Goods;
    use Moose;
                               price
    has price => (
    
       isa    => 'Int',
                                               TaxRole
    
       is    => 'ro',
    
       required => 1,
                                comsumption_tax       price
    );
                                tax_inclusive_price
    with 'TaxRole';

    no Moose;
Trait



    sum : t1 + t2
✤




    alias : t[a→b]
✤




    exclusion : t - a
✤
Trait                        (1) - sum

                                           package TraitsA;
    required + provided = provided
✤
                                           use Moose::Role;
    required + required = required
✤
                                           with 'TraitsB';
    provided + provided = required (   )
✤

                                           no Moose::Role;



        TraitA                TraitB                 TraitA
                    += a                   ⇒
    a      c                     d              b        a
    b      d             c                      c        d
sum :                              ...

                (m, ⊥:     ,⟙:     )             m1 ⊔ ⟙ = ⟙
        →                                    ✤
✤




                                                 ⟘⊔⟙=⟙
                                             ✤
    ⟘ ⊔⟘=⟘
✤



                                                 ⟙⊔⟙=⟙
                                             ✤
    m1 ⊔ ⟘ = m1
✤



                                                 provided: ⊥     ⟙
                                             ✤
    m1 ⊔ m1 = m1
✤




    m1 ⊔ m2 = ⟙                                  required:                - provided
✤                                            ✤



          TraitA                   TraitB                            TraitA
                         += a = m3, c = m4             ⇒
     a = m1, b = m2                                            b = m2, c = m4
     c = ⟘, d = ⟘            d=⟘                               a = ⟙, d = ⟘
Trait                (2) - alias

                                   package AnotherTraits;
                                   use Moose::Role;

                       →
✤
                                   with 'TraitsA' => {
                                      alias => {a => 'e'},
                                   };

                                   no Moose::Role;



        TraitA                      TraitA
                 [e → a]   ⇒
    a      c                   a          c
    b      d                   b          d
                               e
Trait                   (3) - exclusion

                                 package AnotherTraits;
                                 use Moose::Role;

                 −
✤
                                 with 'TraitsA' => {
                                    excludes => ['a'],
                                 };

                                 no Moose::Role;



        TraitA                    TraitA
                 -= a    ⇒
    a      c                 b          c
    b      d                            d
Trait                             :
    package TraitsA;
    use Moose::Role;
                                                               TraitA
    with 'TraitsB' => {
                                                         a        b
       alias     => {b => 'e'},
       excludes => ['c'],                                c
    };                                                   d
                                                         e
    no Moose::Role;




      TraitA                          TraitB
a           d             += ( b         a     [e → b] - c )
b                                 c
c                                 d
Trait                             :
    package TraitsA;
    use Moose::Role;
                                                                TraitA
    with 'TraitsB' => {
                                                          a        b
       alias     => {b => 'e'},
       excludes => ['c'],                                 c
    };                                                    d
                                                          e
    no Moose::Role;




      TraitA                           TraitB
                          += ( b = e
a           d                             a     [e → b] - c )
                                  =
b                                 c
c                                 d
Trait
✤




    package Trait;                                   package Class;
    use Moose::Role;                                 use Moose;
    sub class_vs_trait{ print __PACKAGE__, quot;nquot;; }   extends 'SuperClass'; with 'Trait';
    sub super_vs_trait{ print __PACKAGE__, quot;nquot;; }   sub class_vs_trait{ print __PACKAGE__, quot;nquot;; }
    no Moose::Role;                                  no Moose;

    package SuperClass;                              package main;
    use Moose;                                       my $c = Class->new;
    sub super_vs_trait{ print __PACKAGE__, quot;nquot;; }   $c->class_vs_trait;
    no Moose;                                        $c->super_vs_trait;
Class 1      SuperClass 1       (∵              )
✤


                    Trait   Trait
    ⇒

    Trait                                required
✤


                  (Mix-in                               )
    ⇒

✤




    ✤




        alias exclusion
    ✤
package TraitA;
use Moose::Role;                    package Class;
sub vs{ print __PACKAGE__, quot;nquot; }   use Moose;
no Moose::Role;                     with 'TraitA', 'TraitB';
                                    no Moose;
package TraitB;
use Moose::Role;                    package main;
sub vs{ print __PACKAGE__, quot;nquot; }   Class->new->vs;
no Moose::Role;
Trait

     state(              )   Trait
 ✤




         → has
     ✤




                 Trait
 ✤




         →
     ✤
✤




    Trait
✤




    Trait Mix-in
✤

More Related Content

What's hot

Jordan west real workscalazfinal2
Jordan west   real workscalazfinal2Jordan west   real workscalazfinal2
Jordan west real workscalazfinal2Skills Matter Talks
 
100610_blastclustalw
100610_blastclustalw100610_blastclustalw
100610_blastclustalwocha_kaneko
 
Migrating To Ruby1.9
Migrating To Ruby1.9Migrating To Ruby1.9
Migrating To Ruby1.9tomaspavelka
 
Introduction to ad-3.4, an automatic differentiation library in Haskell
Introduction to ad-3.4, an automatic differentiation library in HaskellIntroduction to ad-3.4, an automatic differentiation library in Haskell
Introduction to ad-3.4, an automatic differentiation library in Haskellnebuta
 
Actionsscript cheat sheet_letter
Actionsscript cheat sheet_letterActionsscript cheat sheet_letter
Actionsscript cheat sheet_letterRadik Setagalih
 
Actionsscript Cheat Sheet Letter
Actionsscript Cheat Sheet LetterActionsscript Cheat Sheet Letter
Actionsscript Cheat Sheet Letterguest2a6b08
 
090622_blast-clustalw
090622_blast-clustalw090622_blast-clustalw
090622_blast-clustalwocha_kaneko
 
MiamiJS - The Future of JavaScript
MiamiJS - The Future of JavaScriptMiamiJS - The Future of JavaScript
MiamiJS - The Future of JavaScriptCaridy Patino
 
5 Favorite Gems (Lightning Talk(
5 Favorite Gems (Lightning Talk(5 Favorite Gems (Lightning Talk(
5 Favorite Gems (Lightning Talk(Mark
 
MTDDC 2010.2.5 Tokyo - Brand new API
MTDDC 2010.2.5 Tokyo - Brand new APIMTDDC 2010.2.5 Tokyo - Brand new API
MTDDC 2010.2.5 Tokyo - Brand new APISix Apart KK
 
Surface flingerservice(서피스플링거서비스초기화)
Surface flingerservice(서피스플링거서비스초기화)Surface flingerservice(서피스플링거서비스초기화)
Surface flingerservice(서피스플링거서비스초기화)fefe7270
 

What's hot (15)

Jordan west real workscalazfinal2
Jordan west   real workscalazfinal2Jordan west   real workscalazfinal2
Jordan west real workscalazfinal2
 
100610_blastclustalw
100610_blastclustalw100610_blastclustalw
100610_blastclustalw
 
Migrating To Ruby1.9
Migrating To Ruby1.9Migrating To Ruby1.9
Migrating To Ruby1.9
 
Introduction to ad-3.4, an automatic differentiation library in Haskell
Introduction to ad-3.4, an automatic differentiation library in HaskellIntroduction to ad-3.4, an automatic differentiation library in Haskell
Introduction to ad-3.4, an automatic differentiation library in Haskell
 
Actionsscript cheat sheet_letter
Actionsscript cheat sheet_letterActionsscript cheat sheet_letter
Actionsscript cheat sheet_letter
 
Actionsscript Cheat Sheet Letter
Actionsscript Cheat Sheet LetterActionsscript Cheat Sheet Letter
Actionsscript Cheat Sheet Letter
 
090622_blast-clustalw
090622_blast-clustalw090622_blast-clustalw
090622_blast-clustalw
 
JSTLQuick Reference
JSTLQuick ReferenceJSTLQuick Reference
JSTLQuick Reference
 
MiamiJS - The Future of JavaScript
MiamiJS - The Future of JavaScriptMiamiJS - The Future of JavaScript
MiamiJS - The Future of JavaScript
 
5 Favorite Gems (Lightning Talk(
5 Favorite Gems (Lightning Talk(5 Favorite Gems (Lightning Talk(
5 Favorite Gems (Lightning Talk(
 
MTDDC 2010.2.5 Tokyo - Brand new API
MTDDC 2010.2.5 Tokyo - Brand new APIMTDDC 2010.2.5 Tokyo - Brand new API
MTDDC 2010.2.5 Tokyo - Brand new API
 
Groovy
GroovyGroovy
Groovy
 
Go &lt;-> Ruby
Go &lt;-> RubyGo &lt;-> Ruby
Go &lt;-> Ruby
 
Android Guava
Android GuavaAndroid Guava
Android Guava
 
Surface flingerservice(서피스플링거서비스초기화)
Surface flingerservice(서피스플링거서비스초기화)Surface flingerservice(서피스플링거서비스초기화)
Surface flingerservice(서피스플링거서비스초기화)
 

Viewers also liked

すべてが@__kanになる
すべてが@__kanになるすべてが@__kanになる
すべてが@__kanになるMasahiro Honma
 
モデルから知るGit
モデルから知るGitモデルから知るGit
モデルから知るGitMasahiro Honma
 
レンズ (ぶつかり稽古の没プレゼン)
レンズ (ぶつかり稽古の没プレゼン)レンズ (ぶつかり稽古の没プレゼン)
レンズ (ぶつかり稽古の没プレゼン)Masahiro Honma
 
カレーとHokkaidopm
カレーとHokkaidopmカレーとHokkaidopm
カレーとHokkaidopmMasahiro Honma
 
Hachioji.pm in Machida の LT
Hachioji.pm in Machida の LTHachioji.pm in Machida の LT
Hachioji.pm in Machida の LTMasahiro Honma
 
Stateモナドの解説 中編
Stateモナドの解説 中編Stateモナドの解説 中編
Stateモナドの解説 中編Masahiro Honma
 
Types and perl language
Types and perl languageTypes and perl language
Types and perl languageMasahiro Honma
 
ウヰスキーとPSGI
ウヰスキーとPSGIウヰスキーとPSGI
ウヰスキーとPSGIMasahiro Honma
 
モナモナ言うモナド入門.tar.gz
モナモナ言うモナド入門.tar.gzモナモナ言うモナド入門.tar.gz
モナモナ言うモナド入門.tar.gzMasahiro Honma
 
Stateモナドの解説 前編
Stateモナドの解説 前編Stateモナドの解説 前編
Stateモナドの解説 前編Masahiro Honma
 
Stateモナドの解説 後編
Stateモナドの解説 後編Stateモナドの解説 後編
Stateモナドの解説 後編Masahiro Honma
 
循環参照のはなし
循環参照のはなし循環参照のはなし
循環参照のはなしMasahiro Honma
 

Viewers also liked (20)

Monads in perl
Monads in perlMonads in perl
Monads in perl
 
すべてが@__kanになる
すべてが@__kanになるすべてが@__kanになる
すべてが@__kanになる
 
モデルから知るGit
モデルから知るGitモデルから知るGit
モデルから知るGit
 
レンズ (ぶつかり稽古の没プレゼン)
レンズ (ぶつかり稽古の没プレゼン)レンズ (ぶつかり稽古の没プレゼン)
レンズ (ぶつかり稽古の没プレゼン)
 
カレーとHokkaidopm
カレーとHokkaidopmカレーとHokkaidopm
カレーとHokkaidopm
 
Perl saved a lady.
Perl saved a lady.Perl saved a lady.
Perl saved a lady.
 
20120526 hachioji.pm
20120526 hachioji.pm20120526 hachioji.pm
20120526 hachioji.pm
 
Git入門
Git入門Git入門
Git入門
 
Hachioji.pm in Machida の LT
Hachioji.pm in Machida の LTHachioji.pm in Machida の LT
Hachioji.pm in Machida の LT
 
Stateモナドの解説 中編
Stateモナドの解説 中編Stateモナドの解説 中編
Stateモナドの解説 中編
 
Types and perl language
Types and perl languageTypes and perl language
Types and perl language
 
ウヰスキーとPSGI
ウヰスキーとPSGIウヰスキーとPSGI
ウヰスキーとPSGI
 
モナモナ言うモナド入門.tar.gz
モナモナ言うモナド入門.tar.gzモナモナ言うモナド入門.tar.gz
モナモナ言うモナド入門.tar.gz
 
定理3
定理3定理3
定理3
 
Stateモナドの解説 前編
Stateモナドの解説 前編Stateモナドの解説 前編
Stateモナドの解説 前編
 
Stateモナドの解説 後編
Stateモナドの解説 後編Stateモナドの解説 後編
Stateモナドの解説 後編
 
Math::Category
Math::CategoryMath::Category
Math::Category
 
AnyEvent and Plack
AnyEvent and PlackAnyEvent and Plack
AnyEvent and Plack
 
Arrows in perl
Arrows in perlArrows in perl
Arrows in perl
 
循環参照のはなし
循環参照のはなし循環参照のはなし
循環参照のはなし
 

Similar to TraitとMoose::Role

Functional Concepts for OOP Developers
Functional Concepts for OOP DevelopersFunctional Concepts for OOP Developers
Functional Concepts for OOP Developersbrweber2
 
Rapid Development with Ruby/JRuby and Rails
Rapid Development with Ruby/JRuby and RailsRapid Development with Ruby/JRuby and Rails
Rapid Development with Ruby/JRuby and Railselliando dias
 
how to hack with pack and unpack
how to hack with pack and unpackhow to hack with pack and unpack
how to hack with pack and unpackDavid Lowe
 
JavaScript 1.5 to 2.0 (TomTom)
JavaScript 1.5 to 2.0 (TomTom)JavaScript 1.5 to 2.0 (TomTom)
JavaScript 1.5 to 2.0 (TomTom)jeresig
 
Introduction To Lisp
Introduction To LispIntroduction To Lisp
Introduction To Lispkyleburton
 
R Workshop for Beginners
R Workshop for BeginnersR Workshop for Beginners
R Workshop for BeginnersMetamarkets
 
A Re-Introduction to JavaScript
A Re-Introduction to JavaScriptA Re-Introduction to JavaScript
A Re-Introduction to JavaScriptSimon Willison
 
Real World Optimization
Real World OptimizationReal World Optimization
Real World OptimizationDavid Golden
 
Concurrent applications with free monads and stm
Concurrent applications with free monads and stmConcurrent applications with free monads and stm
Concurrent applications with free monads and stmAlexander Granin
 
Impacta - Show Day de Rails
Impacta - Show Day de RailsImpacta - Show Day de Rails
Impacta - Show Day de RailsFabio Akita
 

Similar to TraitとMoose::Role (12)

Functional Concepts for OOP Developers
Functional Concepts for OOP DevelopersFunctional Concepts for OOP Developers
Functional Concepts for OOP Developers
 
Rapid Development with Ruby/JRuby and Rails
Rapid Development with Ruby/JRuby and RailsRapid Development with Ruby/JRuby and Rails
Rapid Development with Ruby/JRuby and Rails
 
how to hack with pack and unpack
how to hack with pack and unpackhow to hack with pack and unpack
how to hack with pack and unpack
 
JavaScript 1.5 to 2.0 (TomTom)
JavaScript 1.5 to 2.0 (TomTom)JavaScript 1.5 to 2.0 (TomTom)
JavaScript 1.5 to 2.0 (TomTom)
 
Lisp Primer Key
Lisp Primer KeyLisp Primer Key
Lisp Primer Key
 
Introduction To Lisp
Introduction To LispIntroduction To Lisp
Introduction To Lisp
 
R Workshop for Beginners
R Workshop for BeginnersR Workshop for Beginners
R Workshop for Beginners
 
A Re-Introduction to JavaScript
A Re-Introduction to JavaScriptA Re-Introduction to JavaScript
A Re-Introduction to JavaScript
 
sysprog2 Part1
sysprog2 Part1sysprog2 Part1
sysprog2 Part1
 
Real World Optimization
Real World OptimizationReal World Optimization
Real World Optimization
 
Concurrent applications with free monads and stm
Concurrent applications with free monads and stmConcurrent applications with free monads and stm
Concurrent applications with free monads and stm
 
Impacta - Show Day de Rails
Impacta - Show Day de RailsImpacta - Show Day de Rails
Impacta - Show Day de Rails
 

Recently uploaded

Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piececharlottematthew16
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyAlfredo García Lavilla
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Enterprise Knowledge
 
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostLeverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostZilliz
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Manik S Magar
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningLars Bell
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Mark Simos
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .Alan Dix
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.Curtis Poe
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxLoriGlavin3
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsPixlogix Infotech
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationSlibray Presentation
 
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfHyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfPrecisely
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024Lonnie McRorey
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubKalema Edgar
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxNavinnSomaal
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenHervé Boutemy
 

Recently uploaded (20)

Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piece
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easy
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024
 
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostLeverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!
 
DMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special EditionDMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special Edition
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine Tuning
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and Cons
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
 
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfHyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding Club
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptx
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache Maven
 

TraitとMoose::Role

  • 2. : Moose::Role Perl Java interface ✤ requires API ✤ with API ✤ Perl gihyo.jp ✤ Trait ✤
  • 3. : Mix-in (1) ✤ 3 ( Linux 2005 7 ) Mix-in Lisp ✤
  • 4. : Mix-in (2) Mix-in ✤ ✤ Mix-in ✤ Mix-in ✤ ✤ ✤
  • 5. : Mix-in (3) Ruby SuperClass module MixinA def mixin1 MixinB print quot;Hello Mixin Anquot; end end SubClass module MixinC def mixin2 MixinA MixinC mixin1 print quot;Hello Mixin Cnquot; end SubSubClass end MixinA class SubSubClass < SubClass include MixinA include MixinC end SuperClass2 SubSubClass.new.mixin2
  • 6. Trait OOP ✤ Mix-in ✤ 2002 Traits: Composable Units of Behavior ✤
  • 7. Trait Perl 5(Moose) Perl 6 ✤ JavaScript(Joose) ✤ Java(Scala) ✤ Ruby (module Mix-in ) ✤ Fortress 2006 sun ✤ Smalltalk, PHP, ActionScript 3.0 ✤
  • 8. Trait Mix-in Flatten ✤ (Perl Exporter ) ✤ = Trait ✤ (with, import) ✤ Trait = ✤ Trait ( ) ✤
  • 9. Moose::Role Trait (provided) ✤ (required) ✤ ( OK) ✤ package TaxRole; TaxRole use Moose::Role; requires 'price'; comsumption_tax price our $TAX_RATE = 0.05; tax_inclusive_price sub consumption_tax{ return shift->price * $TAX_RATE; } sub tax_inclusive_price{ my $self = shift; return $self->price + $self->consumption_tax; } no Moose::Role;
  • 10. Moose::Role Trait Trait ✤ required ✤ Goods package Goods; use Moose; price has price => ( isa => 'Int', TaxRole is => 'ro', required => 1, comsumption_tax price ); tax_inclusive_price with 'TaxRole'; no Moose;
  • 11. Trait sum : t1 + t2 ✤ alias : t[a→b] ✤ exclusion : t - a ✤
  • 12. Trait (1) - sum package TraitsA; required + provided = provided ✤ use Moose::Role; required + required = required ✤ with 'TraitsB'; provided + provided = required ( ) ✤ no Moose::Role; TraitA TraitB TraitA += a ⇒ a c d b a b d c c d
  • 13. sum : ... (m, ⊥: ,⟙: ) m1 ⊔ ⟙ = ⟙ → ✤ ✤ ⟘⊔⟙=⟙ ✤ ⟘ ⊔⟘=⟘ ✤ ⟙⊔⟙=⟙ ✤ m1 ⊔ ⟘ = m1 ✤ provided: ⊥ ⟙ ✤ m1 ⊔ m1 = m1 ✤ m1 ⊔ m2 = ⟙ required: - provided ✤ ✤ TraitA TraitB TraitA += a = m3, c = m4 ⇒ a = m1, b = m2 b = m2, c = m4 c = ⟘, d = ⟘ d=⟘ a = ⟙, d = ⟘
  • 14. Trait (2) - alias package AnotherTraits; use Moose::Role; → ✤ with 'TraitsA' => { alias => {a => 'e'}, }; no Moose::Role; TraitA TraitA [e → a] ⇒ a c a c b d b d e
  • 15. Trait (3) - exclusion package AnotherTraits; use Moose::Role; − ✤ with 'TraitsA' => { excludes => ['a'], }; no Moose::Role; TraitA TraitA -= a ⇒ a c b c b d d
  • 16. Trait : package TraitsA; use Moose::Role; TraitA with 'TraitsB' => { a b alias => {b => 'e'}, excludes => ['c'], c }; d e no Moose::Role; TraitA TraitB a d += ( b a [e → b] - c ) b c c d
  • 17. Trait : package TraitsA; use Moose::Role; TraitA with 'TraitsB' => { a b alias => {b => 'e'}, excludes => ['c'], c }; d e no Moose::Role; TraitA TraitB += ( b = e a d a [e → b] - c ) = b c c d
  • 18. Trait ✤ package Trait; package Class; use Moose::Role; use Moose; sub class_vs_trait{ print __PACKAGE__, quot;nquot;; } extends 'SuperClass'; with 'Trait'; sub super_vs_trait{ print __PACKAGE__, quot;nquot;; } sub class_vs_trait{ print __PACKAGE__, quot;nquot;; } no Moose::Role; no Moose; package SuperClass; package main; use Moose; my $c = Class->new; sub super_vs_trait{ print __PACKAGE__, quot;nquot;; } $c->class_vs_trait; no Moose; $c->super_vs_trait;
  • 19. Class 1 SuperClass 1 (∵ ) ✤ Trait Trait ⇒ Trait required ✤ (Mix-in ) ⇒ ✤ ✤ alias exclusion ✤
  • 20. package TraitA; use Moose::Role; package Class; sub vs{ print __PACKAGE__, quot;nquot; } use Moose; no Moose::Role; with 'TraitA', 'TraitB'; no Moose; package TraitB; use Moose::Role; package main; sub vs{ print __PACKAGE__, quot;nquot; } Class->new->vs; no Moose::Role;
  • 21. Trait state( ) Trait ✤ → has ✤ Trait ✤ → ✤
  • 22. Trait ✤ Trait Mix-in ✤

Editor's Notes

  1. &#x30C4;&#x30EA;&#x30FC;&#x7684;&#x3067;&#x306F;&#x306A;&#x304F;&#x3001;&#x52A0;&#x7B97;&#x7684;&#x306B;&#x5408;&#x6210;&#x3059;&#x308B;
  2. &#x3053;&#x3053;&#x3067;&#x3001;&#x4F8B;&#x3068;&#x3057;&#x3066;Traits&#x306E;&#x8AD6;&#x6587;&#x306E;&#x56F3;&#x3092;&#x898B;&#x308B;
  3. provided+provided&#x306F;&#x3001;&#x672C;&#x5F53;&#x306F;&#x7AF6;&#x5408;&#x3002;&#x7AF6;&#x5408;&#x306B;provided&#x3092;&#x52A0;&#x3048;&#x3066;&#x3082;&#x7AF6;&#x5408;&#x306E;&#x307E;&#x307E;(1&#x5F0F;&#x306B;&#x77DB;&#x76FE;)
  4. Moose&#x306E;alias&#x3068;&#x8AD6;&#x6587;&#x5185;&#x306E;&#x8A18;&#x6CD5;&#x306E;&#x5411;&#x304D;&#x304C;&#x9055;&#x3046;&#x306E;&#x3067;&#x6CE8;&#x610F;
  5. &#x7269;&#x4EF6;&#x306E;&#x3088;&#x3046;&#x306A;state&#x304C;&#x4E3B;&#x8981;&#x7D20;&#x3067;&#x3042;&#x308B;&#x30AF;&#x30E9;&#x30B9;&#x7FA4;&#x3067;&#x306F;&#x5B9F;&#x529B;&#x3092;&#x767A;&#x63EE;&#x3057;&#x304D;&#x308C;&#x306A;&#x3044; Trait&#x306F;&#x3001;&#x5B9F;&#x88C5;&#x304C;&#x305F;&#x307E;&#x305F;&#x307E;&#x540C;&#x3058;&#x3082;&#x306E;&#x3092;&#x5171;&#x901A;&#x5316;&#x3059;&#x308B;&#x5834;&#x5408;&#x306B;&#x5F37;&#x529B;&#x3067;&#x3042;&#x308B;&#x3053;&#x3068;&#x306B;&#x6CE8;&#x610F;