the perldoc page on CPAN.pm confuses the hell out of me.
Yes, documentation of the CPAN API is still a bit lacking. It wasn't every really designed for programmatic use by others. You might have better luck with CPANPLUS, if that's available to you.
My program needs to download a couple of modules if they don't already exist. Is this basically just: CPAN::Shell->install("Module::Name::Here");
Yes, that's pretty much it for the simplest possible thing. In fact, that's pretty much all the 'cpan' command line program does when you type "cpan Module::Name::Here". However, you will need to have CPAN.pm configured in advance.
Does that download the package, unarchive it, and install it?
Yes, all three.
I would like it to make sure it doesn't try to re-install anything if the package is already there - is this the default behavior of the function or no?
Yes, the default behavior is not to install anything if the module is up to date. You can actually check that yourself with the "uptodate()" method like this:
my $mod = CPAN::Shell->expand("Module", "Module::Name::Here");
$mod->install unless $mod->uptodate;
And how can I tell if Perl couldn't connect to CPAN to get the package?
That's hard to do programmatically in a way that would be simple to explain. You either need to look at the output or else just check $mod->uptodate afterwards;
my $mod = CPAN::Shell->expand("Module", "Module::Name::Here");
if ( ! $mod->uptodate ) {
$mod->install;
die "Problems installing" unless $mod->uptodate;
}
Best of luck!