http://www.perlmonks.org?node_id=639645


in reply to Comments and suggestions on new module

I've noticed in almost every method that you had "if it's GD, do A, if it's Imager, do B, etc.." This screams to me that you need to do some deeper encapsulation.

I would propose that you have Image::Mate::(GD|Imager|Image::Magick) and when new() is called bless your object to the user's preference.

Just my 2 cents.

--
"Go up to the next female stranger you see and tell her that her "body is a wonderland."
My hypothesis is that she’ll be too busy laughing at you to even bother slapping you.
" (src)

  • Comment on Re: Comments and suggestions on new module

Replies are listed 'Best First'.
Re^2: Comments and suggestions on new module
by Anonymous Monk on Sep 18, 2007 at 16:02 UTC
    Ok... Care to elaborate with a quick code example?
      package X; our $PREF; sub new { bless {}, $PREF; } package A; sub foo { print __PACKAGE__; } package B; sub foo { print __PACKAGE__; } package main; $X::PREF = 'B'; my $o = X->new; $o->foo;

      Prints:

      B

      You can change $X::PREF = line to 'A' and it will print A.

      --
      "Go up to the next female stranger you see and tell her that her "body is a wonderland."
      My hypothesis is that she’ll be too busy laughing at you to even bother slapping you.
      " (src)

        I see. I update with this style in my next release, glad I didn't add to many more features now.