andrewalker / p5-business-cpi

Common Payment Interface
6 stars 2 forks source link

Namespace specification #31

Open dionys opened 9 years ago

dionys commented 9 years ago

The drivers and their parts (like buyer, card, etc) uses different methods to create the namespaces. For example, if we have the driver MyDriver, then its module will be named Business::CPI::Gateway::MyDriver (like Business::CPI::Gateway::PayPal). But the buyer module for this driver will be named Business::CPI::MyDriver::Buyer, because Business::CPI::Util::load_class() function uses template Business::CPI::${driver_name}::${class_name}. So we have two different ways to create the namespaces ${class_name}::${driver_name} and ${driver_name}::${class_name}.

I think that need to use only one of these ways:

Business::CPI::Gateway::MyDriver
Business::CPI::Buyer::MyDriver

or

Business::CPI::MyDriver::Gateway
Business::CPI::MyDriver::Buyer

or may be third

Business::CPI::Gateway::MyDriver
Business::CPI::Gateway::MyDriver::Buyer

And I propose the first (${class_name}::${driver_name}) way.

andrewalker commented 9 years ago

Thank you for your input, @dionys.

This issue annoys me too, and maybe I didn't think it through when I was first creating the classes :) But still, I'm not quite sure of what would be the best way to go.

The third way seemed too long for me. The second way would seem messy with internal namespaces, so that Business::CPI::PayPal::* is in the same namespace as Business::CPI::Role::*, etc. Seems weird to me, but maybe I should just get over it. Another issue would be that it wouldn't be clear that Business::CPI::MyDriver::Gateway is the main class of MyDriver. Maybe it should be called just Business::CPI::MyDriver? But then again, there are things like Business::CPI::Util. Seems incoherent to me.

Finally, the first case.. my issue with it is that a typical, complex, driver would have a directory more or less like this:

- lib/
     - Business/
         - CPI/
             - Gateway/
                - MyDriver.pm
             - Buyer/
                - MyDriver.pm
             - Cart/
                - MyDriver.pm
             - Item/
                - MyDriver.pm
             - Receiver/
                - MyDriver.pm
             - Account/
                - MyDriver.pm

That is also weird for me. When it gets installed, the driver won't have a directory of it's own, it will be scattered around the same folders as the other drivers.

Well, anyway, these are my thoughts on the issue. Do you still think ${class_name}::${driver_name} is the way to go? Why do you prefer that way?

dionys commented 9 years ago

Hmm. You’re right.

Taking in response to your comments I see 2 ways:

  1. Too long namespace:
    • Business::CPI::Gateway::MyDriver
    • Business::CPI::Gateway::MyDriver::*
  2. Another namespace (like DBI & DBD)
    • Business::CPG::MyDriver (or CPIG, or CPD, etc)
    • Business::CPG::MyDriver::*
andrewalker commented 9 years ago

I hadn't thought of the other namespace! Sounds very reasonable!

renatocron commented 9 years ago

I think another name-space looks more intelligent decision!

Renato,

Eokoe.com

On Wed, Feb 4, 2015 at 6:58 PM, André Walker notifications@github.com wrote:

I hadn't thought of the other namespace! Sounds very reasonable!

— Reply to this email directly or view it on GitHub https://github.com/andrewalker/p5-business-cpi/issues/31#issuecomment-72937492 .

dionys commented 9 years ago

So. If you will use another namespace, then no more needed Business::CPI::Base namespace: Business::CPI::Base::Buyer will be Business::CPI::Buyer, etc.

andrewalker commented 9 years ago

Sure. Much better.