use moose; &focus_on_actual_problem_solving

Download use Moose; &focus_on_actual_problem_solving

If you can't read please download the document

Upload: rafiq-gemmail

Post on 15-May-2015

142 views

Category:

Technology


1 download

DESCRIPTION

Introduction to Moose for wellington.pm

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;