SlideShare a Scribd company logo
1 of 43
use Moose;
Finding Object Oriented Enlightenment
Images Courtesy of
   Shutterstock

   http://www.shutterstock.com/
Shutterstock
Developer Ethos
Get feedback as early as possible, and work together
Prefer encapsulated, loosely coupled
   systems for core functionality
Choose the smallest implementation that doesn’t
         suck provides a way forward
Make your code readable,
understandable, maintainable
• Get feedback as early as possible, and work
  together

• Prefer encapsulated, loosely coupled
  systems for core functionality

• Choose the smallest implementation that
  provides a way forward

• Make your code readable, understandable,
  and maintainable
...the object-oriented approach
 encourages the programmer to place
       data where it is not directly
       accessible by the rest of the
 program. Instead, the data is accessed
  by calling specially written functions,
       commonly called methods...

http://en.wikipedia.org/wiki/Object-oriented_programming
A Person Walks and Talks
start_walking               stop_walking




                Person




            speak($something)
Prefer encapsulated, loosely coupled
systems for core functionality

Choose the smallest implementation that
provides a way forward

Make your code readable, understandable,
and maintainable
Ash Nazg Durbatulûk! Ash Nazg Gimbatul!
 Ash Nazg Gimbatul! Ash Nazg Gimbatul!
"I will take the Ring to
 Mordor. Though — I
do not know the way."
    -- Frodo, LoTR
Moose and Perl
Moose is a postmodern object
system for Perl 5 that takes the tedium
 out of writing object-oriented Perl. It
borrows all the best features from Perl
  6, CLOS (Lisp), Smalltalk, Java, BETA,
   OCaml, Ruby and more, while still
     keeping true to its Perl 5 roots.

         http://moose.iinteractive.com/
package Point;

use Moose;
 
has 'x' => (isa => 'Int', is => 'rw', required => 1);
has 'y' => (isa => 'Int', is => 'rw', required => 1);
 
sub clear {
  my $self = shift;
  $self->x(0);
  $self->y(0);
}
Building Blocks

•   Inheritance

•   Roles

•   Delegation
Inheritance
package Point;
use Moose;
 
has 'x' => (isa => 'Int', is => 'rw', required => 1);
has 'y' => (isa => 'Int', is => 'rw', required => 1);
 
sub clear {
  my $self = shift;
  $self->x(0);
  $self->y(0);
}

package Point3D;
use Moose;
 
extends 'Point';
 
has 'z' => (isa => 'Int', is => 'rw', required => 1);
 
after 'clear' => sub {
    my $self = shift;
    $self->z(0);
};
Roles
package Eq;
use Moose::Role;
requires 'equal';

my $defensive_coderef = sub { ... };
 
sub no_equal {
    my ($self, $other) = @_;
    !$self->equal($other);
}
 
package Currency;
use Moose;
with 'Eq';
 
sub equal {
    my ($self, $other) = @_;
    $self->as_float == $other->as_float;
}
Delegation
package MyObject;

use Moose;
use MyLogger;

has ‘logger’ => (
   is => ‘bare’,
   lazy_build => 1,
   handles => [qw/err warn/],
);

sub _build_logger { MyLogger->new }

sub something_worth_logging {
  my ($self) = @_;
  $self->err(“Hey, there’s a problem!!!”);
}
package MyObject;
use Moose;
use MooseX::Types::LoadableClass 'LoadableClass';

has logger_class => (
  is => 'ro',
  default => 'MyLogger',
  isa => LoadableClass,
  coerce => 1);

has logger_args => (
   is=>’ro’, isa=>‘HashRef’, default=> sub { +{} }
);

has ‘logger’ => (
  is => ‘bare’,
  lazy_build => 1,
  handles => [qw/err warn/]);

sub _build_logger {
  my $self = shift;
  $self->logger_class($self->logger_args)
    ->new
}
package MyObject;
use Moose;
 
with 'MooseX::Role::BuildInstanceOf' => {
   target => 'Logger'
};

has ‘+logger’ => (handles => [qw/err warn/]);
Examples
Test::DBIx::Class

• Automatically deploy temporary databases
  based on exist DBIx::Class schema
• Pluggable database targets (Sqlite, MySQL,
  PostgreSQL)
Approach

• Create a Base Class with default
  functionality
• Use Roles to allow ‘plugging in’ various
  target temporary database types
DBIx::Class::Migration

• Make it easy to create deploys and
  upgrades for database schemas
• Be flexible but have sane, community
  accepted standards
Approach

• Create a Base class with lots of delegate
  placeholders.
• Create defaults classes that provide
  required functionality
GeneralAssembly::Guestbook


 • A Test Application to Demonstrate Perl to
   inspired learners
 • Code is probably overkill for the actual
   problem
My Learnings
• Delegation seems the most normally useful
  approach to creating easily testable building
  blocks.
• Roles are great for enforcing contracts and
  for enhancing objects with cross cutting
  functionality.
• (Combine the two)++
Summary

• There is no necessary tension between
  writing the least code and writing good
  code
• Good design lets you evolve over time
  without nasty hacks
Moose

More Related Content

What's hot

Introduction to Moose
Introduction to MooseIntroduction to Moose
Introduction to Moosethashaa
 
CoffeeScript
CoffeeScriptCoffeeScript
CoffeeScriptNone
 
Introduction to CoffeeScript
Introduction to CoffeeScriptIntroduction to CoffeeScript
Introduction to CoffeeScriptStalin Thangaraj
 
JS Level Up: Prototypes
JS Level Up: PrototypesJS Level Up: Prototypes
JS Level Up: PrototypesVernon Kesner
 
Scaling Symfony2 apps with RabbitMQ - Symfony UK Meetup
Scaling Symfony2 apps with RabbitMQ - Symfony UK MeetupScaling Symfony2 apps with RabbitMQ - Symfony UK Meetup
Scaling Symfony2 apps with RabbitMQ - Symfony UK MeetupKacper Gunia
 
"The worst code I ever wrote"
"The worst code I ever wrote""The worst code I ever wrote"
"The worst code I ever wrote"Tomas Doran
 
Replacing "exec" with a type and provider: Return manifests to a declarative ...
Replacing "exec" with a type and provider: Return manifests to a declarative ...Replacing "exec" with a type and provider: Return manifests to a declarative ...
Replacing "exec" with a type and provider: Return manifests to a declarative ...Puppet
 
Introducing Assetic (NYPHP)
Introducing Assetic (NYPHP)Introducing Assetic (NYPHP)
Introducing Assetic (NYPHP)Kris Wallsmith
 
5 Tips for Better JavaScript
5 Tips for Better JavaScript5 Tips for Better JavaScript
5 Tips for Better JavaScriptTodd Anglin
 
Php on the Web and Desktop
Php on the Web and DesktopPhp on the Web and Desktop
Php on the Web and DesktopElizabeth Smith
 
You Don't Know Query (WordCamp Netherlands 2012)
You Don't Know Query (WordCamp Netherlands 2012)You Don't Know Query (WordCamp Netherlands 2012)
You Don't Know Query (WordCamp Netherlands 2012)andrewnacin
 
Non-Relational Databases
Non-Relational DatabasesNon-Relational Databases
Non-Relational Databaseskchodorow
 
Amazon Cloud Services and Zend Framework
Amazon Cloud Services and Zend FrameworkAmazon Cloud Services and Zend Framework
Amazon Cloud Services and Zend FrameworkShahar Evron
 
Koajs as an alternative to Express - OdessaJs'16
Koajs as an alternative to Express - OdessaJs'16Koajs as an alternative to Express - OdessaJs'16
Koajs as an alternative to Express - OdessaJs'16Nikolay Kozhukharenko
 

What's hot (19)

Introduction to Moose
Introduction to MooseIntroduction to Moose
Introduction to Moose
 
CoffeeScript
CoffeeScriptCoffeeScript
CoffeeScript
 
Coffee Script
Coffee ScriptCoffee Script
Coffee Script
 
Introduction to CoffeeScript
Introduction to CoffeeScriptIntroduction to CoffeeScript
Introduction to CoffeeScript
 
JS Level Up: Prototypes
JS Level Up: PrototypesJS Level Up: Prototypes
JS Level Up: Prototypes
 
Scaling Symfony2 apps with RabbitMQ - Symfony UK Meetup
Scaling Symfony2 apps with RabbitMQ - Symfony UK MeetupScaling Symfony2 apps with RabbitMQ - Symfony UK Meetup
Scaling Symfony2 apps with RabbitMQ - Symfony UK Meetup
 
Power of Puppet 4
Power of Puppet 4Power of Puppet 4
Power of Puppet 4
 
"The worst code I ever wrote"
"The worst code I ever wrote""The worst code I ever wrote"
"The worst code I ever wrote"
 
Replacing "exec" with a type and provider: Return manifests to a declarative ...
Replacing "exec" with a type and provider: Return manifests to a declarative ...Replacing "exec" with a type and provider: Return manifests to a declarative ...
Replacing "exec" with a type and provider: Return manifests to a declarative ...
 
Your JavaScript Library
Your JavaScript LibraryYour JavaScript Library
Your JavaScript Library
 
Introducing Assetic (NYPHP)
Introducing Assetic (NYPHP)Introducing Assetic (NYPHP)
Introducing Assetic (NYPHP)
 
Puppet modules for Fun and Profit
Puppet modules for Fun and ProfitPuppet modules for Fun and Profit
Puppet modules for Fun and Profit
 
5 Tips for Better JavaScript
5 Tips for Better JavaScript5 Tips for Better JavaScript
5 Tips for Better JavaScript
 
Php on the Web and Desktop
Php on the Web and DesktopPhp on the Web and Desktop
Php on the Web and Desktop
 
You Don't Know Query (WordCamp Netherlands 2012)
You Don't Know Query (WordCamp Netherlands 2012)You Don't Know Query (WordCamp Netherlands 2012)
You Don't Know Query (WordCamp Netherlands 2012)
 
Non-Relational Databases
Non-Relational DatabasesNon-Relational Databases
Non-Relational Databases
 
Amazon Cloud Services and Zend Framework
Amazon Cloud Services and Zend FrameworkAmazon Cloud Services and Zend Framework
Amazon Cloud Services and Zend Framework
 
Troubleshooting Puppet
Troubleshooting PuppetTroubleshooting Puppet
Troubleshooting Puppet
 
Koajs as an alternative to Express - OdessaJs'16
Koajs as an alternative to Express - OdessaJs'16Koajs as an alternative to Express - OdessaJs'16
Koajs as an alternative to Express - OdessaJs'16
 

Similar to Moose

Python and Oracle : allies for best of data management
Python and Oracle : allies for best of data managementPython and Oracle : allies for best of data management
Python and Oracle : allies for best of data managementLaurent Leturgez
 
Advancing JavaScript with Libraries (Yahoo Tech Talk)
Advancing JavaScript with Libraries (Yahoo Tech Talk)Advancing JavaScript with Libraries (Yahoo Tech Talk)
Advancing JavaScript with Libraries (Yahoo Tech Talk)jeresig
 
DjangoCon 2010 Scaling Disqus
DjangoCon 2010 Scaling DisqusDjangoCon 2010 Scaling Disqus
DjangoCon 2010 Scaling Disquszeeg
 
The Why and How of Scala at Twitter
The Why and How of Scala at TwitterThe Why and How of Scala at Twitter
The Why and How of Scala at TwitterAlex Payne
 
Apache Superset at Airbnb
Apache Superset at AirbnbApache Superset at Airbnb
Apache Superset at AirbnbBill Liu
 
Java Secure Coding Practices
Java Secure Coding PracticesJava Secure Coding Practices
Java Secure Coding PracticesOWASPKerala
 
Pwning with powershell
Pwning with powershellPwning with powershell
Pwning with powershelljaredhaight
 
Objective-C Is Not Java
Objective-C Is Not JavaObjective-C Is Not Java
Objective-C Is Not JavaChris Adamson
 
Node.js introduction
Node.js introductionNode.js introduction
Node.js introductionPrasoon Kumar
 
Bioinformatics p5-bioperl v2013-wim_vancriekinge
Bioinformatics p5-bioperl v2013-wim_vancriekingeBioinformatics p5-bioperl v2013-wim_vancriekinge
Bioinformatics p5-bioperl v2013-wim_vancriekingeProf. Wim Van Criekinge
 
Learn you some Ansible for great good!
Learn you some Ansible for great good!Learn you some Ansible for great good!
Learn you some Ansible for great good!David Lapsley
 
44CON 2014 - Pentesting NoSQL DB's Using NoSQL Exploitation Framework, Franci...
44CON 2014 - Pentesting NoSQL DB's Using NoSQL Exploitation Framework, Franci...44CON 2014 - Pentesting NoSQL DB's Using NoSQL Exploitation Framework, Franci...
44CON 2014 - Pentesting NoSQL DB's Using NoSQL Exploitation Framework, Franci...44CON
 
Rails Tips and Best Practices
Rails Tips and Best PracticesRails Tips and Best Practices
Rails Tips and Best PracticesDavid Keener
 

Similar to Moose (20)

Python and Oracle : allies for best of data management
Python and Oracle : allies for best of data managementPython and Oracle : allies for best of data management
Python and Oracle : allies for best of data management
 
55j7
55j755j7
55j7
 
Advancing JavaScript with Libraries (Yahoo Tech Talk)
Advancing JavaScript with Libraries (Yahoo Tech Talk)Advancing JavaScript with Libraries (Yahoo Tech Talk)
Advancing JavaScript with Libraries (Yahoo Tech Talk)
 
DjangoCon 2010 Scaling Disqus
DjangoCon 2010 Scaling DisqusDjangoCon 2010 Scaling Disqus
DjangoCon 2010 Scaling Disqus
 
The Why and How of Scala at Twitter
The Why and How of Scala at TwitterThe Why and How of Scala at Twitter
The Why and How of Scala at Twitter
 
Apache Superset at Airbnb
Apache Superset at AirbnbApache Superset at Airbnb
Apache Superset at Airbnb
 
Java Secure Coding Practices
Java Secure Coding PracticesJava Secure Coding Practices
Java Secure Coding Practices
 
DevOps for database
DevOps for databaseDevOps for database
DevOps for database
 
Django at Scale
Django at ScaleDjango at Scale
Django at Scale
 
Pwning with powershell
Pwning with powershellPwning with powershell
Pwning with powershell
 
Objective-C Is Not Java
Objective-C Is Not JavaObjective-C Is Not Java
Objective-C Is Not Java
 
Bioinformatica p6-bioperl
Bioinformatica p6-bioperlBioinformatica p6-bioperl
Bioinformatica p6-bioperl
 
Node.js introduction
Node.js introductionNode.js introduction
Node.js introduction
 
Persistences
PersistencesPersistences
Persistences
 
Laravel ppt
Laravel pptLaravel ppt
Laravel ppt
 
Bioinformatics p5-bioperl v2013-wim_vancriekinge
Bioinformatics p5-bioperl v2013-wim_vancriekingeBioinformatics p5-bioperl v2013-wim_vancriekinge
Bioinformatics p5-bioperl v2013-wim_vancriekinge
 
Learn you some Ansible for great good!
Learn you some Ansible for great good!Learn you some Ansible for great good!
Learn you some Ansible for great good!
 
44CON 2014 - Pentesting NoSQL DB's Using NoSQL Exploitation Framework, Franci...
44CON 2014 - Pentesting NoSQL DB's Using NoSQL Exploitation Framework, Franci...44CON 2014 - Pentesting NoSQL DB's Using NoSQL Exploitation Framework, Franci...
44CON 2014 - Pentesting NoSQL DB's Using NoSQL Exploitation Framework, Franci...
 
55 New Features in Java 7
55 New Features in Java 755 New Features in Java 7
55 New Features in Java 7
 
Rails Tips and Best Practices
Rails Tips and Best PracticesRails Tips and Best Practices
Rails Tips and Best Practices
 

Recently uploaded

04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAndrey Devyatkin
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilV3cube
 
HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesBoston Institute of Analytics
 
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
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoffsammart93
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century educationjfdjdjcjdnsjd
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
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
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CVKhem
 
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
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherRemote DBA Services
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessPixlogix Infotech
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobeapidays
 

Recently uploaded (20)

04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of Brazil
 
HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation Strategies
 
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
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
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
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
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...
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your Business
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 

Moose

  • 1. use Moose; Finding Object Oriented Enlightenment
  • 2. Images Courtesy of Shutterstock http://www.shutterstock.com/
  • 3.
  • 4.
  • 5.
  • 6.
  • 8. Get feedback as early as possible, and work together
  • 9. Prefer encapsulated, loosely coupled systems for core functionality
  • 10. Choose the smallest implementation that doesn’t suck provides a way forward
  • 11. Make your code readable, understandable, maintainable
  • 12. • Get feedback as early as possible, and work together • Prefer encapsulated, loosely coupled systems for core functionality • Choose the smallest implementation that provides a way forward • Make your code readable, understandable, and maintainable
  • 13. ...the object-oriented approach encourages the programmer to place data where it is not directly accessible by the rest of the program. Instead, the data is accessed by calling specially written functions, commonly called methods... http://en.wikipedia.org/wiki/Object-oriented_programming
  • 14. A Person Walks and Talks
  • 15. start_walking stop_walking Person speak($something)
  • 16. Prefer encapsulated, loosely coupled systems for core functionality Choose the smallest implementation that provides a way forward Make your code readable, understandable, and maintainable
  • 17.
  • 18. Ash Nazg Durbatulûk! Ash Nazg Gimbatul! Ash Nazg Gimbatul! Ash Nazg Gimbatul!
  • 19. "I will take the Ring to Mordor. Though — I do not know the way." -- Frodo, LoTR
  • 20.
  • 22. Moose is a postmodern object system for Perl 5 that takes the tedium out of writing object-oriented Perl. It borrows all the best features from Perl 6, CLOS (Lisp), Smalltalk, Java, BETA, OCaml, Ruby and more, while still keeping true to its Perl 5 roots. http://moose.iinteractive.com/
  • 23. package Point; use Moose;   has 'x' => (isa => 'Int', is => 'rw', required => 1); has 'y' => (isa => 'Int', is => 'rw', required => 1);   sub clear { my $self = shift;   $self->x(0);   $self->y(0); }
  • 24.
  • 25. Building Blocks • Inheritance • Roles • Delegation
  • 27. package Point; use Moose;   has 'x' => (isa => 'Int', is => 'rw', required => 1); has 'y' => (isa => 'Int', is => 'rw', required => 1);   sub clear { my $self = shift;   $self->x(0);   $self->y(0); } package Point3D; use Moose;   extends 'Point';   has 'z' => (isa => 'Int', is => 'rw', required => 1);   after 'clear' => sub {     my $self = shift;     $self->z(0); };
  • 28. Roles
  • 29. package Eq; use Moose::Role; requires 'equal'; my $defensive_coderef = sub { ... };   sub no_equal {     my ($self, $other) = @_;     !$self->equal($other); }   package Currency; use Moose; with 'Eq';   sub equal {     my ($self, $other) = @_;     $self->as_float == $other->as_float; }
  • 31. package MyObject; use Moose; use MyLogger; has ‘logger’ => ( is => ‘bare’, lazy_build => 1, handles => [qw/err warn/], ); sub _build_logger { MyLogger->new } sub something_worth_logging { my ($self) = @_; $self->err(“Hey, there’s a problem!!!”); }
  • 32. package MyObject; use Moose; use MooseX::Types::LoadableClass 'LoadableClass'; has logger_class => (   is => 'ro',   default => 'MyLogger',   isa => LoadableClass,   coerce => 1); has logger_args => ( is=>’ro’, isa=>‘HashRef’, default=> sub { +{} } ); has ‘logger’ => ( is => ‘bare’, lazy_build => 1, handles => [qw/err warn/]); sub _build_logger { my $self = shift; $self->logger_class($self->logger_args) ->new }
  • 33. package MyObject; use Moose;   with 'MooseX::Role::BuildInstanceOf' => { target => 'Logger' }; has ‘+logger’ => (handles => [qw/err warn/]);
  • 35. Test::DBIx::Class • Automatically deploy temporary databases based on exist DBIx::Class schema • Pluggable database targets (Sqlite, MySQL, PostgreSQL)
  • 36. Approach • Create a Base Class with default functionality • Use Roles to allow ‘plugging in’ various target temporary database types
  • 37. DBIx::Class::Migration • Make it easy to create deploys and upgrades for database schemas • Be flexible but have sane, community accepted standards
  • 38. Approach • Create a Base class with lots of delegate placeholders. • Create defaults classes that provide required functionality
  • 39. GeneralAssembly::Guestbook • A Test Application to Demonstrate Perl to inspired learners • Code is probably overkill for the actual problem
  • 40.
  • 41. My Learnings • Delegation seems the most normally useful approach to creating easily testable building blocks. • Roles are great for enforcing contracts and for enhancing objects with cross cutting functionality. • (Combine the two)++
  • 42. Summary • There is no necessary tension between writing the least code and writing good code • Good design lets you evolve over time without nasty hacks

Editor's Notes

  1. \n
  2. \n
  3. \n
  4. great ideas are simple answers to common problems\n\n
  5. maybe not so simple in the details!\n
  6. \n
  7. \n
  8. \n
  9. \n
  10. \n
  11. \n
  12. \n
  13. \n
  14. \n
  15. \n
  16. \n
  17. \n
  18. great ideas are simple answers to common problems\n\n
  19. \n
  20. \n
  21. \n
  22. \n
  23. \n
  24. \n
  25. \n
  26. \n
  27. \n
  28. \n
  29. \n
  30. \n
  31. \n
  32. \n
  33. \n
  34. \n
  35. \n
  36. \n
  37. \n
  38. \n
  39. \n
  40. \n
  41. \n
  42. \n
  43. \n