SlideShare a Scribd company logo
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 Haskell
nebuta
 
Actionsscript cheat sheet_letter
Actionsscript cheat sheet_letterActionsscript cheat sheet_letter
Actionsscript cheat sheet_letter
Radik 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
 
JSTLQuick Reference
JSTLQuick ReferenceJSTLQuick Reference
JSTLQuick Reference
Hicham QAISSI
 
MiamiJS - The Future of JavaScript
MiamiJS - The Future of JavaScriptMiamiJS - The Future of JavaScript
MiamiJS - The Future of JavaScript
Caridy 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
 
Groovy
GroovyGroovy
Groovy
Zen Urban
 
Go &lt;-> Ruby
Go &lt;-> RubyGo &lt;-> Ruby
Go &lt;-> Ruby
Eleanor McHugh
 
Android Guava
Android GuavaAndroid Guava
Android Guava
丞廷 鄭
 
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

Monads in perl
Monads in perlMonads in perl
Monads in perl
Masahiro Honma
 
すべてが@__kanになる
すべてが@__kanになるすべてが@__kanになる
すべてが@__kanになる
Masahiro Honma
 
モデルから知るGit
モデルから知るGitモデルから知るGit
モデルから知るGit
Masahiro Honma
 
レンズ (ぶつかり稽古の没プレゼン)
レンズ (ぶつかり稽古の没プレゼン)レンズ (ぶつかり稽古の没プレゼン)
レンズ (ぶつかり稽古の没プレゼン)
Masahiro Honma
 
カレーとHokkaidopm
カレーとHokkaidopmカレーとHokkaidopm
カレーとHokkaidopm
Masahiro Honma
 
Perl saved a lady.
Perl saved a lady.Perl saved a lady.
Perl saved a lady.
Masahiro Honma
 
20120526 hachioji.pm
20120526 hachioji.pm20120526 hachioji.pm
20120526 hachioji.pm
Masahiro Honma
 
Git入門
Git入門Git入門
Git入門
Masahiro Honma
 
Hachioji.pm in Machida の LT
Hachioji.pm in Machida の LTHachioji.pm in Machida の LT
Hachioji.pm in Machida の LT
Masahiro Honma
 
Stateモナドの解説 中編
Stateモナドの解説 中編Stateモナドの解説 中編
Stateモナドの解説 中編Masahiro Honma
 
Types and perl language
Types and perl languageTypes and perl language
Types and perl language
Masahiro Honma
 
ウヰスキーとPSGI
ウヰスキーとPSGIウヰスキーとPSGI
ウヰスキーとPSGI
Masahiro Honma
 
モナモナ言うモナド入門.tar.gz
モナモナ言うモナド入門.tar.gzモナモナ言うモナド入門.tar.gz
モナモナ言うモナド入門.tar.gz
Masahiro Honma
 
定理3
定理3定理3
定理3
Masahiro Honma
 
Stateモナドの解説 前編
Stateモナドの解説 前編Stateモナドの解説 前編
Stateモナドの解説 前編Masahiro Honma
 
Stateモナドの解説 後編
Stateモナドの解説 後編Stateモナドの解説 後編
Stateモナドの解説 後編Masahiro Honma
 
Math::Category
Math::CategoryMath::Category
Math::Category
Masahiro Honma
 
AnyEvent and Plack
AnyEvent and PlackAnyEvent and Plack
AnyEvent and Plack
Masahiro Honma
 
Arrows in perl
Arrows in perlArrows in perl
Arrows in perl
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 Developers
brweber2
 
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 Lisp
kyleburton
 
R Workshop for Beginners
R Workshop for BeginnersR Workshop for Beginners
R Workshop for Beginners
Metamarkets
 
A Re-Introduction to JavaScript
A Re-Introduction to JavaScriptA Re-Introduction to JavaScript
A Re-Introduction to JavaScript
Simon Willison
 
sysprog2 Part1
sysprog2 Part1sysprog2 Part1
sysprog2 Part1
Ahmed Mekkawy
 
Real World Optimization
Real World OptimizationReal World Optimization
Real World Optimization
David 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 stm
Alexander Granin
 
Impacta - Show Day de Rails
Impacta - Show Day de RailsImpacta - Show Day de Rails
Impacta - Show Day de Rails
Fabio 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

Removing Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software FuzzingRemoving Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software Fuzzing
Aftab Hussain
 
Large Language Model (LLM) and it’s Geospatial Applications
Large Language Model (LLM) and it’s Geospatial ApplicationsLarge Language Model (LLM) and it’s Geospatial Applications
Large Language Model (LLM) and it’s Geospatial Applications
Rohit Gautam
 
UiPath Test Automation using UiPath Test Suite series, part 5
UiPath Test Automation using UiPath Test Suite series, part 5UiPath Test Automation using UiPath Test Suite series, part 5
UiPath Test Automation using UiPath Test Suite series, part 5
DianaGray10
 
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
DanBrown980551
 
Essentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FMEEssentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FME
Safe Software
 
RESUME BUILDER APPLICATION Project for students
RESUME BUILDER APPLICATION Project for studentsRESUME BUILDER APPLICATION Project for students
RESUME BUILDER APPLICATION Project for students
KAMESHS29
 
Video Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the FutureVideo Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the Future
Alpen-Adria-Universität
 
Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !
KatiaHIMEUR1
 
Artificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopmentArtificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopment
Octavian Nadolu
 
Free Complete Python - A step towards Data Science
Free Complete Python - A step towards Data ScienceFree Complete Python - A step towards Data Science
Free Complete Python - A step towards Data Science
RinaMondal9
 
Generative AI Deep Dive: Advancing from Proof of Concept to Production
Generative AI Deep Dive: Advancing from Proof of Concept to ProductionGenerative AI Deep Dive: Advancing from Proof of Concept to Production
Generative AI Deep Dive: Advancing from Proof of Concept to Production
Aggregage
 
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
Neo4j
 
Uni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems Copilot event_05062024_C.Vlachos.pdfUni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems S.M.S.A.
 
How to Get CNIC Information System with Paksim Ga.pptx
How to Get CNIC Information System with Paksim Ga.pptxHow to Get CNIC Information System with Paksim Ga.pptx
How to Get CNIC Information System with Paksim Ga.pptx
danishmna97
 
Climate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing DaysClimate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing Days
Kari Kakkonen
 
Epistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI supportEpistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI support
Alan Dix
 
GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024
GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024
GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024
Neo4j
 
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdfObservability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Paige Cruz
 
Pushing the limits of ePRTC: 100ns holdover for 100 days
Pushing the limits of ePRTC: 100ns holdover for 100 daysPushing the limits of ePRTC: 100ns holdover for 100 days
Pushing the limits of ePRTC: 100ns holdover for 100 days
Adtran
 
GraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge GraphGraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge Graph
Guy Korland
 

Recently uploaded (20)

Removing Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software FuzzingRemoving Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software Fuzzing
 
Large Language Model (LLM) and it’s Geospatial Applications
Large Language Model (LLM) and it’s Geospatial ApplicationsLarge Language Model (LLM) and it’s Geospatial Applications
Large Language Model (LLM) and it’s Geospatial Applications
 
UiPath Test Automation using UiPath Test Suite series, part 5
UiPath Test Automation using UiPath Test Suite series, part 5UiPath Test Automation using UiPath Test Suite series, part 5
UiPath Test Automation using UiPath Test Suite series, part 5
 
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
 
Essentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FMEEssentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FME
 
RESUME BUILDER APPLICATION Project for students
RESUME BUILDER APPLICATION Project for studentsRESUME BUILDER APPLICATION Project for students
RESUME BUILDER APPLICATION Project for students
 
Video Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the FutureVideo Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the Future
 
Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !
 
Artificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopmentArtificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopment
 
Free Complete Python - A step towards Data Science
Free Complete Python - A step towards Data ScienceFree Complete Python - A step towards Data Science
Free Complete Python - A step towards Data Science
 
Generative AI Deep Dive: Advancing from Proof of Concept to Production
Generative AI Deep Dive: Advancing from Proof of Concept to ProductionGenerative AI Deep Dive: Advancing from Proof of Concept to Production
Generative AI Deep Dive: Advancing from Proof of Concept to Production
 
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
 
Uni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems Copilot event_05062024_C.Vlachos.pdfUni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems Copilot event_05062024_C.Vlachos.pdf
 
How to Get CNIC Information System with Paksim Ga.pptx
How to Get CNIC Information System with Paksim Ga.pptxHow to Get CNIC Information System with Paksim Ga.pptx
How to Get CNIC Information System with Paksim Ga.pptx
 
Climate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing DaysClimate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing Days
 
Epistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI supportEpistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI support
 
GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024
GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024
GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024
 
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdfObservability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
 
Pushing the limits of ePRTC: 100ns holdover for 100 days
Pushing the limits of ePRTC: 100ns holdover for 100 daysPushing the limits of ePRTC: 100ns holdover for 100 days
Pushing the limits of ePRTC: 100ns holdover for 100 days
 
GraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge GraphGraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge Graph
 

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;