Your SlideShare is downloading. ×
Design Patterns in Perl (Grand Rapids Perl Mongers, 2006)
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

Design Patterns in Perl (Grand Rapids Perl Mongers, 2006)

3,029

Published on

Published in: Technology, Business
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
3,029
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
0
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. Perl Design Patterns brian d foy Stonehenge Consulting Ser vices February 24, 2006 Grand Rapids Perl Mongers Sponsored by PriorityHealth
  • 2. Patterns aren’t a ... code cookbook module on CPAN methodology goal religion
  • 3. Patterns are a ... abstraction for things we need to do solutions for common problems name for a design element common language for design discussions way to apply a common design to code relationships
  • 4. Three parts Context System of forces Solution
  • 5. Nothing’s Free Actions have reactions Complexity turns up somewhere else Choices have consequences
  • 6. Who’s responsible? Our application needs config information But we have several modules Who loads the data? How do the other modules get it?
  • 7. A pattern Load the configuration from anywhere But load it only one time Anyone else gets a reference to it The order doesn’t matter
  • 8. What’s in a name A couple words instead of sentences We agree on what the name implies Others know what we mean “A rose is a rose is a rose”
  • 9. The Singleton There is only one configuration Let’s call it a singleton ... or a highlander We don’t have an implementation Just a name with implied design elements
  • 10. An implementation package My::Config; my $singleton = undef; sub new { my $class = shift; return $singleton if defined $singleton; $singleton = bless {}, $class; }
  • 11. A use package My::Database; use My::Config; my $config = My::Config->new( ... ); package My::Network; use My::Config; my $config = My::Config->new( ... );
  • 12. That isn’t the only way The pattern is not a prescription It’s an option Maybe another pattern works better.
  • 13. A Meta Class Write a meta class that contains all of the object parts Objects talk to the meta class to communicate with the other parts use My::Controller; my $controller = My::Controller->new(...); my $value = $controller->config->get( ... );
  • 14. Delegates package My::Controller; sub new { my $class = shift; my $self = bless {}, $class; # weaken some of these circular refs @$self{ qw(_config _database _network ) } = ( My::Config->new( controller => $self ), DBI->new( ... ), My::Socket->new( controller => $self ), ); $self; } sub config { $_[0]{_config} }
  • 15. Some Perl Modules Apache::DBI Netscape::Bookmarks CGI::Prototype many things in Class::*, almost
  • 16. Beware Patterns are not code No matter what the Gang of Four say Class::* is code Ergo, ...
  • 17. Perl is Better People like Patterns because they get code C++, Java suck at some things (Iterators) Perl doesn’t suck at the same things
  • 18. Further Reading The Perl Review (lots of articles (by me)) “Design Patterns Aren’t” by Mark Jason Dominus http:/ /perl.plover.com/yak/design/ Design Patterns - Erich Gamma, et al. (Gang of Four) Perl Design Patterns Wiki http:/ /perldesignpatterns.com/

×