Object Meta Programming
YAPC::EU::2007
Aug 29, 2007
HAI FRENDS
My name is Yuval
Meta Programming
Introduction
continued...
Introduction
continued...
Introduction
- Meta programming
- writing code which outputs or manipulates code
Many forms
continued...
Many forms
continued...
Many forms
continued...
Many forms
- string eval
- %::
- closure generators
continued...
Many forms
- string eval
- %::
- closure generators
- macros
continued...
Many forms
- string eval
- %::
- closure generators
- macros
- real macros
continued...
Many forms
- string eval
- %::
- closure generators
- macros
- real macros
- compilers
Many forms
continued...
Many forms
continued...
Many forms
- Home grown snippets
- Home grown packages
continued...
Many forms
- Home grown snippets
- Home grown packages
- Stuff on the CPAN (e.g. Class::Accessor, Code::Perl)
continued...
Many forms
- Home grown snippets
- Home grown packages
- Stuff on the CPAN (e.g. Class::Accessor, Code::Perl)
- Large systems (Template::Toolkit)
Summary
- You should already know it
- You probably do it
continued...
Summary
- You should already know it
- You probably do it
- That's the intended audience anyway ;-)
Object Meta Programming
Object Meta Programming
continued...
Object Meta Programming
- Code that outputs or manipulates object oriented code
continued...
Object Meta Programming
- Code that outputs or manipulates object oriented code
- Often written in OO
Simple Examples
continued...
Simple Examples
- Class::Accessor, Class::InsideOut
continued...
Simple Examples
- Class::Accessor, Class::InsideOut
- Generates accessor methods
continued...
Simple Examples
- Class::Accessor, Class::InsideOut
- Generates accessor methods
- Class::Prototyped
continued...
Simple Examples
- Class::Accessor, Class::InsideOut
- Generates accessor methods
- Class::Prototyped
- Prototype object support in Perl
continued...
Simple Examples
- Class::Accessor, Class::InsideOut
- Generates accessor methods
- Class::Prototyped
- Prototype object support in Perl
- Lots of stuff on the CPAN
Modeling OO
continued...
Modeling OO
- High level object meta programming
continued...
Modeling OO
- High level object meta programming
continued...
Modeling OO
- High level object meta programming
- The current trend
- The picture illustrates an object modelling with class =)
continued...
Modeling OO
- High level object meta programming
- The current trend
- The picture illustrates an object modelling with class =)
- Seriously though...
Modeling OO
- High level object meta programming
- What is a class?
continued...
Modeling OO
- High level object meta programming
- What is a class?
class Class {
has @isa;
has %methods;
has %attributes;
...
}
Modeling OO
continued...
Modeling OO
continued...
Modeling OO
continued...
Modeling OO
- Implementing OO
- Meta objects:
continued...
Modeling OO
- Implementing OO
- Meta objects:
continued...
Modeling OO
- Implementing OO
- Meta objects:
continued...
Modeling OO
- Implementing OO
- Meta objects:
Example class
class Point {
has $x;
has $y;
method distance_to { ... }
}
Modeled with objects
Class->new(
attributes => [
Attribute->new( name => '$x' ),
Attribute->new( name => '$y' ),
],
methods => [
Method->new(
name => "distance_to",
definition => sub { ... }
),
],
);
Metamodel Services
continued...
Metamodel Services
continued...
Metamodel Services
continued...
Metamodel Services
continued...
Metamodel Services
continued...
Metamodel Services
- Form
- Function
- Class generation
- Class transformation
continued...
Metamodel Services
- Form
- Function
- Class generation
- Class transformation
- Pattern packaging
Case Study
Moose
continued...
Case Study
Moose
- A deep meta object system
continued...
Case Study
Moose
- A deep meta object system
- 4 layers deep
continued...
Case Study
Moose
- A deep meta object system
- 4 layers deep
continued...
Case Study
Moose
- A deep meta object system
- 4 layers deep
- Syntactic sugar
- Custom metaclasses
continued...
Case Study
Moose
- A deep meta object system
- 4 layers deep
- Syntactic sugar
- Custom metaclasses
- Class::MOP
continued...
Case Study
Moose
- A deep meta object system
- 4 layers deep
- Syntactic sugar
- Custom metaclasses
- Class::MOP
- Perl's native OO
Perl's native OO
continued...
Perl's native OO
continued...
Perl's native OO
- Minimalistic
- Class = Package = Symbol table hash
- Inheritence tree embedded in @ISA entry
- bless links data to a class
- ->
continued...
Perl's native OO
- Minimalistic
- Class = Package = Symbol table hash
- Inheritence tree embedded in @ISA entry
- bless links data to a class
- ->
- Insanely flexible
continued...
Perl's native OO
- Minimalistic
- Class = Package = Symbol table hash
- Inheritence tree embedded in @ISA entry
- bless links data to a class
- ->
- Insanely flexible
- Pretty klunky
continued...
Perl's native OO
- Minimalistic
- Class = Package = Symbol table hash
- Inheritence tree embedded in @ISA entry
- bless links data to a class
- ->
- Insanely flexible
- Pretty klunky
- Written in C (not very accessible)
Class::MOP
continued...
Class::MOP
- port of CLOS, more or less
continued...
Class::MOP
- port of CLOS, more or less
- MOP = Meta Object Protocol
Class::MOP
continued...
Class::MOP
continued...
Class::MOP
- Model
- Class::MOP::Class
- Class::MOP::Method
- Class::MOP::Attribute
continued...
Class::MOP
- Model
- Class::MOP::Class
- Class::MOP::Method
- Class::MOP::Attribute
- Easy interface
continued...
Class::MOP
- Model
- Class::MOP::Class
- Class::MOP::Method
- Class::MOP::Attribute
- Easy interface
continued...
Class::MOP
- Model
- Class::MOP::Class
- Class::MOP::Method
- Class::MOP::Attribute
- Easy interface
- Introspection
- Transformation
Class::MOP
continued...
Class::MOP
- Can "parse" packages into meta objects
continued...
Class::MOP
- Can "parse" packages into meta objects
- Modifying the objects writes back to packages
continued...
Class::MOP
- Can "parse" packages into meta objects
- Modifying the objects writes back to packages
- Code generation
continued...
Class::MOP
- Can "parse" packages into meta objects
- Modifying the objects writes back to packages
- Code generation
- Accessors from attributes
continued...
Class::MOP
- Can "parse" packages into meta objects
- Modifying the objects writes back to packages
- Code generation
- Accessors from attributes
- Constructor from attributes
continued...
Class::MOP
- Can "parse" packages into meta objects
- Modifying the objects writes back to packages
- Code generation
- Accessors from attributes
- Constructor from attributes
- Method modifiers
Moose's custom metaclasses
continued...
Moose's custom metaclasses
- Subclasses of Class::MOP::Class et al
continued...
Moose's custom metaclasses
- Subclasses of Class::MOP::Class et al
- More fun features
continued...
Moose's custom metaclasses
- Subclasses of Class::MOP::Class et al
- More fun features
continued...
Moose's custom metaclasses
- Subclasses of Class::MOP::Class et al
- More fun features
- Roles
- BUILD etc a la Perl 6
continued...
Moose's custom metaclasses
- Subclasses of Class::MOP::Class et al
- More fun features
- Roles
- BUILD etc a la Perl 6
- Type constraints
Moose sugar layer
continued...
Moose sugar layer
- Pseudo-declarative syntax
continued...
Moose sugar layer
- Pseudo-declarative syntax
- Maps to metaclass manipulations
continued...
Moose sugar layer
- Pseudo-declarative syntax
- Maps to metaclass manipulations
has foo => ( is => "rw" );
continued...
Moose sugar layer
- Pseudo-declarative syntax
- Maps to metaclass manipulations
has foo => ( is => "rw" );
continued...
Moose sugar layer
- Pseudo-declarative syntax
- Maps to metaclass manipulations
has foo => ( is => "rw" );
$metaclass->add_attribute(
Moose::Meta::Attribute->new(
foo => ( is => "rw" ),
)
);
Moose vs. Class::Accessor
continued...
Moose vs. Class::Accessor
- All that bloat just for the has syntax?
continued...
Moose vs. Class::Accessor
- All that bloat just for the has syntax?
- NO!
continued...
Moose vs. Class::Accessor
- All that bloat just for the has syntax?
- NO!
- Pattern packaging
MooseX::
continued...
MooseX::
continued...
MooseX::
- Packaged meta code
- Pretty clean
continued...
MooseX::
- Packaged meta code
- Pretty clean
- Mostly composable
MooseX::
continued...
MooseX::
continued...
MooseX::
- MooseX::Storage
- Customizable serialization through metaprogramming
continued...
MooseX::
- MooseX::Storage
- Customizable serialization through metaprogramming
- MooseX::AttributeHelpers
continued...
MooseX::
- MooseX::Storage
- Customizable serialization through metaprogramming
- MooseX::AttributeHelpers
- Additional methods for collection type attributes
continued...
MooseX::
- MooseX::Storage
- Customizable serialization through metaprogramming
- MooseX::AttributeHelpers
- Additional methods for collection type attributes
- MooseX::Getopt
continued...
MooseX::
- MooseX::Storage
- Customizable serialization through metaprogramming
- MooseX::AttributeHelpers
- Additional methods for collection type attributes
- MooseX::Getopt
- Additional constructor compiles attributes into a Getopt spec
continued...
MooseX::
- MooseX::Storage
- Customizable serialization through metaprogramming
- MooseX::AttributeHelpers
- Additional methods for collection type attributes
- MooseX::Getopt
- Additional constructor compiles attributes into a Getopt spec
- MooseX::IOC
continued...
MooseX::
- MooseX::Storage
- Customizable serialization through metaprogramming
- MooseX::AttributeHelpers
- Additional methods for collection type attributes
- MooseX::Getopt
- Additional constructor compiles attributes into a Getopt spec
- MooseX::IOC
- Inversion of control integrated into the object system
The point of Moose
continued...
The point of Moose
continued...
The point of Moose
- OO is less tedious
- Helps you write meta code
continued...
The point of Moose
- OO is less tedious
- Helps you write meta code
- Good APIs promote clean code
continued...
The point of Moose
- OO is less tedious
- Helps you write meta code
- Good APIs promote clean code
- Easier to build on existing base
continued...
The point of Moose
- OO is less tedious
- Helps you write meta code
- Good APIs promote clean code
- Easier to build on existing base
- Conventions and structure let you play well with others (MooseX::)
continued...
The point of Moose
- OO is less tedious
- Helps you write meta code
- Good APIs promote clean code
- Easier to build on existing base
- Conventions and structure let you play well with others (MooseX::)
- Introspectable & tranformable metamodel
Another Case Study
ORMs
continued...
Another Case Study
ORMs
continued...
Another Case Study
ORMs
- Are HARD
- Not even fun like the picture
ORMs
continued...
ORMs
continued...
ORMs
continued...
ORMs
- Modeling
- Tables <-> Classes
- Fields <-> Attributes
continued...
ORMs
- Modeling
- Tables <-> Classes
- Fields <-> Attributes
- Code Generation
continued...
ORMs
- Modeling
- Tables <-> Classes
- Fields <-> Attributes
- Code Generation
continued...
ORMs
- Modeling
- Tables <-> Classes
- Fields <-> Attributes
- Code Generation
continued...
ORMs
- Modeling
- Tables <-> Classes
- Fields <-> Attributes
- Code Generation
- SQL
- Accessors
- Relationship fetchers
Class::DBI
continued...
Class::DBI
- Meta code is in the base class
continued...
Class::DBI
- Meta code is in the base class
- No clear schema modelling
continued...
Class::DBI
- Meta code is in the base class
- No clear schema modelling
- No separation between regular & meta code
continued...
Class::DBI
- Meta code is in the base class
- No clear schema modelling
- No separation between regular & meta code
- Lots of hacks
continued...
Class::DBI
- Meta code is in the base class
- No clear schema modelling
- No separation between regular & meta code
- Lots of hacks
- Don't go there
DBIx::Class
continued...
DBIx::Class
- Meta enlightened
- Schema objects fully model the SQL side
continued...
DBIx::Class
- Meta enlightened
- Schema objects fully model the SQL side
- ResultSource etc partially model the OO side
continued...
DBIx::Class
- Meta enlightened
- Schema objects fully model the SQL side
- ResultSource etc partially model the OO side
- Components for everything
DBIx::Class
continued...
DBIx::Class
- Meta code:
- Proxy objects
- Accessors
- Code generation (SQL, Perl)
ORM related meta programming
continued...
ORM related meta programming
continued...
ORM related meta programming
Vaporware
MO
continued...
MO
continued...
MO
continued...
MO
- My baby
- Moose spinoff
- Stevan says it's Moose 2.0's
continued...
MO
- My baby
- Moose spinoff
- Stevan says it's Moose 2.0's
- Perl 5 & Haskell (in pugs)
MO Sucks
continued...
MO Sucks
continued...
MO Sucks
- Experimental code
- Boring parts messy or unwritten
continued...
MO Sucks
- Experimental code
- Boring parts messy or unwritten
- Lacking integration, sugar layer
continued...
MO Sucks
- Experimental code
- Boring parts messy or unwritten
- Lacking integration, sugar layer
continued...
MO Sucks
- Experimental code
- Boring parts messy or unwritten
- Lacking integration, sugar layer
- Some parts slow as $*!&%
MO Rocks
continued...
MO Rocks
continued...
MO Rocks
- Purely functional
- Very suited for meta transformations
continued...
MO Rocks
- Purely functional
- Very suited for meta transformations
- Fine grained control over everything
continued...
MO Rocks
- Purely functional
- Very suited for meta transformations
- Fine grained control over everything
- Can introduce entirely new conceptions of OO
MO Architechture
continued...
MO Architechture
continued...
MO Architechture
- Modeling layer
- Corresponds to compilation
continued...
MO Architechture
- Modeling layer
- Corresponds to compilation
- Responder layer
continued...
MO Architechture
- Modeling layer
- Corresponds to compilation
- Responder layer
MO Architechture
continued...
MO Architechture
- Compiler/sugar layer creates the modeling layer
continued...
MO Architechture
- Compiler/sugar layer creates the modeling layer
- Class objects are constructed, with all the details
continued...
MO Architechture
- Compiler/sugar layer creates the modeling layer
- Class objects are constructed, with all the details
- No meta calculations happen yet
continued...
MO Architechture
- Compiler/sugar layer creates the modeling layer
- Class objects are constructed, with all the details
- No meta calculations happen yet
- Modeling layer is "compiled" into responder layer
continued...
MO Architechture
- Compiler/sugar layer creates the modeling layer
- Class objects are constructed, with all the details
- No meta calculations happen yet
- Modeling layer is "compiled" into responder layer
- Can be done on demand or upfront
continued...
MO Architechture
- Compiler/sugar layer creates the modeling layer
- Class objects are constructed, with all the details
- No meta calculations happen yet
- Modeling layer is "compiled" into responder layer
- Can be done on demand or upfront
- Obscurely named objects
continued...
MO Architechture
- Compiler/sugar layer creates the modeling layer
- Class objects are constructed, with all the details
- No meta calculations happen yet
- Modeling layer is "compiled" into responder layer
- Can be done on demand or upfront
- Obscurely named objects
"Concepts"
continued...
"Concepts"
- The purest form of OO is prototypes
continued...
"Concepts"
- The purest form of OO is prototypes
- prototype OO can implement class OO
continued...
"Concepts"
- The purest form of OO is prototypes
- prototype OO can implement class OO
- Concepts are new ways to express objects
continued...
"Concepts"
- The purest form of OO is prototypes
- prototype OO can implement class OO
- Concepts are new ways to express objects
- A class is a concept
continued...
"Concepts"
- The purest form of OO is prototypes
- prototype OO can implement class OO
- Concepts are new ways to express objects
- A class is a concept
- A role is a concept
"Responder Interfaces"
continued...
"Responder Interfaces"
- $ri->dispatch( $responder, $invocation )
continued...
"Responder Interfaces"
- $ri->dispatch( $responder, $invocation )
- Generated from concepts
continued...
"Responder Interfaces"
- $ri->dispatch( $responder, $invocation )
- Generated from concepts
- Abstract VTable
continued...
"Responder Interfaces"
- $ri->dispatch( $responder, $invocation )
- Generated from concepts
- Abstract VTable
- The flattened method hierarchy
continued...
"Responder Interfaces"
- $ri->dispatch( $responder, $invocation )
- Generated from concepts
- Abstract VTable
- The flattened method hierarchy
- ... or something completely different
continued...
"Responder Interfaces"
- $ri->dispatch( $responder, $invocation )
- Generated from concepts
- Abstract VTable
- The flattened method hierarchy
- ... or something completely different
- Performance
continued...
"Responder Interfaces"
- $ri->dispatch( $responder, $invocation )
- Generated from concepts
- Abstract VTable
- The flattened method hierarchy
- ... or something completely different
- Performance
- Flexibility
"Responders"
continued...
"Responders"
- Something that is the subject of invocations
continued...
"Responders"
- Something that is the subject of invocations
continued...
"Responders"
- Something that is the subject of invocations
- An object instance
- A class (class methods)
continued...
"Responders"
- Something that is the subject of invocations
- An object instance
- A class (class methods)
- A simple tuple ( $data, $ri )
"Invocations"
continued...
"Invocations"
- A method call, multimethod, message... whatever
continued...
"Invocations"
- A method call, multimethod, message... whatever
continued...
"Invocations"
- A method call, multimethod, message... whatever
- Whatever an RI will put up with
continued...
"Invocations"
- A method call, multimethod, message... whatever
- Whatever an RI will put up with
- Extensible calling semantics
MO compilation flow
continued...
MO compilation flow
- Instantiate a Class object
continued...
MO compilation flow
- Instantiate a Class object
- Specify members (methods, attributes)
continued...
MO compilation flow
- Instantiate a Class object
- Specify members (methods, attributes)
- ... and ancestor classes & roles
continued...
MO compilation flow
- Instantiate a Class object
- Specify members (methods, attributes)
- ... and ancestor classes & roles
- Compile class
continued...
MO compilation flow
- Instantiate a Class object
- Specify members (methods, attributes)
- ... and ancestor classes & roles
- Compile class
- my $class_methods_ri = $class->class_interface()
continued...
MO compilation flow
- Instantiate a Class object
- Specify members (methods, attributes)
- ... and ancestor classes & roles
- Compile class
- my $class_methods_ri = $class->class_interface()
- Instance method RI closed in the constructor, within $ri
continued...
MO compilation flow
- Instantiate a Class object
- Specify members (methods, attributes)
- ... and ancestor classes & roles
- Compile class
- my $class_methods_ri = $class->class_interface()
- Instance method RI closed in the constructor, within $ri
- Purely functional operation
RI composition
continued...
RI composition
- Compute instance methods and attributes from ancestry
continued...
RI composition
- Compute instance methods and attributes from ancestry
- Compute instance slots from attributes
continued...
RI composition
- Compute instance methods and attributes from ancestry
- Compute instance slots from attributes
- Generate accessors
continued...
RI composition
- Compute instance methods and attributes from ancestry
- Compute instance slots from attributes
- Generate accessors
MO::Run::ResponderInterface::MethodTable->new(
methods => %methods
);
continued...
RI composition
- Compute instance methods and attributes from ancestry
- Compute instance slots from attributes
- Generate accessors
MO::Run::ResponderInterface::MethodTable->new(
methods => %methods
);
continued...
RI composition
- Compute instance methods and attributes from ancestry
- Compute instance slots from attributes
- Generate accessors
MO::Run::ResponderInterface::MethodTable->new(
methods => %methods
);
sub {
my $data = process_params(@_);
return box( $data, $instance_ri );
}
Instantiation
continued...
Instantiation
- Lookup RI using class name
continued...
Instantiation
- Lookup RI using class name
- Dispatch constructor class method
continued...
Instantiation
- Lookup RI using class name
- Dispatch constructor class method
- Compose data from params
continued...
Instantiation
- Lookup RI using class name
- Dispatch constructor class method
- Compose data from params
continued...
Instantiation
- Lookup RI using class name
- Dispatch constructor class method
- Compose data from params
- Link data with closed $instance_ri
continued...
Instantiation
- Lookup RI using class name
- Dispatch constructor class method
- Compose data from params
- Link data with closed $instance_ri
- Responder == ( Data, RI )
continued...
Instantiation
- Lookup RI using class name
- Dispatch constructor class method
- Compose data from params
- Link data with closed $instance_ri
- Responder == ( Data, RI )
- Like bless
Method calls
continued...
Method calls
- How to talk with your new object?
continued...
Method calls
- How to talk with your new object?
my $ri = $responder->responder_interface;
continued...
Method calls
- How to talk with your new object?
my $ri = $responder->responder_interface;
my $method = MO::Run::Invocation::Method->new(
name => "foo"
arguments => \@blah,
);
continued...
Method calls
- How to talk with your new object?
my $ri = $responder->responder_interface;
my $method = MO::Run::Invocation::Method->new(
name => "foo"
arguments => \@blah,
);
$ri->dispatch( $responder, $method );
continued...
Method calls
- How to talk with your new object?
my $ri = $responder->responder_interface;
my $method = MO::Run::Invocation::Method->new(
name => "foo"
arguments => \@blah,
);
$ri->dispatch( $responder, $method );
- Arbitrary responder interfaces also allowed
continued...
Method calls
- How to talk with your new object?
my $ri = $responder->responder_interface;
my $method = MO::Run::Invocation::Method->new(
name => "foo"
arguments => \@blah,
);
$ri->dispatch( $responder, $method );
- Arbitrary responder interfaces also allowed
- Doesn't have to be $responder->responder_interface
OH NOES!!!
continued...
OH NOES!!!
- What's wrong with the previous slide?
continued...
OH NOES!!!
- What's wrong with the previous slide?
- RIs are objects too!
continued...
OH NOES!!!
- What's wrong with the previous slide?
- RIs are objects too!
- Need to bootstrap method calls
continued...
OH NOES!!!
- What's wrong with the previous slide?
- RIs are objects too!
- Need to bootstrap method calls
- Runtime must bootstrap low level OO
continued...
OH NOES!!!
- What's wrong with the previous slide?
- RIs are objects too!
- Need to bootstrap method calls
- Runtime must bootstrap low level OO
Meta level polymorphism
continued...
Meta level polymorphism
continued...
Meta level polymorphism
continued...
Meta level polymorphism
- An important point
- Responder interfaces are polymorphic
continued...
Meta level polymorphism
- An important point
- Responder interfaces are polymorphic
- Method table, network proxy, whatever
continued...
Meta level polymorphism
- An important point
- Responder interfaces are polymorphic
- Method table, network proxy, whatever
- Easy to specialize
continued...
Meta level polymorphism
- An important point
- Responder interfaces are polymorphic
- Method table, network proxy, whatever
- Easy to specialize
continued...
Meta level polymorphism
- An important point
- Responder interfaces are polymorphic
- Method table, network proxy, whatever
- Easy to specialize
- Optimizations
- Strange features
continued...
Meta level polymorphism
- An important point
- Responder interfaces are polymorphic
- Method table, network proxy, whatever
- Easy to specialize
- Optimizations
- Strange features
- Easy to mix several OO systems
continued...
Meta level polymorphism
- An important point
- Responder interfaces are polymorphic
- Method table, network proxy, whatever
- Easy to specialize
- Optimizations
- Strange features
- Easy to mix several OO systems
- Just compile to separate RIs
MO in Perl 5
continued...
MO in Perl 5
continued...
MO in Perl 5
- Two runtimes
- Very different
continued...
MO in Perl 5
- Two runtimes
- Very different
- MO::Run::Aux wraps both
continued...
MO in Perl 5
- Two runtimes
- Very different
- MO::Run::Aux wraps both
- Share tests by running with different %ENV var
Hosted runtime
continued...
Hosted runtime
continued...
Hosted runtime
- Nested object system
- Bootstraps with Perl 5
continued...
Hosted runtime
- Nested object system
- Bootstraps with Perl 5
- Native Perl OO == Low level, like VM opcodes
continued...
Hosted runtime
- Nested object system
- Bootstraps with Perl 5
- Native Perl OO == Low level, like VM opcodes
- Virtualized MO == High Level
continued...
Hosted runtime
- Nested object system
- Bootstraps with Perl 5
- Native Perl OO == Low level, like VM opcodes
- Virtualized MO == High Level
- Completely separate levels
continued...
Hosted runtime
- Nested object system
- Bootstraps with Perl 5
- Native Perl OO == Low level, like VM opcodes
- Virtualized MO == High Level
- Completely separate levels
- $ri->dispatch( $responder, $method )
continued...
Hosted runtime
- Nested object system
- Bootstraps with Perl 5
- Native Perl OO == Low level, like VM opcodes
- Virtualized MO == High Level
- Completely separate levels
- $ri->dispatch( $responder, $method )
- not $responder->$method()
continued...
Hosted runtime
- Nested object system
- Bootstraps with Perl 5
- Native Perl OO == Low level, like VM opcodes
- Virtualized MO == High Level
- Completely separate levels
- $ri->dispatch( $responder, $method )
- not $responder->$method()
- Full expressiveness
continued...
Hosted runtime
- Nested object system
- Bootstraps with Perl 5
- Native Perl OO == Low level, like VM opcodes
- Virtualized MO == High Level
- Completely separate levels
- $ri->dispatch( $responder, $method )
- not $responder->$method()
- Full expressiveness
- Slow, verbose
Native runtime
continued...
Native runtime
continued...
Native runtime
- Integrated object system
- RIs are compiled into packages
continued...
Native runtime
- Integrated object system
- RIs are compiled into packages
- Simple RIs are dissassembled and stuffed into the stash
continued...
Native runtime
- Integrated object system
- RIs are compiled into packages
- Simple RIs are dissassembled and stuffed into the stash
- Complex RIs use AUTOLOAD, delegating to the RI meta object
continued...
Native runtime
- Integrated object system
- RIs are compiled into packages
- Simple RIs are dissassembled and stuffed into the stash
- Complex RIs use AUTOLOAD, delegating to the RI meta object
- Only named method calls
continued...
Native runtime
- Integrated object system
- RIs are compiled into packages
- Simple RIs are dissassembled and stuffed into the stash
- Complex RIs use AUTOLOAD, delegating to the RI meta object
- Only named method calls
- No arbitrary call concepts
continued...
Native runtime
- Integrated object system
- RIs are compiled into packages
- Simple RIs are dissassembled and stuffed into the stash
- Complex RIs use AUTOLOAD, delegating to the RI meta object
- Only named method calls
- No arbitrary call concepts
- -> doesn't support anything else
continued...
Native runtime
- Integrated object system
- RIs are compiled into packages
- Simple RIs are dissassembled and stuffed into the stash
- Complex RIs use AUTOLOAD, delegating to the RI meta object
- Only named method calls
- No arbitrary call concepts
- -> doesn't support anything else
- As fast as "regular" Perl OO
continued...
Native runtime
- Integrated object system
- RIs are compiled into packages
- Simple RIs are dissassembled and stuffed into the stash
- Complex RIs use AUTOLOAD, delegating to the RI meta object
- Only named method calls
- No arbitrary call concepts
- -> doesn't support anything else
- As fast as "regular" Perl OO
- Even makes simple, standalone `.pmc`s
Perl 5 Runtimes
continued...
Perl 5 Runtimes
continued...
Perl 5 Runtimes
- Native
- Usable with regular Perl OO ☺
continued...
Perl 5 Runtimes
- Native
- Usable with regular Perl OO ☺
- Lacks arbitrary invocations ☹
continued...
Perl 5 Runtimes
- Native
- Usable with regular Perl OO ☺
- Lacks arbitrary invocations ☹
- Virtualized
continued...
Perl 5 Runtimes
- Native
- Usable with regular Perl OO ☺
- Lacks arbitrary invocations ☹
- Virtualized
continued...
Perl 5 Runtimes
- Native
- Usable with regular Perl OO ☺
- Lacks arbitrary invocations ☹
- Virtualized
- Feature complete ☺
- Doesn't integrate ☹
continued...
Perl 5 Runtimes
- Native
- Usable with regular Perl OO ☺
- Lacks arbitrary invocations ☹
- Virtualized
- Feature complete ☺
- Doesn't integrate ☹
- Slow ☹
Idealized MO toolchain
continued...
Idealized MO toolchain
- Compiler handles modeling
continued...
Idealized MO toolchain
- Compiler handles modeling
- Constructs meta objects at compile time
continued...
Idealized MO toolchain
- Compiler handles modeling
- Constructs meta objects at compile time
- VM Opcodes support standard RI
continued...
Idealized MO toolchain
- Compiler handles modeling
- Constructs meta objects at compile time
- VM Opcodes support standard RI
- Custom RIs are just objects
continued...
Idealized MO toolchain
- Compiler handles modeling
- Constructs meta objects at compile time
- VM Opcodes support standard RI
- Custom RIs are just objects
- Bootstrapped using standard runtime objects
continued...
Idealized MO toolchain
- Compiler handles modeling
- Constructs meta objects at compile time
- VM Opcodes support standard RI
- Custom RIs are just objects
- Bootstrapped using standard runtime objects
continued...
Idealized MO toolchain
- Compiler handles modeling
- Constructs meta objects at compile time
- VM Opcodes support standard RI
- Custom RIs are just objects
- Bootstrapped using standard runtime objects
- Method table RI
- Named method invocation
Perl 6
continued...
Perl 6
- Perl 6 is the idealized MO toolchain
continued...
Perl 6
- Perl 6 is the idealized MO toolchain
continued...
Perl 6
- Perl 6 is the idealized MO toolchain
continued...
Perl 6
- Perl 6 is the idealized MO toolchain
- Can introduce syntax
- Invocation types
- Concept declarations
continued...
Perl 6
- Perl 6 is the idealized MO toolchain
- Can introduce syntax
- Invocation types
- Concept declarations
- Implement bootstrap RIs in VM opcodes
continued...
Perl 6
- Perl 6 is the idealized MO toolchain
- Can introduce syntax
- Invocation types
- Concept declarations
- Implement bootstrap RIs in VM opcodes
- Pugs might be using MO
continued...
Perl 6
- Perl 6 is the idealized MO toolchain
- Can introduce syntax
- Invocation types
- Concept declarations
- Implement bootstrap RIs in VM opcodes
- Pugs might be using MO
continued...
Perl 6
- Perl 6 is the idealized MO toolchain
- Can introduce syntax
- Invocation types
- Concept declarations
- Implement bootstrap RIs in VM opcodes
- Pugs might be using MO
- I'm not really sure
- It was ported a while ago
Introducing new concepts
continued...
Introducing new concepts
continued...
Introducing new concepts
- Roles are the shit
- But what about next week's fad?
continued...
Introducing new concepts
- Roles are the shit
- But what about next week's fad?
- MO lets you introduce a new concept
continued...
Introducing new concepts
- Roles are the shit
- But what about next week's fad?
- MO lets you introduce a new concept
- Arbitrary at compile time
continued...
Introducing new concepts
- Roles are the shit
- But what about next week's fad?
- MO lets you introduce a new concept
- Arbitrary at compile time
- RI protocol at runtime
Example - Prototype Objects
continued...
Example - Prototype Objects
sub dispatch {
my ( $object, $invocation ) = @_;
my $method = $object->{ $invocation->name };
$object->$method( $invocation->arguments );
}
Example - Attribute Grammars
continued...
Example - Attribute Grammars
- Crazy stuff from the 1970s
continued...
Example - Attribute Grammars
- Crazy stuff from the 1970s
- Renewed interest in λ land
continued...
Example - Attribute Grammars
- Crazy stuff from the 1970s
- Renewed interest in λ land
- Was pretty easy in MO
Attribute Grammer Implementation
continued...
Attribute Grammer Implementation
- Introduce new concept objects
continued...
Attribute Grammer Implementation
- Introduce new concept objects
continued...
Attribute Grammer Implementation
- Introduce new concept objects
- Attribute Grammar
- Attribute Grammer Instance - one per AG per class
continued...
Attribute Grammer Implementation
- Introduce new concept objects
- Attribute Grammar
- Attribute Grammer Instance - one per AG per class
- Runtime specialized RI
continued...
Attribute Grammer Implementation
- Introduce new concept objects
- Attribute Grammar
- Attribute Grammer Instance - one per AG per class
- Runtime specialized RI
- Shadows any RI with additional context sensitive methods
continued...
Attribute Grammer Implementation
- Introduce new concept objects
- Attribute Grammar
- Attribute Grammer Instance - one per AG per class
- Runtime specialized RI
- Shadows any RI with additional context sensitive methods
- Additional runtime support code
MO TODO
continued...
MO TODO
continued...
MO TODO
continued...
MO TODO
- Write a sugar layer
- Tests
continued...
MO TODO
- Write a sugar layer
- Tests
- Refactor the Class objects
continued...
MO TODO
- Write a sugar layer
- Tests
- Refactor the Class objects
continued...
MO TODO
- Write a sugar layer
- Tests
- Refactor the Class objects
- Bloated example code
- There are some patterns to extract
continued...
MO TODO
- Write a sugar layer
- Tests
- Refactor the Class objects
- Bloated example code
- There are some patterns to extract
- Self hosting
Self Hosting
continued...
Self Hosting
- Easier to maintain MO written in Moose
continued...
Self Hosting
- Easier to maintain MO written in Moose
- Need to have clean syntax
continued...
Self Hosting
- Easier to maintain MO written in Moose
- Need to have clean syntax
- Stable .pmc compilation
Conclusion
continued...
Conclusion
- Meta code is awesome code
continued...
Conclusion
- Meta code is awesome code
- Especially my meta code ;-)
Conclusion
- Meta code is awesome code
continued...
Conclusion
- Meta code is awesome code
- Lets you program in new ways
continued...
Conclusion
- Meta code is awesome code
- Lets you program in new ways
- Helps you take care of your other code
continued...
Conclusion
- Meta code is awesome code
- Lets you program in new ways
- Helps you take care of your other code
- Meta code is important code
continued...
Conclusion
- Meta code is awesome code
- Lets you program in new ways
- Helps you take care of your other code
- Meta code is important code
continued...
Conclusion
- Meta code is awesome code
- Lets you program in new ways
- Helps you take care of your other code
- Meta code is important code
- It can affect anything
- Keep it minimalistic, and clearly defined
continued...
Conclusion
- Meta code is awesome code
- Lets you program in new ways
- Helps you take care of your other code
- Meta code is important code
- It can affect anything
- Keep it minimalistic, and clearly defined
- No spaghetti monsters
continued...
Conclusion
- Meta code is awesome code
- Lets you program in new ways
- Helps you take care of your other code
- Meta code is important code
- It can affect anything
- Keep it minimalistic, and clearly defined
- No spaghetti monsters
- Meta code can be simple
continued...
Conclusion
- Meta code is awesome code
- Lets you program in new ways
- Helps you take care of your other code
- Meta code is important code
- It can affect anything
- Keep it minimalistic, and clearly defined
- No spaghetti monsters
- Meta code can be simple
- Only complicated if you aren't careful
BIE FRENDS