App-Sqitch

 view release on metacpan or  search on metacpan

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

    default => sub {
        my $self = shift;
         $ENV{ SQITCH_EMAIL }
            || $self->config->get( key => 'user.email' )
            || $ENV{ SQITCH_ORIG_EMAIL }
        || do {
            my $sysname = $self->sysuser || hurl user => __x(
                'Cannot infer your email address; run sqitch config --user user.email {email}',
                email => 'you@example.com',
            );
            require Sys::Hostname;
            "$sysname@" . Sys::Hostname::hostname();
        };
    }
);

has config => (
    is      => 'ro',
    isa     => Config,
    lazy    => 1,
    default => sub {
        App::Sqitch::Config->new;
    }
);

has editor => (
    is      => 'ro',
    lazy    => 1,
    default => sub {
        return
             $ENV{SQITCH_EDITOR}
          || shift->config->get( key => 'core.editor' )
          || $ENV{VISUAL}
          || $ENV{EDITOR}
          || ( ISWIN ? 'notepad.exe' : 'vi' );
    }
);

has pager_program => (
    is      => "ro",
    lazy    => 1,
    default => sub {
        my $self = shift;
        return
            $ENV{SQITCH_PAGER}
         || $self->config->get(key => "core.pager")
         || $ENV{PAGER};
    },
);

has pager => (
    is       => 'ro',
    lazy     => 1,
    isa      => declare('Pager', where {
        eval { $_->isa('IO::Pager') || $_->isa('IO::Handle') }
    }),
    default  => sub {
        # Dupe and configure STDOUT.
        require IO::Handle;
        my $fh = IO::Handle->new_from_fd(*STDOUT, 'w');
        binmode $fh, ':utf8_strict';

        # Just return if no pager is wanted or there is no TTY.
        return $fh if shift->options->{no_pager} || !(-t *STDOUT);

        # Load IO::Pager and tie the handle to it.
        eval "use IO::Pager 0.34"; die $@ if $@;
        return IO::Pager->new($fh, ':utf8_strict');
    },
);

sub go {
    my $class = shift;
    my @args = @ARGV;

    # 1. Parse core options.
    my $opts = $class->_parse_core_opts(\@args);

    # 2. Load config.
    my $config = App::Sqitch::Config->new;

    # 3. Instantiate Sqitch.
    my $sqitch = $class->new({ options => $opts, config  => $config });

    # 4. Find the command.
    my $cmd = $class->_find_cmd(\@args);

    # 5. Instantiate the command object.
    my $command = $cmd->create({
        sqitch => $sqitch,
        config => $config,
        args   => \@args,
    });

    # IO::Pager respects the PAGER environment variable.
    local $ENV{PAGER} = $sqitch->pager_program;

    # 6. Execute command.
    return try {
        $command->execute( @args ) ? 0 : 2;
    } catch {
        # Just bail for unknown exceptions.
        $sqitch->vent($_) && return 2 unless eval { $_->isa('App::Sqitch::X') };

        # It's one of ours.
        if ($_->exitval == 1) {
            # Non-fatal exception; just send the message to info.
            $sqitch->info($_->message);
        } elsif ($_->ident eq 'DEV') {
            # Vent complete details of fatal DEV error.
            $sqitch->vent($_->as_string);
        } else {
            # Vent fatal error message, trace details.
            $sqitch->vent($_->message);
            $sqitch->trace($_->details_string);
        }

        # Bail.
        return $_->exitval;
    };
}



( run in 1.877 second using v1.01-cache-2.11-cpan-140bd7fdf52 )