This tutorial walks you through some of the typical use cases for a Pinto repository.
Along the way,
it demonstrates most of the pinto commands.
You are encouraged to try the commands as you read along.
If you would prefer to get a more condensed summary of features and commands,
please read the Pinto::Manual::QuickStart.
For detailed instructions on installing the software read Pinto::Manual::Installing.

The first step in using Pinto is to create a repository,
using the init command like this:

$> pinto -r ~/repo init

This will create a new repository in the ~/repo directory. If that directory does not exist, it will be created for you. If it already does exist, then it must be empty.

The -r (or --root) option specifies where the repository is. This argument is required for every pinto command. But if you get tired of typing it, you can set the PINTO_REPOSITORY_ROOT environment variable to point to your repository instead.

The repository is created with a stack called "master" which is also marked as the default stack. We'll talk more about stacks and default stack later.

Suppose we are working on an application called My-App that contains a package called My::App. The application also depends on the URI package. Using the pull command, you can bring the URI package into your repository:

$> pinto -r ~/repo pull URI

You will be prompted to enter a log message that describes why this change is happening. The message template will include a semi-informative generated message. Feel free to edit this message as you see fit. Save the file and close your editor when you are done.

Now, you should have URI in your local repository. So lets look and see what we really got. Once again, you use the list command to see inside the repository:

Now suppose that you've finished work on My-App and your ready to release the first version. Using your preferred build tool (ExtUtils::MakeMaker, Module::Build, Module::Install etc.) you package a release as My-App-1.0.tar.gz. Now put the distribution into the repository with the add command:

$> pinto -r ~/repo add path/to/My-App-1.0.tar.gz

When you list the repository contents now, it will include the My::App package and show you as the author of the distribution:

Now the repository contains both your application and all of its prerequisites, so you can install it into your environment using the install command:

$> pinto -r ~/repo install My::App

When My::App is installed, it will only use the prerequisites that are in your repository. Even if a newer version of URI is released to the CPAN in the future, My::App will always be built with the same versions of the same prerequisites that you developed and tested against. This ensures your application builds will be stable and predictable.

On the surface, a Pinto repository looks like an ordinary CPAN, so you can also install packages from it using cpanm directly. All you have to do is point them at the URL of your repository (under the hood, this is all the install command is really doing anyway). For example:

Suppose that several weeks have passed since you first released My-App and now URI version 1.62 is available on the CPAN. It has some bug critical fixes that you'd like to get. Again, we can bring that into the repository using the pull command. But since your repository already contains a version of URI, you must indicate that you want a *newer* one by specifying the minimum version that you want:

$> pinto -r ~/repo pull URI~1.62

If you look at the listing again, this time you'll see the newer version of URI (and possibly other packages as well):

So far in this tutorial, we've treated the repository as a singular resource. For example, when we upgraded URI in the last section, it impacted every person and every application that might have been using the repository. But this kind of broad impact is undesirable. You would prefer to make those kinds of changes in isolation and test them before forcing everyone else to upgrade. This is what stacks are designed for.

All CPAN-like repositories have an index which maps the latest version of each package to the archive that contains it. Usually, there is only one such index per repository. But with Pinto, there can be many indexes. Each of these indexes is called a "stack". This allows you to create different stacks of dependencies within a single repository. So you could have a development stack and a production stack. Whenever you add a distribution or upgrade a prerequisite, it only affects one stack.

Before getting into the gory details, you first need to know about the default stack. For most operations, the name of the stack is an optional parameter. So if you do not specify a stack explicitly, then the operation is applied to whichever stack is marked as the default.

In any repository, there is never more than one default stack. When we created this repository, the master stack was marked as the default. You can also change the default stack or change the name of a stack, but we won't go into that here. See the default command to learn more about that.

Just remember that master is the name of the stack that was created when the repository was first initialized.

Suppose your repository contains version 1.60 of URI, but version 1.62 has been released to the CPAN, just like in the earlier section. You want to try upgrading, but this time you're going to do it on a separate stack.

Thus far, everything you've added or pulled into the repository has gone onto the master stack. You could create an entirely new stack, but the master stack already has the prerequisites for My-App, so we're just going to make a clone using the copy command:

$> pinto -r ~/repo copy master uri_upgrade

This creates a new stack called uri_upgrade. If you want to see the contents of that stack, just use the list command with the --stack option:

Now that you've got a separate stack, you can try upgrading URI. Just as before, you'll use the pull command. But this time, you'll tell Pinto that you want the packages to be pulled onto the uri_upgrade stack:

$> pinto -r ~/repo pull --stack uri_upgrade URI~1.62

Now lets compare the master and uri_upgrade stacks using the diff command:

With URI upgraded on the uri_upgrade stack, you can now try building and testing our application. All you have to do is run the install command and point to the right stack:

$> pinto -r ~/repo install --stack uri_upgrade My::App

This will build My::App using only the prerequisites that are on the uri_upgrade stack. If the tests pass, then you can confidently upgrade URI on the dev stack as well.

As mentioned earlier, you can also use cpanm to install modules from your repository. But when installing from a stack other than the default, you must append "stacks/stack_name" to the URL. For example:

In the last section, we used a stack to experiment with upgrading a dependency. Fortunately, all the tests passed. But what if the tests didn't pass? If the problem lies within My-App and you can quickly correct it, you might just modify your code, release version 2.0 of My-App, and then proceed to upgrade URI on the master stack.

But if the issue is a bug in URI or it will take a long time to fix My-App, then you have a real problem. You don't want someone else to upgrade URI, nor do you want it to be upgraded inadvertently to satisfy some other prerequisite that My-App may have. Until the bug is fixed (in either URI or My-App) you need to prevent URI from being upgraded. This is what pins are for.

When you pin a package, that version of the package is forced to stay in a stack. Any attempt to upgrade it (either directly or via another prerequisite) will fail. To pin a package, use the pin command like this:

$> pinto -r ~/repo pin URI

If you look at the listing for the master stack again, you'll see something like this:

The "!" near the beginning of the line indicates the package has been pinned. Notice every package in the URI-1.60.tar.gz distribution has been pinned, so it is impossible to partially upgrade a distribution (this situation could happen when a package moves into a different distribution).

Pins and stacks are used together to help manage change during the development cycle. For example, you could create a stack called prod that contains your known-good dependencies. Likewise, you could create a stack called dev that contains experimental dependencies for your next release. Initially, the dev stack is just a copy of the prod stack.

As development proceeds, you may upgrade or add several packages on the dev stack. If an upgraded package breaks your application, then you'll place a pin in that package on the prod stack to signal that it shouldn't be upgraded.

Sometimes you may find that a new version of a CPAN distribution has a bug but the author is unable or unwilling to fix it (at least not before your next release is due). In that situation, you may elect to make a local patch of the CPAN distribution.

So suppose that you forked the code for URI and made a local version of the distribution called URI-1.60_PATCHED.tar.gz. You can add it to your repository using the add command:

$> pinto -r ~/repo add path/to/URI-1.60_PATCHED.tar.gz

In this situation, it is wise to pin the package as well, since you do not want it to be upgraded until you are sure that the new release includes your patch or the author has fixed the bug by other means.

$> pinto -r ~/repo pin URI

When the author of URI releases version 1.62 with your patch, you'll want to try it before deciding to unpin from your locally patched version. Just as before, this can be done by cloning the stack with the copy command. Let's call it the trial stack this time:

$> pinto -r ~/repo copy master trial

But before you can upgrade URI on the trial stack, you'll have to unpin it there:

$> pinto -r ~/repo unpin --stack trial URI

Now you can proceed to upgrade URI on the stack and try building My::App like this:

The header for each message shows who made the change and when it happened. It also has a unique identifier similar to Git's SHA-1 digests. You can use these identifiers to see the diffs between different revisions or to reset the stack back to a prior revision [NB: this feature is not actually implemented yet].

In this tutorial, you've seen the basic pinto commands for pulling dependencies into the repository, and adding your own distributions to the repository. You've also seen how to use stacks and pins to manage your dependencies in the face of some common development obstacles.

Each command has several options that were not discussed in this tutorial, and there are some commands that were not mentioned here at all. So you are encouraged to explore the manual pages for each command and learn more.