Module: Language::Perl::Shebang Private

Extended by:
T::Helpers
Defined in:
language/perl.rb

Overview

This module is part of a private API. This module may only be used in the Homebrew/brew repository. Third parties should avoid using this module if possible, as it may be removed or changed without warning.

Helper module for replacing perl shebangs.

Constant Summary collapse

PERL_SHEBANG_REGEX =

This constant is part of a private API. This constant may only be used in the Homebrew/brew repository. Third parties should avoid using this constant if possible, as it may be removed or changed without warning.

A regex to match potential shebang permutations.

%r{^#! ?/usr/bin/(?:env )?perl( |$)}
PERL_SHEBANG_MAX_LENGTH =

This constant is part of a private API. This constant may only be used in the Homebrew/brew repository. Third parties should avoid using this constant if possible, as it may be removed or changed without warning.

The length of the longest shebang matching SHEBANG_REGEX.

T.let("#! /usr/bin/env perl ".length, Integer)

Class Method Summary collapse

Class Method Details

.detected_perl_shebang(formula = T.cast(self, Formula)) ⇒ Utils::Shebang::RewriteInfo

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Parameters:

  • formula (Formula) (defaults to: T.cast(self, Formula))

Returns:

Raises:



34
35
36
37
38
39
40
41
42
43
44
45
# File 'language/perl.rb', line 34

def detected_perl_shebang(formula = T.cast(self, Formula))
  perl_deps = formula.declared_deps.select { |dep| dep.required? && dep.name == "perl" }
  raise ShebangDetectionError.new("Perl", "formula does not depend on Perl") if perl_deps.empty?

  perl_path = if perl_deps.any? { |dep| !dep.uses_from_macos? || !dep.use_macos_install? }
    Formula["perl"].opt_bin/"perl"
  else
    "/usr/bin/perl#{MacOS.preferred_perl_version}"
  end

  perl_shebang_rewrite_info(perl_path)
end