The hierarchy and composition of Perl modules

As I read more and more about Perl, I have doubts about how I organized my modules in the current project.

I have a main namespace - let me have it "MyProject".

In this project, the base data are graphs in which each object has a class. objects are related to relationships. Both objects and relationships can have attributes.

There is a part of the project where I use the model to check these graphs. Therefore, I have a Model class, which consists of Class, Relation, and Attribute objects.

Classes Class, Relation, and Attribute are only used by the Model class, so it was wise for me to organize the modules as follows:

  • MyProject :: Model
  • MyProject :: Model :: Class
  • MyProject :: Model :: Value
  • MyProject :: Model :: Attribute

But I'm starting to think that it will only make sense to me if I ever dare to transfer part of my project to CPAN. I think people will believe that Class, Relation, and Attribute inherit the model and not make it up.

So: should I reorganize my modules as follows:

  • MyProject :: Model
  • MyProject :: Class
  • MyProject :: communication
  • MyProject :: Attribute

Or maybe indicate that Class, Relation and Attribute are parts of the model, adding their names?

  • MyProject :: Model
  • MyProject :: ModelClass
  • MyProject :: ModelRelation
  • MyProject :: ModelAttribute

My question is : What are currently the best methods for organizing modules and their names when it comes to composition?

Cross on Perlmonks

+4
source share
1

. , , . . , -.

. , CPAN. , :

OurCompany::Shop

, , ,

OurCompany/Shop.pm

, -. MCV, . :

OurCompany::Shop::Controller::ProductSearch
OurCompany::Shop::Controller::Cart
OurCompany::Shop::Controller::Checkout
OurCompany::Shop::Model::Database

.

OurCompany/Shop/Controller/ProductSearch.pm
OurCompany/Shop/Controller/Cart.pm
OurCompany/Shop/Controller/Checkout.pm
OurCompany/Shop/Model/Database.pm

OurCompany::Controller. - .

, , OurCompany:: Shop, .

OurCompany::Shop::Session

, .

, , - . , Redis . ( , CPAN ),

OurCompany::Shop::Session::Engine::Redis

, , - OurCompany:: Shop:: Session . , . , Redis , .

OurCompany::Shop::Session::Engine::File

, :: Session, - , , .

1. .

OurCompany::Shop::Product

.

OurCompany/Shop/Product.pm

, , , :: ( isa). , :: Session, .

, , , . , . .

OurCompany::Shop::Product::Shoe
OurCompany::Shop::Product::HardDrive

.

OurCompany/Shop/Product/Shoe.pm
OurCompany/Shop/Product/HardDrive.pm

HardDrive SSD, :: SSD.

OurCompany::Shop::Product::HardDrive::SSD

OurCompany/Shop/Product/HardDrive/SSD.pm

, , . .

.
└── OurCompany
    β”œβ”€β”€ Shop
    β”‚   β”œβ”€β”€ Controller
    β”‚   β”‚   β”œβ”€β”€ Cart.pm
    β”‚   β”‚   β”œβ”€β”€ Checkout.pm
    β”‚   β”‚   └── ProductSearch.pm
    β”‚   β”œβ”€β”€ Model
    β”‚   β”‚   └── Database.pm
    β”‚   β”œβ”€β”€ Product
    β”‚   β”‚   β”œβ”€β”€ HardDrive
    β”‚   β”‚   β”‚   └── SSD.pm
    β”‚   β”‚   β”œβ”€β”€ HardDrive.pm
    β”‚   β”‚   └── Shoe.pm
    |   β”œβ”€β”€ Product.pm
    β”‚   └── Session.pm
    β”‚   β”‚   └── Engine.pm
    β”‚   β”‚       β”œβ”€β”€ File.pm
    β”‚   β”‚       └── Redis.pm
    └── Shop.pm

:

  • . .
  • , , .
  • , -, .
  • , , .

, MyProject:: AB, , MyProject:: A. . , :

OurCompany::ShopProductShoe

1) , backoffice, . OurCompany:: Product, : OurCompany:: Shop OurCompany:: BackOffice.

+9

Source: https://habr.com/ru/post/1665981/


All Articles