Logo

dev-resources.site

for different kinds of informations.

App::cpx

Published at
9/5/2024
Categories
perl
cpan
npx
Author
thibaultduponchelle
Categories
3 categories in total
perl
open
cpan
open
npx
open
Author
19 person written this
thibaultduponchelle
open
App::cpx

(Picture from Erda Estremera)

Background

I'm sometimes doing Front End dev.

Or sometimes the best tool for the job is only installable via npm.

It can be scripts to "uglify" or "beautify" css/js, optimize svg files (svgo) or clients to SaaS platforms (wrangler).

Actually, it's not that important if it's part of javascript ecosystem, what I want is just to execute them!

The usual process: I start testing it locally, quickly and in a "trash-able" way, then install in a continuous integration pipeline, then forget πŸ˜„

So far, do you feel some resemblance with some periodical process or yours?

For this purpose, I'm using frequently npx (now part of npm).

Do you see now where I'm going to? πŸ€”

App::cpx, a npx-like for CPAN

I just uploaded App::cpx for this purpose.

Give cpx a binary and it will find it in CPAN, install it for you then execute it.

$ cpx hr -s 40
🎯 Found [bin/hr]
πŸ“¦ Release to install [https://cpan.metacpan.org/authors/id/W/WO/WOLDRICH/App-term-hr-0.11.tar.gz]
πŸ”§ Will install into /home/tib/cpx-test/.cpx
DONE install Term-ExtendedColor-0.504
DONE install App-term-hr-0.11
2 distributions installed.
=======================================
Enter fullscreen mode Exit fullscreen mode

(purpose of hr is to draw horizontal lines)

Or another example with mlocate:

$  cpx mlocate Redis Moo
🎯 Found [bin/mlocate]
πŸ“¦ Release to install [https://cpan.metacpan.org/authors/id/C/CE/CELOGEEK/App-Module-Locate-0.7.tar.gz]
πŸ”§ Will install into /home/tib/cpx-test/.cpx
DONE install Module-Locate-1.80
DONE install Module-Build-0.4234
DONE install App-Module-Locate-0.7
3 distributions installed.
/usr/local/share/perl/5.34.0/Redis.pm
/usr/local/share/perl/5.34.0/Moo.pm
Enter fullscreen mode Exit fullscreen mode

mlocate is a script that lives in App::Module::Locate. It's an utility to "find a module by its name".

cpx saves you from some frustrating tries:

  • Is it cpm install App::mlocate?
  • OK try capitalize cpm install App::Mlocate, I know some authors do that
  • Hmm maybe simply locate like this cpm install App::locate
  • Oh wait, capitalize cpm install App::Locate
  • Raaah! Stop it and open MetaCPAN and search
  • OK it's cpm install App::Module::Locate but now it's installed locally, how do I set local::lib? Maybe I should install globally
  • Hmm I will install globally even if it can be a bit dirty for a one time use

And at start were you 100% sure mlocate was something that exists in CPAN? πŸ€”

cpx saves you from this pain and hides you the internals of installing the module, if missing.

When running cpx again, it won't reinstall but reuse the already installed binary:

$ cpx mlocate Redis Moo
βš“ Found executable already installed
/usr/local/share/perl/5.34.0/Redis.pm
/usr/local/share/perl/5.34.0/Moo.pm
Enter fullscreen mode Exit fullscreen mode

Your companion for Continuous Integration

$ curl -sL https://git.io/cpm | sudo perl - install -g App::cpx
$ cpx hr -s 40
Enter fullscreen mode Exit fullscreen mode

In GitHub Actions, it would give something like this:

name : Test cpx
on: push
jobs:
  cpx:
    runs-on: ubuntu-latest

    steps:
      - name: Install cpx
        run: curl -sL https://git.io/cpm | sudo perl - install -g App::cpx
      - name: cpx hr 
        run: cpx hr -s 40
Enter fullscreen mode Exit fullscreen mode

And see the result:
GitHub Action cpx

Conclusion

As of now, the code for this small utility is ridiculously simple (source), but sometimes good ideas (yes, all glory to myself πŸ˜€) are simple to implement.

Resources

  • I'm still lazy - Great module discussed here and I stole the idea of using App::cpm::CLI
cpan Article's
30 articles in total
Favicon
A link site of your very own
Favicon
App::cpx
Favicon
Combining calendars
Favicon
Installing CPAN modules from git
Favicon
Deploying Dancer Apps
Favicon
Feature release 1.36 of the Date::Holidays Perl distribution
Favicon
Building a tool to integrate Readwise.io highlights into my Zettelkasten via Perl
Favicon
Dist::Zilla::Plugin::GitHub::CreateRelease
Favicon
GitHub Organisations
Favicon
Mission (Almost) Accomplished
Favicon
Writing a CPAN module that talks to ChatGPT
Favicon
How to download cpanm in the portable way that supports Perl 5.8.1
Favicon
SPVM::IO 0.14 is released on Perl/CPAN
Favicon
Feature release 1.32 of Date::Holidays Perl distribution
Favicon
CPAN Module Tutorials
Favicon
cpanm - Installation of Perl Modules on User Directories 2022
Favicon
Wrapping a JSON API to access your personal data
Favicon
Highlighting members of the Perl family
Favicon
Create foo.a using Pure Perl and Archive::Ar
Favicon
Multiple ways to inheritance in Perl
Favicon
Taming the Moose: Classing up Perl attributes
Favicon
Some thoughts on Perl template processing
Favicon
Making Single-binary Release with pp
Favicon
The reports of Perl’s death have been greatly exaggerated
Favicon
Read The Fantastic Manual: How to get the most out of Perl documentation
Favicon
Failing to get product information from Amazon with Perl
Favicon
CPAN Release of TooMuchCode 0.18
Favicon
Fast Perl module installation with cpm
Favicon
CPAN installation as a test, with GitHub workflow
Favicon
CPAN Release of TooMuchCode 0.17

Featured ones: