Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine

Install Perl module from CPAN (Apple Mac Service)

by usemodperl (Beadle)
on Jul 08, 2018 at 18:16 UTC ( #1218123=CUFP: print w/replies, xml ) Need Help??

Installing Perl modules from CPAN just got easier for Apple users.
This service enables the following functionality in macOS/OSX:
  1. Select the name of a Perl module in any application.
  2. Select: Services -> Install Perl module from CPAN
  3. Terminal opens and CPAN client installs the module!
This sends any selected text to the CPAN client, so it can invoke any
command and install multiple modules, or just make a mess. The name
of the service shown above is an option you set when saving the service.
Use this Applescript code to create the service with Automator:

(* Apple macOS/OSX Automator Service. *) (* Install selected Perl CPAN module! *) (* Customize the CPAN variable below: *) on run {input} set CPAN to "cpanm" try tell application "Terminal" activate tell application "System Events" to keystroke "n" using {c +ommand down} end tell tell application "System Events" tell application process "Terminal" set frontmost to true set CMD to CPAN & " " & input keystroke CMD keystroke return end tell end tell end try end run (* Source: *)


Replies are listed 'Best First'.
Re: Install Perl module from CPAN (Apple Mac Service)
by kcott (Archbishop) on Jul 09, 2018 at 10:11 UTC

    G'day usemodperl,

    Unfortunately, I see a problem with what you have here. Consider this scenario.

    Let's say you're running macOS 10.x which provides Perl 5.x; you follow the steps you show and install a variety of CPAN modules; these are now all available for Perl 5.x code to load. At some later point, you upgrade to macOS 10.y which uses Perl 5.y; Perl 5.x is completely removed along with all modules installed using that version of Perl.

    I've been using macOS (formerly Mac OS X) for about eight or nine years; the scenario I've just described seems to have been standard Apple practice for all of that time. I'm away from home (where my Mac is) at the moment so I can't test any this: please correct me if you think some (or even all) of this is wrong.

    I continue to recommend leaving the System Perl (/usr/bin/perl) alone on Mac systems and instead use perlbrew and install modules using your preferred cpan utility.

    — Ken

      Unfortunately, I see a problem with what you have here.

      Thanks for your concern but there is no problem. This service will not install modules in system perl (unless modified to use sudo, etc). This service simply copies the name of a selected module and pastes it to your preferred CPAN client. If you're using perlbrew, as is recommended, the module installs in whatever perl is in use at the time (just like shell).


        Thanks for the feedback. It was unclear from the OP that it worked like this and, as I said, I'm not currently in a position to try it out.

        — Ken

Re: Install Perl module from CPAN (Apple Mac Service)
by marto (Cardinal) on Jul 09, 2018 at 18:57 UTC

    "This sends any selected text to the CPAN client"

    It doesn't, you should be more specific. It uses cpanm rather than cpan. The latter ships with perl, the former does not.

      >> This sends any selected text to the CPAN client"

      > It doesn't

      Yes. It. Does. How hard is it to configure this software?

      set CPAN to "cpanm"

      If you don't like noisy cpanm set CPAN to "cpanm -q".
      If you don't like cpanm set CPAN to "cpan".
      If you don't like my software, create your own! ☺
      (Help is always available from the generous Perlmonks!)


        "Yes. It. Does"

        It doesn't. You've set the default value to something that doesn't exist by default, referred to cpanm as cpan.

Re: Install Perl module from CPAN (Apple Mac Service)
by Anonymous Monk on Jul 09, 2018 at 07:11 UTC
    This is CUFP, this is not perl you posted. Takes longer to select and invoke the service than just typing. potentially dangerous
      Greetings Anonymous Friend! This Applescript wrapper for your CPAN client was developed to enhance accessibility on Apple Mac so Perl modules can be installed without typing (see System Preferences -> Accessibility). Physical situations and disabilities exist that prevent typing, or make it difficult, and this software solves that problem. I have thousands of CPAN modules installed and can assure you this is an efficient TIMTOWTDI to typing. Can you elaborate on the potential dangers of essentially copying and pasting text to a CPAN client? I'm eager to fix any problems.

      This code provides several innovations that do not
      otherwise exist in the known universe AFAIK:

      1. Extends your CPAN client to respond to mouse actions only, no keyboard is required to install modules.

      2. Extends the CPAN site to have something like a "click to install" button except this requires: click; select; click; click: Perl module installed! One can also assign a keyboard shortcut (System Preferences -> Keyboard -> Shortcuts -> Services) to eliminate the last 2 clicks: click; select; key: Installed!

      3. Extends your browser as if some sort of CPAN plugin was installed since modules can be selected from any site.

      4. Extends the entire OS by providing glue between selected text and CPAN and Perl.

      All that with one word of Perl wrapped in 17 lines of Applescript! To see the Perl that cpan and cpanm mean type less $(which cpanm) in shell. Thank you for participating in the development of free accessibility software for Apple Mac OSX and macOS written for Perl and CPAN!

      This code can also be implemented as a voice command to make your own Perl-centric voice assistant: "Hey CPAN, install Some::Module", "Dave, The module has been installed.", "Ok CPAN, install Other::Module", "I'm sorry Dave. I'm afraid I can't do that. Other::Module is already installed. Would you like to upgrade or reinstall the module, Dave?"


Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: CUFP [id://1218123]
Approved by haukex
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (7)
As of 2022-12-06 19:45 GMT
Find Nodes?
    Voting Booth?

    No recent polls found