SlideShare a Scribd company logo
Moo, the universe and everything… 
Cincinnati.pm 
Henry Van Styn 
<vanstyn@cpan.org> 
Wednesday, 22 October, 2014
Agenda 
• Overview of Moo 
• Differences between Moo and Moose 
• Moosey concepts 
• Within the larger context of Perl OO 
• Some useful patterns (and anti-patterns)
Moo is… 
• Light version of Moose 
• Object system for Perl written in Perl 
• Sugar 
• Result of lessons learned from Moose, Mouse 
MooseX, etc 
• Current state-of-the-art*
Differences from Moose 
• Smaller set of features (~2/3 of Moose) 
• “Less is more” 
• Faster startup, more straightforward APIs 
• Types - simple CodeRef interface* 
• also use CodeRefs for default, coerce, etc…*
Moosey concepts 
• Declarative OO 
• MOP 
• Provides additional, higher-level object concepts: 
attributes, roles, method modifiers 
• Perl is still perl: classes (packages), methods, 
inheritance, blessed references
Peeling back the onion -- Perl OO… 
• “Bag of functions” 
• classes == packages + inheritance 
• blessed refs: attach data to a class == objects 
• runtime introspection and modification…
class-based OO 
• Push package names on @ISA (inheritance) 
• Early sugar: use base, use parent 
Some::Class::method(); 
# ^^ calls method() in Some::Class 
Some::Class->method(); 
# ^^ calls method() in Some::Class 
# - or the next parent of Some::Class * 
# - with ‘Some::Class’ passed as the first argument
object-based OO 
my $obj = bless($ref, ’Some::Class’); 
$obj->method(); 
# ^^ calls method() in Some::Class 
# - or the next parent of Some::Class * 
# - with $obj passed as the first argument 
# - $obj is like a merger of $ref and ‘Some::Class’
Multiple Inheritance 
• Push multiple package names on @ISA 
• Which is the “next parent” ? 
• Flattened (linearized) according to ‘MRO’ 
use mro ‘c3’; 
# ^^ Don’t be stupid 
# next::method() is now a thing 
# MRO::Compat before Perl 5.10 
# perldoc mro
constructors 
• Perl doesn’t have or need the concept 
• Do it however you want 
sub new { 
my $class = shift; 
bless({},$class); 
}
object attributes, etc 
• Perl doesn’t have or need the concept 
• Do it however you want 
sub thing { 
my ($self,$new_val) = @_; 
$self->{thing} = $new_val if ($new_val); 
$self->{thing} 
}
What Moo does 
• Sugar to write classes following a specific pattern 
• Designed to be instantiated into objects (via new) 
• Subclass using ‘extends’ 
• Declare attributes with ‘has’
How it does it 
• Uses introspection to modify the package 
• ‘extends’ modifies @ISA like base and parent 
• ‘has’ adds/changes methods
Roles (‘with’) 
• Also uses introspection to add/modify methods 
• Accomplish MI like designs w/o actually using Perl’s 
“MI” 
• No need to worry about MRO 
• You can still do MI if you really want to: 
pass multiple class names to ‘extends’ 
• But don’t - just use Roles
Method-Modifiers 
• Access MI concepts but also w/o worry about MRO 
around ‘foo’ => sub { 
my ($orig,$self,@args) = @_; 
$self->$orig(@args) 
}; 
sub foo { 
my $self = shift; 
$self->next::method(@_) 
}
Useful patterns 
• Chaining (like DBIC ResultSets) 
• Methods written to work on class or object 
• Using class names as params 
• Type::Tiny for types 
• Coercions
When to use Moo 
• When writing object classes 
• When extending anything 
• Extend Moose classes
Anti-Patterns 
• Getting too carried away 
• Doing things for dogma rather than benefit 
• Forgetting you are still writing Perl (and that it is 
wonderful) 
• There really is more than one way to do it
Code Examples 
https://github.com/vanstyn/LJ-moose-article-examples 
https://github.com/vanstyn/DBIx-Class-Schema-Diff 
https://github.com/vanstyn/Hash-Layout

More Related Content

KEY
GeekAustin PHP Class - Session 6
PPTX
Ruby :: Training 1
PPT
Java01
PPT
Java intro
PPT
PPT
RIBBUN SOFTWARE
PPT
Introduction what is java
GeekAustin PHP Class - Session 6
Ruby :: Training 1
Java01
Java intro
RIBBUN SOFTWARE
Introduction what is java

What's hot (8)

PPTX
Ruby object model - Understanding of object play role for ruby
PPT
java-corporate-training-institute-in-mumbai
PPTX
PyData Ljubljana meetup #1
PPTX
OOP and JavaScript
KEY
Introduction to JRuby
PDF
Php Training Canada
PPTX
Type script
Ruby object model - Understanding of object play role for ruby
java-corporate-training-institute-in-mumbai
PyData Ljubljana meetup #1
OOP and JavaScript
Introduction to JRuby
Php Training Canada
Type script
Ad

Similar to Moo the universe and everything (20)

KEY
Introduction To Moose
PDF
OO Perl with Moose
ODP
Object-Oriented Programming with Perl and Moose
KEY
Intro To Moose
ODP
use Moose; &focus_on_actual_problem_solving
PDF
Moose
PDF
Perl objects 101
PDF
Introduction to OO Perl with Moose
PDF
P6 OO vs Moose (&Moo)
ODP
Moose - YAPC::NA 2012
PDF
Moo at System::Image::Update
ODP
Moose talk at FOSDEM 2011 (Perl devroom)
ODP
Perl Teach-In (part 2)
KEY
Perl: Hate it for the Right Reasons
PDF
Make Your Own Perl with Moops
PDF
Moose Design Patterns
PDF
Perl object ?
PDF
Modern Web Development in Perl
PDF
Moose workshop
Introduction To Moose
OO Perl with Moose
Object-Oriented Programming with Perl and Moose
Intro To Moose
use Moose; &focus_on_actual_problem_solving
Moose
Perl objects 101
Introduction to OO Perl with Moose
P6 OO vs Moose (&Moo)
Moose - YAPC::NA 2012
Moo at System::Image::Update
Moose talk at FOSDEM 2011 (Perl devroom)
Perl Teach-In (part 2)
Perl: Hate it for the Right Reasons
Make Your Own Perl with Moops
Moose Design Patterns
Perl object ?
Modern Web Development in Perl
Moose workshop
Ad

Recently uploaded (20)

PDF
AI in Product Development-omnex systems
PPTX
Operating system designcfffgfgggggggvggggggggg
PDF
Adobe Premiere Pro 2025 (v24.5.0.057) Crack free
PDF
Addressing The Cult of Project Management Tools-Why Disconnected Work is Hold...
PDF
Digital Strategies for Manufacturing Companies
PDF
Adobe Illustrator 28.6 Crack My Vision of Vector Design
PDF
2025 Textile ERP Trends: SAP, Odoo & Oracle
PPTX
Transform Your Business with a Software ERP System
PDF
Navsoft: AI-Powered Business Solutions & Custom Software Development
PDF
Understanding Forklifts - TECH EHS Solution
PDF
Nekopoi APK 2025 free lastest update
PDF
EN-Survey-Report-SAP-LeanIX-EA-Insights-2025.pdf
PPTX
ai tools demonstartion for schools and inter college
PDF
T3DD25 TYPO3 Content Blocks - Deep Dive by André Kraus
PPTX
Introduction to Artificial Intelligence
PDF
System and Network Administration Chapter 2
PDF
Raksha Bandhan Grocery Pricing Trends in India 2025.pdf
PPTX
L1 - Introduction to python Backend.pptx
PDF
Upgrade and Innovation Strategies for SAP ERP Customers
PDF
System and Network Administraation Chapter 3
AI in Product Development-omnex systems
Operating system designcfffgfgggggggvggggggggg
Adobe Premiere Pro 2025 (v24.5.0.057) Crack free
Addressing The Cult of Project Management Tools-Why Disconnected Work is Hold...
Digital Strategies for Manufacturing Companies
Adobe Illustrator 28.6 Crack My Vision of Vector Design
2025 Textile ERP Trends: SAP, Odoo & Oracle
Transform Your Business with a Software ERP System
Navsoft: AI-Powered Business Solutions & Custom Software Development
Understanding Forklifts - TECH EHS Solution
Nekopoi APK 2025 free lastest update
EN-Survey-Report-SAP-LeanIX-EA-Insights-2025.pdf
ai tools demonstartion for schools and inter college
T3DD25 TYPO3 Content Blocks - Deep Dive by André Kraus
Introduction to Artificial Intelligence
System and Network Administration Chapter 2
Raksha Bandhan Grocery Pricing Trends in India 2025.pdf
L1 - Introduction to python Backend.pptx
Upgrade and Innovation Strategies for SAP ERP Customers
System and Network Administraation Chapter 3

Moo the universe and everything

  • 1. Moo, the universe and everything… Cincinnati.pm Henry Van Styn <vanstyn@cpan.org> Wednesday, 22 October, 2014
  • 2. Agenda • Overview of Moo • Differences between Moo and Moose • Moosey concepts • Within the larger context of Perl OO • Some useful patterns (and anti-patterns)
  • 3. Moo is… • Light version of Moose • Object system for Perl written in Perl • Sugar • Result of lessons learned from Moose, Mouse MooseX, etc • Current state-of-the-art*
  • 4. Differences from Moose • Smaller set of features (~2/3 of Moose) • “Less is more” • Faster startup, more straightforward APIs • Types - simple CodeRef interface* • also use CodeRefs for default, coerce, etc…*
  • 5. Moosey concepts • Declarative OO • MOP • Provides additional, higher-level object concepts: attributes, roles, method modifiers • Perl is still perl: classes (packages), methods, inheritance, blessed references
  • 6. Peeling back the onion -- Perl OO… • “Bag of functions” • classes == packages + inheritance • blessed refs: attach data to a class == objects • runtime introspection and modification…
  • 7. class-based OO • Push package names on @ISA (inheritance) • Early sugar: use base, use parent Some::Class::method(); # ^^ calls method() in Some::Class Some::Class->method(); # ^^ calls method() in Some::Class # - or the next parent of Some::Class * # - with ‘Some::Class’ passed as the first argument
  • 8. object-based OO my $obj = bless($ref, ’Some::Class’); $obj->method(); # ^^ calls method() in Some::Class # - or the next parent of Some::Class * # - with $obj passed as the first argument # - $obj is like a merger of $ref and ‘Some::Class’
  • 9. Multiple Inheritance • Push multiple package names on @ISA • Which is the “next parent” ? • Flattened (linearized) according to ‘MRO’ use mro ‘c3’; # ^^ Don’t be stupid # next::method() is now a thing # MRO::Compat before Perl 5.10 # perldoc mro
  • 10. constructors • Perl doesn’t have or need the concept • Do it however you want sub new { my $class = shift; bless({},$class); }
  • 11. object attributes, etc • Perl doesn’t have or need the concept • Do it however you want sub thing { my ($self,$new_val) = @_; $self->{thing} = $new_val if ($new_val); $self->{thing} }
  • 12. What Moo does • Sugar to write classes following a specific pattern • Designed to be instantiated into objects (via new) • Subclass using ‘extends’ • Declare attributes with ‘has’
  • 13. How it does it • Uses introspection to modify the package • ‘extends’ modifies @ISA like base and parent • ‘has’ adds/changes methods
  • 14. Roles (‘with’) • Also uses introspection to add/modify methods • Accomplish MI like designs w/o actually using Perl’s “MI” • No need to worry about MRO • You can still do MI if you really want to: pass multiple class names to ‘extends’ • But don’t - just use Roles
  • 15. Method-Modifiers • Access MI concepts but also w/o worry about MRO around ‘foo’ => sub { my ($orig,$self,@args) = @_; $self->$orig(@args) }; sub foo { my $self = shift; $self->next::method(@_) }
  • 16. Useful patterns • Chaining (like DBIC ResultSets) • Methods written to work on class or object • Using class names as params • Type::Tiny for types • Coercions
  • 17. When to use Moo • When writing object classes • When extending anything • Extend Moose classes
  • 18. Anti-Patterns • Getting too carried away • Doing things for dogma rather than benefit • Forgetting you are still writing Perl (and that it is wonderful) • There really is more than one way to do it
  • 19. Code Examples https://github.com/vanstyn/LJ-moose-article-examples https://github.com/vanstyn/DBIx-Class-Schema-Diff https://github.com/vanstyn/Hash-Layout