App-Rakubrew

 view release on metacpan or  search on metacpan

lib/App/Rakubrew.pm  view on Meta::CPAN

package App::Rakubrew;
use strict;
use warnings;
use 5.010;
our $VERSION = '45';

use Encode::Locale;
if (-t) {
    binmode(STDIN, ":encoding(console_in)");
    binmode(STDOUT, ":encoding(console_out)");
    binmode(STDERR, ":encoding(console_out)");
}
use FindBin qw($RealBin);
use File::Path qw(remove_tree);
use File::Spec::Functions qw(catfile catdir splitpath updir rel2abs);

use App::Rakubrew::Build;
use App::Rakubrew::Config;
use App::Rakubrew::Download;
use App::Rakubrew::Shell;
use App::Rakubrew::Tools;
use App::Rakubrew::Update;
use App::Rakubrew::Variables;
use App::Rakubrew::VersionHandling;

sub new {
    my ($class, @argv) = @_;
    my %opt = (
        args => \@argv,
    );
    my $self = bless \%opt, $class;
    return $self;
}

sub run_script {
    my ($self) = @_;
    my @args = @{$self->{args}};

    sub _cant_access_home {
        say STDERR "Can't create rakubrew home directory in $prefix";
        say STDERR "Probably rakubrew was denied access. You can either change that folder to be writable";
        say STDERR "or set a different rakubrew home directory by setting the `\$RAKUBREW_HOME` environment";
        say STDERR "prior to calling the rakubrew shell hook. ";
        exit 1;
    }

    unless (-d $prefix) {
        _cant_access_home() unless mkdir $prefix;
    }

    mkdir(catdir($prefix, 'bin'))    || _cant_access_home() unless (-d catdir($prefix, 'bin'));
    mkdir(catdir($prefix, 'update')) || _cant_access_home() unless (-d catdir($prefix, 'update'));
    mkdir(catdir($prefix, 'repos'))    || _cant_access_home() unless (-d catdir($prefix, 'repos'));
    mkdir $shim_dir                  || _cant_access_home() unless (-d $shim_dir);
    mkdir $versions_dir              || _cant_access_home() unless (-d $versions_dir);
    mkdir $git_reference             || _cant_access_home() unless (-d $git_reference);

    { # Check whether we are called as a shim and forward if yes.
        my (undef, undef, $prog_name) = splitpath($0);

        # TODO: Mac is also case insensitive. Is this way to compensate for insensitivity safe?
        if ($prog_name ne $brew_name &&
        ($^O !~ /win32/i || $prog_name =~ /^\Q$brew_name\E\z/i)) {
            $self->do_exec($prog_name, \@args);
        }
    }

    { # Detect shell environment and initialize the shell object.
        my $shell = '';
        $shell = $args[1] if @args >= 2 && $args[0] eq 'internal_shell_hook';
        $shell = $args[1] if @args >= 2 && $args[0] eq 'internal_hooked';



( run in 0.576 second using v1.01-cache-2.11-cpan-39bf76dae61 )