A typical Perl project directory structure - ScienceChronicle
ScienceChronicle
September 1, 2024

A typical Perl project directory structure

Posted on September 1, 2024  •  3 minutes  • 539 words
Table of contents

A typical Perl project directory structure is designed to separate the main script(s) from modules, configurations, and other resources like tests or documentation. Here’s an example of a standard Perl project directory structure:

my_perl_project/
├── bin/
│   └── main.pl
├── lib/
│   ├── MyApp/
│   │   ├── Module1.pm
│   │   └── Module2.pm
├── t/
│   ├── 01_module1.t
│   └── 02_module2.t
├── script/
│   └── some_utility_script.pl
├── doc/
│   └── README.md
├── Makefile.PL
└── MANIFEST

Breakdown of the Structure

1. bin/ Directory:

2. lib/ Directory:

Typical Module Structure:

# lib/MyApp/Module1.pm
package MyApp::Module1;

use strict;
use warnings;

sub new {
    my $class = shift;
    return bless {}, $class;
}

sub do_something {
    print "Doing something...\n";
}

1;

3. t/ Directory:

Typical Test Structure:

# t/01_module1.t
use strict;
use warnings;
use Test::More tests => 1;
use MyApp::Module1;

my $module = MyApp::Module1->new();
isa_ok($module, 'MyApp::Module1');

4. script/ Directory:

5. doc/ Directory:

6. Makefile.PL:

7. MANIFEST:

Example:

bin/main.pl
lib/MyApp/Module1.pm
lib/MyApp/Module2.pm
t/01_module1.t
t/02_module2.t
Makefile.PL
MANIFEST

Usage

Summary

This directory structure provides a clean and organized way to manage Perl projects, separating the main script, modules, tests, and other resources. It follows common conventions used in the Perl community and makes it easier to maintain and scale your project.


Share


Tags


Counters

Support us

Science Chronicle