DEV Community

Tib
Tib

Posted on

5 2

Grab a distribution tarball from CPAN

This is another "CPAN utils" post (sort of) but this time around resolving and fetching tarballs 😃

  1. cpan -g
  2. sourcepan
  3. cpan-get
  4. MetaCPAN::Client + HTTP::Simple

cpan -g

First let's start by using the venerable CPAN:

$ cpan -g Parser::MGC 
Checking Parser::MGC
Reading '/home/tduponchelle/.local/share/.cpan/Metadata'
  Database was generated on Sat, 15 May 2021 16:41:03 GMT
CPAN: LWP::UserAgent loaded ok (v6.53)
Fetching with LWP:
http://www.cpan.org/authors/01mailrc.txt.gz
CPAN: YAML loaded ok (v1.30)
Reading '/home/tduponchelle/.local/share/.cpan/sources/authors/01mailrc.txt.gz'
CPAN: Compress::Zlib loaded ok (v2.102)
............................................................................DONE
Fetching with LWP:
http://www.cpan.org/modules/02packages.details.txt.gz
Reading '/home/tduponchelle/.local/share/.cpan/sources/modules/02packages.details.txt.gz'
  Database was generated on Tue, 18 May 2021 12:29:03 GMT
............................................................................DONE
Debug(CPAN,CPAN.pm,703,[Index,Index.pm,483,all_objects]): mgr[CPAN=HASH(0x563dc712a9e8)] class[CPAN::Module]
Debug(CPAN,CPAN.pm,703,[Index,Index.pm,483,all_objects]): mgr[CPAN=HASH(0x563dc712a9e8)] class[CPAN::Bundle]
Debug(CPAN,CPAN.pm,703,[Index,Index.pm,483,all_objects]): mgr[CPAN=HASH(0x563dc712a9e8)] class[CPAN::Distribution]
Fetching with LWP:
http://www.cpan.org/modules/03modlist.data.gz
Reading '/home/tduponchelle/.local/share/.cpan/sources/modules/03modlist.data.gz'
DONE
Writing /home/tduponchelle/.local/share/.cpan/Metadata
Use of uninitialized value in concatenation (.) or string at /usr/share/perl/5.26/App/Cpan.pm line 1186.
Downloaded [Parser::MGC] to []
Enter fullscreen mode Exit fullscreen mode

sourcepan

Then look at the more developer oriented sourcepan:

$ sourcepan Acme::LSD
Reading '/home/tduponchelle/.local/share/.cpan/Metadata'
  Database was generated on Tue, 18 May 2021 12:29:03 GMT
CONTRA/Acme-LSD-0.04.tar.gz => Acme-LSD-0.04.tar.gz
Enter fullscreen mode Exit fullscreen mode

sourcepan --git could even init for you a repository...

cpan-get

Continue with the newborn cpan-get:

$ cpan-get Test::More
'http://cpan.metacpan.org/authors/id/E/EX/EXODIST/Test-Simple-1.302183.tar.gz' was downloaded.
Enter fullscreen mode Exit fullscreen mode

MetaCPAN::Client + HTTP::Simple

And finish by a mixed MetaCPAN API client + an HTTP client (with no error handling at all 💀):

# Init MetaCPAN client
use MetaCPAN::Client;
my $mcpan = MetaCPAN::Client->new();

# Resolve url
my $download_url = $mcpan->download_url('ExtUtils::MakeMaker');

# Download
use HTTP::Simple;
getstore($download_url->{data}->{download_url}, "EUMM.tgz");
Enter fullscreen mode Exit fullscreen mode

(Should be possible fetch with MetaCPAN::Client, if you know how, please comment)

Heroku

This site is built on Heroku

Join the ranks of developers at Salesforce, Airbase, DEV, and more who deploy their mission critical applications on Heroku. Sign up today and launch your first app!

Get Started

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay