Alien-MSYS2

 view release on metacpan or  search on metacpan

lib/Alien/MSYS2.pm  view on Meta::CPAN

package Alien::MSYS2;

use strict;
use warnings;
use 5.008001;
use File::Spec;
use JSON::PP ();

# ABSTRACT: Tools required for autogen scripts in Windows (MSYS2)
our $VERSION = '0.02'; # VERSION


sub new
{
  my($class) = @_;
  bless {}, $class;
}


{

  my $share;
  my $config;

  sub _share ()
  {
    $share ||= do {
      $_ = __FILE__;
      s{(MSYS2).pm}{.$1.devshare};
      my $share = -e $_
        ? do {
          require File::Basename;
          # TODO: squeeze out the updirs
          File::Spec->rel2abs(File::Spec->catdir(File::Basename::dirname("lib/Alien/MSYS2.pm"), File::Spec->updir, File::Spec->updir, "share"));
        }
        : do {
          require File::ShareDir;
          File::ShareDir::dist_dir('Alien-MSYS2');
        };
    };
  }

  sub _config ()
  {
    $config ||= do {
      my $filename = File::Spec->catfile(_share, 'alien_msys2.json');
      open my $fh, '<', $filename;
      JSON::PP::decode_json(do { local $/; <$fh> });
    };
  }
}

sub install_type
{
  _config()->{install_type};
}


sub msys2_root
{
  _config->{msys2_root} || File::Spec->catdir(_share, _config->{ptrsize} == 8 ? 'msys64' : 'msys32');
}


sub bin_dir
{
  my($class) = @_;
  return if $^O eq 'msys';
  my $dir = File::Spec->catdir( $class->msys2_root, qw( usr bin ) );
  $dir =~ s{\\}{/}g;
  if($class->install_type eq 'system')
  {
    require File::Which;
    # assume if pacman is in the path then MSYS is already in the path
    my $pacman = File::Which::which('pacman');
    return if $pacman;



( run in 3.081 seconds using v1.01-cache-2.11-cpan-d06a3f9ecfd )