Your SlideShare is downloading. ×
  • Like
use Moose; &focus_on_actual_problem_solving
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×

Now you can save presentations on your phone or tablet

Available for both IPhone and Android

Text the download link to your phone

Standard text messaging rates apply

use Moose; &focus_on_actual_problem_solving

  • 121 views
Published

Introduction to Moose for wellington.pm

Introduction to Moose for wellington.pm

Published in Technology , Health & Medicine
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Be the first to comment
    Be the first to like this
No Downloads

Views

Total Views
121
On SlideShare
0
From Embeds
0
Number of Embeds
1

Actions

Shares
Downloads
0
Comments
0
Likes
0

Embeds 0

No embeds

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
    No notes for slide

Transcript

  • 1. use Moose; &focus_on_actual_problem_solving Raf Gemmail @fiqus Wellington.pm June 2014
  • 2. % perldoc perltoot
  • 3. % perldoc perltoot
  • 4. % perldoc perltoot
  • 5. % perldoc perltoot
  • 6. % perldoc perltoot Does Not Solve A Business Problem
  • 7. Class::Accessor
  • 8. Class::Accessor
  • 9. Prelude ● Declarative ● Focus TDD(esign) and Single Responsibility ● Standard Paradigm (Mo[ou].* and Perl6) ● Focus on returning business value / solution
  • 10. Moose
  • 11. Moose ● strict and warnings pragmas enabled
  • 12. Moose ● strict and warnings pragmas enabled ● Constructor : Person->new
  • 13. Moose ● strict and warnings pragmas enabled ● Constructor : Person->new
  • 14. Moose ● strict and warnings pragmas enabled ● Constructor : Person->new({name=>'Raf'})
  • 15. Moose ● strict and warnings pragmas enabled ● Constructor : Person->new({name=>'Raf'}) ● $person->name() immutable ● $person->age(5) ● $age = $person->age()
  • 16. Moose ● strict and warnings pragmas enabled ● Constructor : Person->new ● get_name, get_age, set_age
  • 17. Moose ● strict and warnings pragmas enabled ● Constructor : Person->new ● get_name (immutable), get_age, set_age ● Type checking (isa)
  • 18. Attributes
  • 19. Attributes ● is (mutability)
  • 20. Attributes ● is (mutability) – ro – rw
  • 21. Attributes ● is (mutability) ● isa (type validation)
  • 22. Attributes ● is (mutability) ● isa (type validation) – Class (or Role) name eg. Person
  • 23. Attributes ● is (mutability) ● isa (type validation) – Class (or Role) name eg. Person – Object, Int, Str, Bool, Undef, Def,
  • 24. Attributes ● is (mutability) ● isa (type validation) – Class (or Role) name eg. Person – Object, Int, Str, Bool, Undef, Def, – Ref (ScalarRef, ArrayRef, HashRef)
  • 25. Attributes ● default – default => $scalar || $sub_ref
  • 26. Attributes ● default – default => $scalar || $sub_ref
  • 27. Attributes ● builder, lazy – builder => method name
  • 28. Attributes ● builder, lazy – builder => method name
  • 29. Attributes ● lazy_build => 1
  • 30. Attributes ● handles – Proxies methods
  • 31. Attributes
  • 32. Attributes
  • 33. Attributes
  • 34. Attributes ● reader, writer – reader => 'get_vm_config' – writer => 'persist_vm_config'
  • 35. Attributes ● reader, writer – reader => 'get_vm_config' – writer => 'persist_vm_config' ● clearer => 'clear_attribute_name'
  • 36. Attributes ● reader, writer – reader => 'get_vm_config' – writer => 'persist_vm_config' ● clearer => 'clear_attribute_name' ● predicate => 'is_verbose'
  • 37. Attributes ● reader, writer – reader => 'get_vm_config' – writer => 'persist_vm_config' ● clearer => 'clear_attribute_name' ● predicate => 'is_verbose' ● trigger => &sub_ref
  • 38. Inheritance ● extends Ape Person
  • 39. 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);
  • 40. Roles ● Cross cutting characteristics (attribs & methods) ● Like Interface and Abstract Classes ● Base class which defines a behavioural contract with an optional partial implementation
  • 41. Roles
  • 42. Role
  • 43. Roles
  • 44. Roles
  • 45. Roles Consume role after attribute declarations
  • 46. 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
  • 47. 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
  • 48. Method Modifiers
  • 49. Method Modifiers
  • 50. Method Modifiers
  • 51. Method Modifiers
  • 52. Method Modifiers
  • 53. Method Modifiers
  • 54. Method Modifiers before
  • 55. Method Modifiers Transform Args
  • 56. Method Modifiers Real Method
  • 57. Method Modifiers After Invocation
  • 58. Method Modifiers
  • 59. Method Modifiers ● around [qw(method_1, method_2)] ● before qr/.*all_matching.*/ ● HasLogger HasModel HasWebService
  • 60. MooseX::Method::Signatures MooseX::Method::Signatures ● Type checking ● Method argument validation
  • 61. Moops
  • 62. MooseX::Declare
  • 63. And they all play together
  • 64. Avoid Starup Costs with Moo ● Pure Perl
  • 65. Avoid Starup Costs with Moo ● Pure Perl ● Painless integration with Moose deps (auto upgrades and does meta-magic)
  • 66. Avoid Starup Costs with Moo ● Pure Perl ● Painless integration with Moose deps (auto upgrades and does meta-magic) ● Fast
  • 67. MooseX ● Lots of Extensions ● MooseX::Types ● MooseX::GetOpt ● MooseX::App ● MooseX::Aspect
  • 68. MooseX::App::Simple
  • 69. MooseX::App::Simple
  • 70. Meta Magic ● Refelection ● __PACKAGE__->meta – > get_all_subclasses – > get_all_attributes – > add_attribute – > magix
  • 71. Recommendations ● use namespace::clean ● Use MooseX::FollowPBP ● Test::Routine – test with fixture roles and various permutations of test data. ● __PACKAGE__->meta->make_immutable;
  • 72. no Moose;