App-pepper

 view release on metacpan or  search on metacpan

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


        # remove any trailing comment
        $command =~ s/\#.*//g;
    }

    if (!defined($command)) {
        last;

    } elsif ($command ne '') {
        if ($term && $command eq '!!') {
            execute_command($last) if ($last ne '');

        } else {
            $last = $command;

            note("Executing command '%s'", $command) if (!$term);
            execute_command($command);
        }
    }
}

$term->WriteHistory($histfile) if ($term && 'Term::ReadLine::Gnu' eq $term->ReadLine);

handle_logout() if ($epp->connected && $epp->authenticated);
$epp->disconnect if ($epp->connected);

note('Bye!');

exit(0);

sub execute_command {
    my $line = shift;

    return if ($line eq '');

    my @args = shellwords($line);

    my $command = shift(@args);

    my $fail;
    if (!$term && $command =~/^!/) {
        $fail = 1;
        $command = substr($command, 1);
    }

    if (!defined($handlers->{$command})) {
        error("Unknown command '$command'");
        handle_exit() if (!$term);

    } else {
        &{$handlers->{$command}}(@args);
        if (!$term && $fail) {
            note("%s%04d%s %s", color($Net::EPP::Simple::Code < 2000 ? 'green' : 'red'), $Net::EPP::Simple::Code, color('reset'), $Net::EPP::Simple::Message);
            fatal($Net::EPP::Simple::Message) if ($Net::EPP::Simple::Code > 1999);
        }
    }
}

sub handle_timeout {
    $epp->{'timeout'} = int($_[0]);
    note("Timeout set to %ds", $_[0]);
    return 1;
}

sub handle_ssl {
    if ($epp->connected) {
        return error("Already connected");

    } elsif ($_[0] eq 'on') {
        $epp->{'ssl'} = 1;
        note('SSL enabled');

    } elsif ($_[0] eq 'off') {
        $epp->{'ssl'} = 0;
        note('SSL disabled');

    } else {
        return error("Invalid SSL mode '%s'", $_[0]);

    }
    return 1;
}

sub handle_host {
    if ($epp->connected) {
        return error("Already connected");

    } else {
        $epp->{'host'} = $_[0];
        note("Host set to %s", $_[0]);
        return 1;
    }
}

sub handle_port {
    if ($epp->connected) {
        return error("Already connected");

    } else {
        $epp->{'port'} = int($_[0]);
        note("Port set to %d", $_[0]);
        return 1;
    }
}

sub handle_connect {
    if ($epp->connected) {
        return error("Already connected");

    } elsif ($epp->{'host'} eq '') {
        return error('No host specified');

    } else {
        note('Connecting to %s...', $epp->{'host'});

        $epp->{'quiet'} = 1;
        my $result = $epp->_connect(undef);
        $epp->{'quiet'} = 0;

        if ($result) {
            note("Connected OK. Type 'hello' to see the greeting frame.");



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