Class AutomateIt::PackageManager::CPAN
In: lib/automateit/package_manager/cpan.rb
Parent: ::AutomateIt::PackageManager::BaseDriver

PackageManager::CPAN

A PackageManager driver for Perl CPAN (Comprehensive Perl Archive Network) software packages.

No automatic dependency installation

Unlike other AutomateIt PackageManager drivers, the CPAN driver will not install a package‘s dependencies automatically. This protects you because many CPAN packages require a specific version of Perl, often one which you don‘t have installed, and installing that dependency will destroy your Perl interpreter and everything that depends on it. Therefore, you must specify all package dependencies manually. If a package dependency isn‘t found, the install will fail.

Specifying Perl interpreter

Use setup to specify the Perl interpreter to use for all subsequent calls.

Example:

  package_manager[:cpan].setup(:perl => "/usr/local/bin/perl")
  package_manager.install %w(File::Next App::Ack), :with => :cpan

Methods

Constants

CPAN_WRAPPER = File.join(::AutomateIt::Constants::HELPERS_DIR, "cpan_wrapper.pl")

Attributes

perl  [RW]  Path to Perl interpreter

Public Instance methods

Options:

  • :perl — Command to use as the Perl interpreter, otherwise defaults to the one specified during setup or to "perl"

See AutomateIt::PackageManager#install

[Source]

# File lib/automateit/package_manager/cpan.rb, line 76
  def install(*packages)
    return _install_helper(*packages) do |list, opts|
      perl = opts[:perl] || self.perl
      cmd = "#{perl} #{CPAN_WRAPPER} --install #{list.join(' ')}"
      cmd << " > /dev/null" if opts[:quiet]
      cmd << " 2>&1"

      interpreter.sh(cmd)
    end
  end

Options:

  • :perl — Command to use as the Perl interpreter, otherwise defaults to the one specified during setup or to "perl"

See AutomateIt::PackageManager#installed?

[Source]

# File lib/automateit/package_manager/cpan.rb, line 51
  def installed?(*packages)
    return _installed_helper?(*packages) do |list, opts|
      perl = opts[:perl] || self.perl
      cmd = "#{perl} #{CPAN_WRAPPER} --query #{list.join(' ')}"

      # FIXME if CPAN isn't configured, this will hang because Perl will demand input
      log.debug(PEXEC+cmd)
      output = `#{cmd}`
      output.sub!(/.*---(\s[^\n]+)?\n/m, '')
      struct = ::YAML.load(output)

      struct["available"] || []
    end
  end

See AutomateIt::PackageManager#not_installed?

[Source]

# File lib/automateit/package_manager/cpan.rb, line 67
  def not_installed?(*packages)
    # TODO Move #not_installed? up to BaseDriver
    return _not_installed_helper?(*packages)
  end

Setup the PackageManager::CPAN driver.

Options:

  • :perl — The absolute, relative or unqualified path for the Perl interpreter to use. E.g., "perl" or "/usr/local/bin/perl".

[Source]

# File lib/automateit/package_manager/cpan.rb, line 31
  def setup(*args)
    super(*args)

    args, opts = args_and_opts(*args)
    if opts[:perl]
      self.perl = opts[:perl]
    else
      self.perl ||= "perl"
    end
  end

Options:

  • :perl — Command to use as the Perl interpreter, otherwise defaults to the one specified during setup or to "perl"

See AutomateIt::PackageManager#uninstall

[Source]

# File lib/automateit/package_manager/cpan.rb, line 91
  def uninstall(*packages)
    return _uninstall_helper(*packages) do |list, opts|
      perl = opts[:perl] || self.perl
      cmd = "#{perl} #{CPAN_WRAPPER} --uninstall #{list.join(' ')} < /dev/null"
      cmd << " > /dev/null" if opts[:quiet]
      cmd << " 2>&1"

      interpreter.sh(cmd)
    end
  end

[Validate]