Evolving Software with Moose

  • 4,162 views
Uploaded on

 

More in: Technology
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Be the first to comment
No Downloads

Views

Total Views
4,162
On Slideshare
0
From Embeds
0
Number of Embeds
1

Actions

Shares
Downloads
39
Comments
0
Likes
1

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. Evolving Software with Moose
  • 2. Dave Cross [email_address] @davorg
  • 3. Perlanet
  • 4. Perl + Planet
  • 5. Web Feed Aggregation
  • 6. Input: Lots of web feeds
  • 7. Output: Web page + web feed
  • 8.  
  • 9.  
  • 10.  
  • 11. Scratching an itch
  • 12. Wrote it for me
  • 13. CPAN
  • 14. github
  • 15. A few bug fixes
  • 16. A few enhancements
  • 17. Perl Ironman
  • 18. Using Plagger
  • 19. Wanted to use Perlanet
  • 20. Didn't scale well
  • 21. YAML config
  • 22. NWE.pm Hackday
  • 23. Enter the Moose
  • 24. Slash and burn
  • 25. More easily subclassable
  • 26. Monolithic vs Overridable
  • 27. HTML::Scrubber
  • 28. # deep in the 'run' subroutine my %scrub_rules = ( # stuff ); my %scrub_def = ( # more stuff ) my $scrub = HTML::Scrubber->new; $scrub->rules(%scrub_rules); $scrub->default(1, scrub_def);
  • 29. Overriding this is hard
  • 30. has 'scrubber' => ( is => 'rw', lazy_build => 1 ); sub _build_scrubber { my $self = shift; # all that previous stuff return $scrub; }
  • 31. Overriding this is easy
  • 32. Repeat half a dozen times
  • 33. YAML config
  • 34. YAML config
  • 35. DB config
  • 36. Better scaling
  • 37. Phase 1 complete
  • 38. Almost
  • 39. Need better tests
  • 40. Release early Release often
  • 41. Phase 2
  • 42. Traits
  • 43. Moose has traits and roles
  • 44. Difference is subtle
  • 45. Implementation looks similar
  • 46. I didn't know the difference
  • 47. Role is like an interface
  • 48. Defines methods that class MUST implement
  • 49. package ARole; use Moose::Role; requires 'do_stuff'; 1;
  • 50. package AClass; use Moose; with 'ARole'; has name => ( is => 'rw', isa => 'Str', ); 1;
  • 51. #!/usr/bin/perl use strict; use warnings; use AClass; my $obj = Aclass->new({ name => 'davorg', });
  • 52. $ ./role_demo 'ARole' requires the method 'do_stuff' to be implemented by 'AClass' ... other scary stuff ...
  • 53. Need to implement method
  • 54. package AClass; use Moose; with 'ARole'; has name => ( is => 'rw', isa => 'Str', ); sub do_stuff { my $self = shift; print $self->name, “ does stuff ”; } 1;
  • 55. Roles impose an interface
  • 56. (We don't use those in Perlanet)
  • 57. Traits add functionality
  • 58. Like a mixin
  • 59. Remember HTML::Scrubber?
  • 60. package Perlanet::Trait::Scrubber; use Moose::Role; # yes really – hold that thought use HTML::Scrubber; has scrubber => ( is => 'rw', lazy_build => 1, ); sub _build_scrubber { # all that stuff from before return $scrub; }
  • 61. package Perlanet::Trait::Scrubber; use Moose::Role; # yes really – hold that thought use HTML::Scrubber; has scrubber => ( is => 'rw', lazy_build => 1, ); sub _build_scrubber { # all that stuff from before return $scrub; }
  • 62. around 'clean_html' => sub { my $orig = shift; my ($self, $html) = @_; $html = $self->orig($html); $self->scrubber->scrub($html); return $html; } 1;
  • 63. Perlanet.pm has clean_html method
  • 64. But it does nothing until traits are added
  • 65. Perlanet is now a hollow shell of a module
  • 66. All the fun stuff is in traits
  • 67. Perlanet::Simple
  • 68. package Perlanet::Simple; use Moose; extends 'Perlanet'; with qw( Perlanet::Trait::Cache Perlanet::Trait::OPML Perlanet::Trait::Scrubber Perlanet::Trait::Tidy Perlanet::Trait::YAMLConfig Perlanet::Trait::TemplateToolkit Perlanet::Trait::FeedFile );
  • 69. Moose::Role
  • 70. Used in both roles and traits
  • 71. This is Perl
  • 72. Difference is not clear-cut
  • 73. Roles and traits are the same thing
  • 74. Depends where the code is
  • 75. All based on Moose::Role
  • 76. Perlanet now trait-based
  • 77. Easy to add functionality
  • 78. Perlanet trait ecosystem
  • 79. And I learned about Moose roles and traits
  • 80. (And now, so have you)
  • 81. ht tp://search.cpan.org/dist/Perlanet http://theplanetarium.org/ ht tp://perlanet.mag-sol.com/ http://moose.perl.org/
  • 82.