Carton::Doc::FAQ(3pm)
π NAME π
Okay so bestie, this is Carton::Doc::FAQ β straight from the User Contributed Perl Documentation, aka the Carton::Doc::FAQ(3pm) page π β and it is literally just Frequently Asked Questions. That's the whole thing. Buckle up. π¦
π¬ QUESTIONS π¬
"It looks useful, but what is the use case of this tool?" π
The particular problem that carton is trying to address is this:
You develop a Perl-based application, possibly but not limited to webapps, with dozens of CPAN module dependencies. You install these modules on your development machine, and describe these dependencies in your cpanfile.
Now you get a production environment, either on a PaaS provider or some VPS, you install the dependencies using cpanm --installdeps . and it will pull all the latest releases from CPAN as of today and everything just works. β¨
A few weeks later, your application becomes more popular, and you think you need another machine to serve more requests. You set up another machine with a vanilla perl installation and install the dependencies the same way. That will pull the latest releases from CPAN on that date, rather than the same as what you have today.
And that is the problem. It's not likely that everything just breaks one day, but there's always a chance that one of the dependencies breaks an API compatibility, or just uploaded a buggy version to CPAN on that particular day. π
Carton allows you to lock these dependencies into a version controlled system, so that every time you deploy from a checkout, it is guaranteed that all the same versions are installed into the local environment. π
"How is this different from Pinto or CPAN::Mini::Inject?" π¦
carton definitely shares the goal with these private CPAN repository management tools. But the main difference is that rather than creating an actual CPAN-like repository that works with any CPAN clients, Carton provides a way to install specific versions of distributions from CPAN, or any CPAN-like mirrors (as well as git repositories in the future version of Carton).
Existing tools are designed to work with CPAN clients such as CPAN or CPANPLUS, and have accomplished that by working around the CPAN mirror structure.
carton internally does the same thing, but its user interface is centered around the installer, by implementing a wrapper for cpanm, so you can use the same commands in the development mode and deployment mode. π
Carton automatically maintains the cpanfile.snapshot file, which is meant to be version controlled, inside your application directory. You don't need a separate database, a directory or a web server to maintain tarballs outside your application. The cpanfile.snapshot file can always be generated with carton install command, and carton install on another machine can use the version in the snapshot.
"I already use Pinto to create DarkPAN mirror. Can I use Carton with this?" π
Yes π― β by specifying Pinto mirror as your Carton mirror, you can take a snapshot of your dependencies including your private modules on Pinto, or whatever DarkPAN mirror.
"I'm already using perlbrew and local::lib. Can I use carton with this?" π§
If you're using local::lib already with perlbrew perl, possibly with the new perlbrew lib command, that's great! There are multiple benefits over using perlbrew and local::lib for development and use Carton for deployment.
The best practice and workflow to get your perl environment as clean as possible with lots of modules installed for quick development would be this:
- Install fresh perl using perlbrew. The version must be the same against the version you'll run on the production environment.
- Once the installation is done, use
perlbrew libcommand to create a new local lib environment (let's call it devel) and always use the library as a default environment. Install as many modules as you would like into the devel library path.
This ensures to have a vanilla perl library path as clean as possible. π«§
- When you build a new project that you want to manage dependencies via Carton, turn off the devel local::lib and create a new one, like myapp. Install Carton and all of its dependencies to the myapp local::lib path. Then run
carton installlike you normally do.
Because devel and myapp are isolated, the modules you installed into devel doesn't affect the process when carton builds the dependency tree for your new project at all. This could often be critical when you have a conditional dependency in your tree, like Any::Moose. π₯
"I'm using perlbrew, but carton install uses system perl, how to fix?" π
The issue is most likely caused by an initial bad install of cpanm or carton or both, that ended up with a shebang line pointed to the (wrong) system perl. Classic. π
Re-install Carton on your perlbrew environment π«Ά
Run cpanm -f Carton. This will force-install Carton, and because your cpanm is now using the correct perl, the same will happen with carton.
Make sure the shebang (the first line) of your carton script points to the right perl path, rather than /usr/bin/perl.
And that's the whole FAQ bestie, no cap π this page is from perl v5.34.0, dated 2022-05-12, and it lives at Carton::Doc::FAQ(3pm) β go lock your deps and slay your deploys πβ¨πΈ
π¦ where this page comes from
- debian bookworm: carton 1.0.35-1 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- debian trixie: carton 1.0.35-1 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu noble: carton 1.0.35-1 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms