SlideShare uma empresa Scribd logo
1 de 72
use Moose;
&focus_on_actual_problem_solving
Raf Gemmail
@fiqus
Wellington.pm
June 2014
% perldoc perltoot
% perldoc perltoot
% perldoc perltoot
% perldoc perltoot
% perldoc perltoot
Does Not Solve
A
Business
Problem
Class::Accessor
Class::Accessor
Prelude
● Declarative
● Focus TDD(esign) and Single Responsibility
● Standard Paradigm (Mo[ou].* and Perl6)
● Focus on returning business value / solution
Moose
Moose
● strict and warnings pragmas enabled
Moose
● strict and warnings pragmas enabled
● Constructor : Person->new
Moose
● strict and warnings pragmas enabled
● Constructor : Person->new
Moose
● strict and warnings pragmas enabled
● Constructor : Person->new({name=>'Raf'})
Moose
● strict and warnings pragmas enabled
● Constructor : Person->new({name=>'Raf'})
● $person->name() immutable
● $person->age(5)
● $age = $person->age()
Moose
● strict and warnings pragmas enabled
● Constructor : Person->new
● get_name, get_age, set_age
Moose
● strict and warnings pragmas enabled
● Constructor : Person->new
● get_name (immutable), get_age, set_age
● Type checking (isa)
Attributes
Attributes
● is (mutability)
Attributes
● is (mutability)
– ro
– rw
Attributes
● is (mutability)
● isa (type validation)
Attributes
● is (mutability)
● isa (type validation)
– Class (or Role) name eg. Person
Attributes
● is (mutability)
● isa (type validation)
– Class (or Role) name eg. Person
– Object, Int, Str, Bool, Undef, Def,
Attributes
● is (mutability)
● isa (type validation)
– Class (or Role) name eg. Person
– Object, Int, Str, Bool, Undef, Def,
– Ref (ScalarRef, ArrayRef, HashRef)
Attributes
● default
– default => $scalar || $sub_ref
Attributes
● default
– default => $scalar || $sub_ref
Attributes
● builder, lazy
– builder => method name
Attributes
● builder, lazy
– builder => method name
Attributes
● lazy_build => 1
Attributes
● handles
– Proxies methods
Attributes
Attributes
Attributes
Attributes
● reader, writer
– reader => 'get_vm_config'
– writer => 'persist_vm_config'
Attributes
● reader, writer
– reader => 'get_vm_config'
– writer => 'persist_vm_config'
● clearer => 'clear_attribute_name'
Attributes
● reader, writer
– reader => 'get_vm_config'
– writer => 'persist_vm_config'
● clearer => 'clear_attribute_name'
● predicate => 'is_verbose'
Attributes
● reader, writer
– reader => 'get_vm_config'
– writer => 'persist_vm_config'
● clearer => 'clear_attribute_name'
● predicate => 'is_verbose'
● trigger => &sub_ref
Inheritance
● extends
Ape
Person
Method Resolution Order
Animal
RomulanHorse Bird
Pegasus
• Perl depth-first: [Pegasus → Horse → Animal, Bird]
• eg. Animal::brain has higher precedence than Bird::brain
• C3 MRO breadth first: [Pegasus, Horse, Bird, Animal]
use base qw(Horse Bird)
vs
extends qw(Horse Bird);
Roles
● Cross cutting characteristics (attribs &
methods)
● Like Interface and Abstract Classes
● Base class which defines a behavioural
contract with an optional partial implementation
Roles
Role
Roles
Roles
Roles
Consume role
after attribute
declarations
Method Modifiers
● Aspects – non-core cross-cutting behaviour
● Advice (do this) eg. A sub ref
● Point-cut (do the advice at these point of my
execution) Before, After and Around
Method Modifiers
● Aspects – non-core cross-cutting behaviour
● Advice (do this) eg. A sub ref
● Point-cut (do the advice at these point of my
execution) Before, After and Around
Method Modifiers
Method Modifiers
Method Modifiers
Method Modifiers
Method Modifiers
Method Modifiers
Method Modifiers
before
Method Modifiers
Transform
Args
Method Modifiers
Real
Method
Method Modifiers
After
Invocation
Method Modifiers
Method Modifiers
● around [qw(method_1, method_2)]
● before qr/.*all_matching.*/
● HasLogger HasModel HasWebService
MooseX::Method::Signatures
MooseX::Method::Signatures
● Type checking
● Method argument validation
Moops
MooseX::Declare
And they all play together
Avoid Starup Costs with Moo
● Pure Perl
Avoid Starup Costs with Moo
● Pure Perl
● Painless integration with Moose deps (auto
upgrades and does meta-magic)
Avoid Starup Costs with Moo
● Pure Perl
● Painless integration with Moose deps (auto
upgrades and does meta-magic)
● Fast
MooseX
● Lots of Extensions
● MooseX::Types
● MooseX::GetOpt
● MooseX::App
● MooseX::Aspect
MooseX::App::Simple
MooseX::App::Simple
Meta Magic
● Refelection
● __PACKAGE__->meta
– > get_all_subclasses
– > get_all_attributes
– > add_attribute
– > magix
Recommendations
● use namespace::clean
● Use MooseX::FollowPBP
● Test::Routine – test with fixture roles and
various permutations of test data.
● __PACKAGE__->meta->make_immutable;
no Moose;

Mais conteúdo relacionado

Semelhante a use Moose; &focus_on_actual_problem_solving

A3 sec -_regular_expressions
A3 sec -_regular_expressionsA3 sec -_regular_expressions
A3 sec -_regular_expressions
a3sec
 
Deployments with rails
Deployments with railsDeployments with rails
Deployments with rails
Gourav Tiwari
 
Benchmarking Perl Lightning Talk (NPW 2007)
Benchmarking Perl Lightning Talk (NPW 2007)Benchmarking Perl Lightning Talk (NPW 2007)
Benchmarking Perl Lightning Talk (NPW 2007)
brian d foy
 
Benchmarking Perl (Chicago UniForum 2006)
Benchmarking Perl (Chicago UniForum 2006)Benchmarking Perl (Chicago UniForum 2006)
Benchmarking Perl (Chicago UniForum 2006)
brian d foy
 

Semelhante a use Moose; &focus_on_actual_problem_solving (20)

Learning groovy 1: half day workshop
Learning groovy 1: half day workshopLearning groovy 1: half day workshop
Learning groovy 1: half day workshop
 
Gradle - time for another build
Gradle - time for another buildGradle - time for another build
Gradle - time for another build
 
A3 sec -_regular_expressions
A3 sec -_regular_expressionsA3 sec -_regular_expressions
A3 sec -_regular_expressions
 
Core Java Programming Language (JSE) : Chapter IV - Expressions and Flow Cont...
Core Java Programming Language (JSE) : Chapter IV - Expressions and Flow Cont...Core Java Programming Language (JSE) : Chapter IV - Expressions and Flow Cont...
Core Java Programming Language (JSE) : Chapter IV - Expressions and Flow Cont...
 
Valerii Vasylkov Erlang. measurements and benefits.
Valerii Vasylkov Erlang. measurements and benefits.Valerii Vasylkov Erlang. measurements and benefits.
Valerii Vasylkov Erlang. measurements and benefits.
 
SE2016 Exotic Valerii Vasylkov "Erlang. Measurements and benefits"
SE2016 Exotic Valerii Vasylkov "Erlang. Measurements and benefits"SE2016 Exotic Valerii Vasylkov "Erlang. Measurements and benefits"
SE2016 Exotic Valerii Vasylkov "Erlang. Measurements and benefits"
 
Querydsl overview 2014
Querydsl overview 2014Querydsl overview 2014
Querydsl overview 2014
 
Java conventions
Java conventionsJava conventions
Java conventions
 
Deployments with rails
Deployments with railsDeployments with rails
Deployments with rails
 
Benchmarking Perl Lightning Talk (NPW 2007)
Benchmarking Perl Lightning Talk (NPW 2007)Benchmarking Perl Lightning Talk (NPW 2007)
Benchmarking Perl Lightning Talk (NPW 2007)
 
Lecture1.pdf
Lecture1.pdfLecture1.pdf
Lecture1.pdf
 
Optimizing a large angular application (ng conf)
Optimizing a large angular application (ng conf)Optimizing a large angular application (ng conf)
Optimizing a large angular application (ng conf)
 
Benchmarking Perl (Chicago UniForum 2006)
Benchmarking Perl (Chicago UniForum 2006)Benchmarking Perl (Chicago UniForum 2006)
Benchmarking Perl (Chicago UniForum 2006)
 
Scale up your thinking
Scale up your thinkingScale up your thinking
Scale up your thinking
 
Core java
Core javaCore java
Core java
 
Kicking off with Zend Expressive and Doctrine ORM (PHPNW2016)
Kicking off with Zend Expressive and Doctrine ORM (PHPNW2016)Kicking off with Zend Expressive and Doctrine ORM (PHPNW2016)
Kicking off with Zend Expressive and Doctrine ORM (PHPNW2016)
 
Dart workshop
Dart workshopDart workshop
Dart workshop
 
OSDC.tw 2008 Lightening Talk
OSDC.tw 2008 Lightening TalkOSDC.tw 2008 Lightening Talk
OSDC.tw 2008 Lightening Talk
 
Developer-friendly taskqueues: What you should ask yourself before choosing one
Developer-friendly taskqueues: What you should ask yourself before choosing oneDeveloper-friendly taskqueues: What you should ask yourself before choosing one
Developer-friendly taskqueues: What you should ask yourself before choosing one
 
Developer-friendly task queues: what we learned building MRQ, Sylvain Zimmer
Developer-friendly task queues: what we learned building MRQ, Sylvain ZimmerDeveloper-friendly task queues: what we learned building MRQ, Sylvain Zimmer
Developer-friendly task queues: what we learned building MRQ, Sylvain Zimmer
 

Último

Último (20)

"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu SubbuApidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
 
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...
 
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
 
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
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
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
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024
 
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...
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot ModelNavi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
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
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 

use Moose; &focus_on_actual_problem_solving