SlideShare uma empresa Scribd logo
1 de 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
✤

Mais conteúdo relacionado

Mais procurados

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
 

Mais procurados (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(서피스플링거서비스초기화)
 

Destaque

すべてが@__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
 

Destaque (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
 
循環参照のはなし
循環参照のはなし循環参照のはなし
循環参照のはなし
 

Semelhante a 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
 

Semelhante a 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
 

Último

Evaluating the top large language models.pdf
Evaluating the top large language models.pdfEvaluating the top large language models.pdf
Evaluating the top large language models.pdfChristopherTHyatt
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUK Journal
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfEnterprise Knowledge
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEarley Information Science
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024The Digital Insurer
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Servicegiselly40
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
Tech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfTech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfhans926745
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 

Último (20)

Evaluating the top large language models.pdf
Evaluating the top large language models.pdfEvaluating the top large language models.pdf
Evaluating the top large language models.pdf
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Tech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfTech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdf
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 

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 ✤

Notas do Editor

  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;