Am I a Convert???

Some time ago I was on a team that was rewriting a very large legacy system. We wanted to use a more maintainable OO style (rather then just a huge global hash-ref ) but unfortunately the team was restricted by using only perl 5.6.0. By the time I joined the project work was well underway and I was still stuck doing accessors by hand. So I came up with this little beastly Orignal to solve that problem.

It fixed things up nicely as we could have nice 5.14 style accessors with some silly other little bits that came in very handy at least to us.

As we progressed along we noticed an anti patten developing in our code. We where using a god mod stuff full of goddies used all over the place. We started with a simple base class with a few universal attributes and just used good old use base to extend other classes by it like this

use base qw(KW::Abstract);

Well eventually we stuffed so much into this base class we had a good deal of extra attributes and functionality open across the system. We had field and type validation, class validation. We had so much we broke it down into smaller Utility mods and used them something like this
use base qw(KW::Base KW::User KW::Date KW::Validate::Email );

Turns out the name of this anti-pattern is BaseBean

So we got that one worked out. As we progressed (or digressed perhaps) we began to run into another anti-pattern. Seems as our little objects were being used in bigger and more complex objects and we had to start doing this;

sub new {

my $self = shift;
$self = $self->SUPER::new(@_);
my ($opt) = @_;

and sometimes this

sub new {
my $self = shift;
my ($opt) = @_;
$self = $self->SUPER::new(@_);

We ending up with sorts of little developer notes reminding us to call SUPER::New at the proper point. Seems this one has a name as well, the very obvious call super.

Fortunately not all was lost as all we had to do was stub in a before and after code in Orignal base that would call new for us. Seem my 4th year Lisp course did come in handy after all.

In the end things worked out and the project finished up and the client was happy.

Where is this leading?

Well I recently took up Moose full time and surprise surprise by default I get rid of these two design patterns simply by using Moose. I also get validation, roles etc etc.

So maybe I am a convert?

I guess I must be, because the more and more I adjusted my little Orignal mod to git rid of design patterns and add in some functionality the more and more it became like Moose!

I guess all paths are on the road to enlightenment.

Leave a comment

About byterock

user-pic Long time Perl guy, a few CPAN mods allot of work on DBD::Oracle and a few YAPC presentations