perl-cpan-ecosystem
CPAN Ecosystem Guide
Comprehensive guide for managing Perl modules using cpanm, cpanfile, Carton, and local::lib.
cpanm (cpanminus)
The recommended tool for installing CPAN modules.
Installation
# Using curl
curl -L https://cpanmin.us | perl - --self-upgrade
# Using system package manager
# Debian/Ubuntu
sudo apt install cpanminus
# macOS
brew install cpanminus
# From CPAN
cpan App::cpanminus
Basic Usage
# Install a module
cpanm Module::Name
# Install specific version
cpanm Module::Name@1.23
# Install with dependencies only (for testing)
cpanm --installdeps .
# Quiet installation
cpanm --quiet --notest Module::Name
# Install to local directory
cpanm --local-lib=~/perl5 Module::Name
Common Flags
| Flag | Purpose |
|---|---|
--notest |
Skip tests (faster, less safe) |
--quiet |
Minimal output |
--verbose |
Detailed output |
--force |
Install despite test failures |
--installdeps |
Install dependencies only |
--local-lib=DIR |
Install to specific directory |
--self-upgrade |
Update cpanm itself |
--mirror URL |
Use specific CPAN mirror |
--skip-satisfied |
Skip already installed |
Mirror Configuration
# Use a specific mirror
cpanm --mirror https://cpan.metacpan.org Module::Name
# Use mirror only (no fallback)
cpanm --mirror https://cpan.metacpan.org --mirror-only Module::Name
cpanfile
Declare dependencies in a cpanfile for reproducible installations.
Basic cpanfile
# cpanfile
requires 'Moo';
requires 'Path::Tiny';
requires 'Try::Tiny';
# Version constraints
requires 'DBI', '1.643'; # Exact version
requires 'JSON::XS', '>= 4.0'; # Minimum version
requires 'Plack', '< 2.0'; # Maximum version
requires 'Moose', '>= 2.0, < 3.0'; # Range
# Development dependencies
on 'develop' => sub {
requires 'Perl::Critic';
requires 'Perl::Tidy';
};
# Test dependencies
on 'test' => sub {
requires 'Test::More', '0.98';
requires 'Test::Exception';
requires 'Test::Deep';
};
# Build dependencies
on 'build' => sub {
requires 'Module::Build';
};
# Recommended (not required)
recommends 'JSON::XS';
suggests 'IO::Socket::SSL';
Feature Phases
| Phase | Purpose | When Installed |
|---|---|---|
runtime |
Production deps | Always (default) |
test |
Testing deps | --with-test |
develop |
Dev tools | --with-develop |
build |
Build tools | During build |
Install from cpanfile
# Install all runtime dependencies
cpanm --installdeps .
# Include test dependencies
cpanm --installdeps --with-test .
# Include all phases
cpanm --installdeps --with-develop --with-test .
Carton
Lock dependencies to exact versions for reproducible deployments.
Installation
cpanm Carton
Basic Workflow
# Create cpanfile.snapshot from cpanfile
carton install
# Install to local/ directory
carton install --deployment
# Update dependencies
carton update
# Run script with locked dependencies
carton exec perl script.pl
# Run with specific local path
carton exec --path local perl app.pl
Generated Files
| File | Purpose | Git |
|---|---|---|
cpanfile |
Dependency declaration | Commit |
cpanfile.snapshot |
Locked versions | Commit |
local/ |
Installed modules | Ignore |
.gitignore for Carton
/local/
/.carton/
Deployment Pattern
# Development machine
carton install
git add cpanfile cpanfile.snapshot
git commit -m "Update dependencies"
# Production machine
git pull
carton install --deployment --without develop,test
carton exec perl app.pl
local::lib
Install modules in user directory without root access.
Setup
# Install local::lib
cpanm local::lib
# Initialize (add to shell profile)
eval $(perl -I$HOME/perl5/lib/perl5 -Mlocal::lib)
# Add to ~/.bashrc or ~/.zshrc
echo 'eval $(perl -I$HOME/perl5/lib/perl5 -Mlocal::lib)' >> ~/.bashrc
Environment Variables
local::lib sets these variables:
PERL5LIB=$HOME/perl5/lib/perl5
PERL_LOCAL_LIB_ROOT=$HOME/perl5
PERL_MB_OPT="--install_base $HOME/perl5"
PERL_MM_OPT="INSTALL_BASE=$HOME/perl5"
PATH=$HOME/perl5/bin:$PATH
Custom Installation Path
# Use different directory
eval $(perl -Mlocal::lib=$HOME/myperllib)
# Project-specific
eval $(perl -Mlocal::lib=./local)
Module Resolution Order
Perl searches for modules in this order:
- Directories in
@INC PERL5LIBpaths- Site lib (system-wide)
- Core modules
Check current @INC:
perl -V # Full config including @INC
perl -e 'print join("\n", @INC)'
Finding Modules
Search MetaCPAN
# Using mccpan (if installed)
cpanm App::cpanminus::reporter
cpan-outdated
# Or use web: https://metacpan.org/
Check Installed Modules
# List all installed
perldoc perllocal
# Check specific module
perl -MModule::Name -e 'print $Module::Name::VERSION'
# Using cpan
cpan -l
# Using pmvers (from pmtools)
pmvers Module::Name
Troubleshooting
Common Issues
Module not found after install:
# Check PERL5LIB
echo $PERL5LIB
# Verify module location
perl -MModule::Name -e 'print $INC{"Module/Name.pm"}'
Permission denied:
# Use local::lib instead of sudo
eval $(perl -Mlocal::lib)
cpanm Module::Name
Build failures:
# Install build tools
# Debian/Ubuntu
sudo apt install build-essential
# Check build log
less ~/.cpanm/build.log
XS module compilation:
# Install development headers
sudo apt install libssl-dev # For SSL modules
sudo apt install libxml2-dev # For XML modules
Project Setup Example
Initialize a new Perl project with proper dependency management:
# Create project structure
mkdir -p myapp/{lib,t,bin}
cd myapp
# Create cpanfile
cat > cpanfile << 'EOF'
requires 'Moo';
requires 'Path::Tiny';
requires 'Try::Tiny';
on 'test' => sub {
requires 'Test::More', '0.98';
};
EOF
# Install with Carton
carton install
# Add to .gitignore
echo '/local/' >> .gitignore
echo '/.carton/' >> .gitignore
# Commit dependency spec
git add cpanfile cpanfile.snapshot
Additional Resources
For Perl version management with perlbrew, see the perl-environment-setup skill.
More from jamie-bitflight/claude_skills
perl-lint
This skill should be used when the user asks to lint Perl code, run perlcritic, check Perl style, format Perl code, run perltidy, or mentions Perl Critic policies, code formatting, or style checking.
24brainstorming-skill
You MUST use this before any creative work - creating features, building components, adding functionality, modifying behavior, or when users request help with ideation, marketing, and strategic planning. Explores user intent, requirements, and design before implementation using 30+ research-validated prompt patterns.
11design-anti-patterns
Enforce anti-AI UI design rules based on the Uncodixfy methodology. Use when generating HTML, CSS, React, Vue, Svelte, or any frontend UI code. Prevents "Codex UI" — the generic AI aesthetic of soft gradients, floating panels, oversized rounded corners, glassmorphism, hero sections in dashboards, and decorative copy. Applies constraints from Linear/Raycast/Stripe/GitHub design philosophy: functional, honest, human-designed interfaces. Triggers on: UI generation, dashboard building, frontend component creation, CSS styling, landing page design, or any task producing visual interface code.
7python3-review
Comprehensive Python code review checking patterns, types, security, and performance. Use when reviewing Python code for quality issues, when auditing code before merge, or when assessing technical debt in a Python codebase.
7hooks-guide
Cross-platform hooks reference for AI coding assistants — Claude Code, GitHub Copilot, Cursor, Windsurf, Amp. Covers hook authoring in Node.js CJS and Python, per-platform event schemas, inline-agent hooks and MCP in agent frontmatter, common JSON I/O, exit codes, best practices, and a fetch script to refresh docs from official sources. Use when writing, reviewing, or debugging hooks for any AI assistant.
7agent-creator
Create high-quality Claude Code agents from scratch or by adapting existing agents as templates. Use when the user wants to create a new agent, modify agent configurations, build specialized subagents, or design agent architectures. Guides through requirements gathering, template selection, and agent file generation following Anthropic best practices (v2.1.63+).
6