Skip to content
This repository was archived by the owner on May 17, 2024. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 15 additions & 21 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,28 +1,22 @@
sudo: false
language: perl
matrix:
fast_finish: true
perl:
- "5.24"
- "5.22"
- "5.20"
- "5.18"
- "5.16"
- "5.14"
- "5.12"
- '5.24'
- '5.22'
- '5.20'
- '5.18'
- '5.16'
- '5.14'
before_install:
- git clone git://github.com/travis-perl/helpers ~/travis-perl-helpers
- source ~/travis-perl-helpers/init
- build-perl
- perl -V
# install prereqs
- cpanm -n Test::NoWarnings
- cpanm -n Test::Exception
- cpanm -n Moose
- cpanm -n Expect
- cpanm -n Test::Requires::Git
- cpanm -n Devel::Cover::Report::Codecov
- git config --global user.name "TravisCI"
- git config --global user.email $HOSTNAME":not-for-mail@travis-ci.org"
install:
- cpanm --quiet --notest Dist::Zilla Dist::Zilla::App::Command::cover App::cpm Devel::Cover::Report::Codecov
- cpm install -w 2 --mirror=http://cpan.cpantesters.org/ -g $(dzil authordeps --missing)
- cpm install -w 2 --mirror=http://cpan.cpantesters.org/ -g $(dzil listdeps --author --missing)

script:
- perl Makefile.PL
- make test
- cover -test -report codecov
- dzil smoke --release --author && dzil cover -test -report codecov && dzil xtest

5 changes: 4 additions & 1 deletion Changes
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
Command::Interactive

1.2 5/11/2014
{{$NEXT}}
Switch to dzil

1.20 5/11/2014
Fixed test cases with non-English locales

0.03 06/06/2014
Expand Down
12 changes: 0 additions & 12 deletions MANIFEST

This file was deleted.

12 changes: 12 additions & 0 deletions cpanfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
requires 'Expect';
requires 'Moose';
requires 'perl', '5.006';

on configure => sub {
requires 'ExtUtils::MakeMaker';
};

on test => sub {
requires 'Test::Exception';
requires 'Test::NoWarnings';
};
69 changes: 69 additions & 0 deletions dist.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
name = Command-Interactive
author = binary.com <BINARY@cpan.org>
license = Perl_5
copyright_holder = binary.com
copyright_year = 2017

[Git::GatherDir]
exclude_filename = Makefile.PL
include_dotfiles = 1
[PruneCruft]
except = t/rc/\.perl.*rc$
[ManifestSkip]
[MetaYAML]
[License]
[Readme]
[MakeMaker]
eumm_version = 6.48
prereq_fatal = 1
[ExecDir]
[ShareDir]
dir = share
[Manifest]
[TestRelease]
[ConfirmRelease]
[Prereqs::FromCPANfile]
[Prereqs / BuildRequires]
perl = 5.014000
[CheckPrereqsIndexed]
[CheckExtraTests]
[NextRelease]
[VersionFromModule]
[ReversionOnRelease]
[OurPkgVersion]
[GitHub::Meta]
repo = binary-com/perl-command-interactive
[InstallGuide]
[MetaJSON]
[InsertExample]
[PerlTidy]
perltidyrc = t/rc/.perltidyrc
[PodSyntaxTests]
[MojibakeTests]
[Test::CheckDeps]
[Test::Compile]
[Test::Synopsis]
[Test::EOL]
[Test::Version]
[Test::Pod::LinkCheck]
[PodCoverageTests]
[Test::UnusedVars]
[Test::ReportPrereqs]
[Test::Perl::Critic]
critic_config = t/rc/.perlcriticrc
[SpellingCommonMistakesTests]
[CopyFilesFromRelease]
filename = lib/Command/Interactive.pm
filename = Makefile.PL
[Git::Commit]
allow_dirty = dist.ini
allow_dirty = cpanfile
allow_dirty = Changes
allow_dirty = Makefile.PL
allow_dirty = lib/Command/Interactive.pm
[Git::Tag]
tag_format = v%v
tag_message = Tag v%v for CPAN release
[InstallRelease]
install_command = carton install
[UploadToCPAN]
29 changes: 13 additions & 16 deletions lib/Command/Interactive.pm
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,10 @@ package Command::Interactive;
use strict;
use warnings;

our $VERSION = 1.2;
our $VERSION = 1.20;

use Moose;


=head1 NAME

Command::Interactive- handles interactive (and non-interactive) process invocation through a reliable and easily configured interface.
Expand All @@ -21,7 +20,7 @@ This module can be used to invoke both interactive and non-interactive commands
use Carp;

# Simple, non-interactive usage
my $result1 = Command::Interactive->new->run("cp foo /tmp/");
my $result = Command::Interactive->new->run("cp foo /tmp/");
croak "Could not copy foo to /tmp/: $result!" if($result);

# Interactive usage supports output parsing
Expand All @@ -31,12 +30,13 @@ This module can be used to invoke both interactive and non-interactive commands
response => 'secret',
});

my $my_logging_fh;
my $command = Command::Interactive->new({
echo_output => 1,
output_stream => $my_logging_fh,
interactions => [ $password_prompt ],
});
my $restart_result = $command->run("ssh user@somehost 'service apachectl restart'");
my $restart_result = $command->run("ssh user\@somehost 'service apachectl restart'");
if($restart_result)
{
warn "Couldn't restart server!";
Expand Down Expand Up @@ -265,13 +265,13 @@ sub _run_via_expect {

if ($occurrences->[$match_position] > $i->max_allowed_occurrences) {
$result =
"Got string '$matched_string', which matched expected $type '"
. $i->expected_string
. "'. This was occurrence #"
. $occurrences->[$match_position]
. ", which exceeds the specified limit of "
. $i->max_allowed_occurrences
. " occurrence(s) set for this $type";
"Got string '$matched_string', which matched expected $type '"
. $i->expected_string
. "'. This was occurrence #"
. $occurrences->[$match_position]
. ", which exceeds the specified limit of "
. $i->max_allowed_occurrences
. " occurrence(s) set for this $type";
last EXPECT_READ;
}
if ($i->response) {
Expand Down Expand Up @@ -329,7 +329,6 @@ sub _generate_interaction_list {
my $expect_array = [];
my $indexed_interactions = [];

my $counter;
foreach my $i (@{$self->interactions}) {
push @$expect_array, '-re' if ($i->expected_string_is_regex);
push @$expect_array, $i->expected_string;
Expand Down Expand Up @@ -370,16 +369,14 @@ sub _log {
my $self = shift;
my $message = shift;

my $result;

if ($self->debug_logfile) {
my $f = IO::File->new(">>" . $self->debug_logfile);
croak("Could not open debugging log file " . $self->debug_logfile) unless ($f);
my $result = $f->print(map { POSIX::strftime("[%Y-%m-%dT%H:%M:%SZ] $_\n", gmtime) } split(/[\r\n]/, $message));
$f->print(map { POSIX::strftime("[%Y-%m-%dT%H:%M:%SZ] $_\n", gmtime) } split(/[\r\n]/, $message));
$f->close;
}

return $result;
return;
}

no Moose;
Expand Down
12 changes: 6 additions & 6 deletions lib/Command/Interactive/Interaction.pm
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package Command::Interactive::Interaction;
use strict;
use warnings;

our $VERSION = 1.1;
## VERSION

use Moose;

Expand All @@ -26,7 +26,7 @@ Command::Interactive. Optionally this class can model the string to be sent in r

my $result = Command::Interactive->new({
interactions => [ $password_prompt ],
})-run("ssh user@somehost");
})-run('ssh user@somehost');

=head1 FIELDS

Expand Down Expand Up @@ -55,7 +55,7 @@ has response => (

=head2 expected_string_is_regex (DEFAULT: FALSE)

Whether the C<expected_string> should be treated as a Perl regular expression.
Whether the C<expected_string> should be treated as a Perl regular expression.

=cut

Expand Down Expand Up @@ -126,13 +126,13 @@ has max_allowed_occurrences => (

Returns the actual string to send in response to discovering C<expected_string>, including any newlines that might be added to the end of the string.

=cut
=cut

sub actual_response_to_send {
my $self = shift;
return $self->response
? $self->response . ($self->send_newline_with_response ? "\n" : '')
: undef;
? $self->response . ($self->send_newline_with_response ? "\n" : '')
: undef;
}

=head2 type
Expand Down
23 changes: 23 additions & 0 deletions t/rc/.perlcriticrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
severity = 4
criticism-fatal = 1
color = 1
include = TestingAndDebugging::RequireUseWarnings Subroutines::RequireArgUnpacking TestingAndDebugging::ProhibitNoStrict CodeLayout::RequireTidyCode ErrorHandling::RequireCheckingReturnValueOfEval TestingAndDebugging::RequireUseStrict
exclude = ValuesAndExpressions::ProhibitConstantPragma Subroutines::ProhibitExplicitReturnUndef

[TestingAndDebugging::RequireUseWarnings]
equivalent_modules=MooseX::Singleton Mojo::Base

[Subroutines::RequireArgUnpacking]
short_subroutine_statements=3

[TestingAndDebugging::ProhibitNoStrict]
allow=refs

[CodeLayout::RequireTidyCode]
perltidyrc=t/rc/.perltidyrc

[ErrorHandling::RequireCheckingReturnValueOfEval]
severity=4

[TestingAndDebugging::RequireUseStrict]
equivalent_modules=MooseX::Singleton Mojo::Base
62 changes: 62 additions & 0 deletions t/rc/.perltidyrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
# line length; keep it quite short so that lists of arguments to subs
# are wrapped
--maximum-line-length=150

# Cuddled else
-ce

# Stack Closing Tokens
# http://perltidy.sourceforge.net/stylekey.html#stack_closing_tokens
# "The manual shows how all of these vertical tightness controls may be
# applied independently to each type of non-block opening and opening token."
--stack-closing-tokens

# Similarly for opening.
--stack-opening-tokens

# 4 char wide tabs instead of spaces for indentation.
-i=4

# Horizontal Tightness
# http://perltidy.sourceforge.net/stylekey.html#define_horizontal_tightness
# parentheses if ((my $len_tab = length($tabstr)) > 0)
-pt=2

# square brackets $width = $col[$j + $k] - $col[$j];
-sbt=2

# braces $width = $col[$j + $k] - $col[$j];
-bt=2

# block braces map { $_ => -M $_ } grep { /\.deb$/ }
-bbt=0

# no space in front of semi-colons in a for loop
--nospace-for-semicolon

# no outdenting of long quotes
# http://perltidy.sourceforge.net/stylekey.html#outdenting_long_quotes
--no-outdent-long-quotes

--add-semicolons

# always break a new line after a semi-colon
--want-break-after=";"

# all hash key/values on a separate line
--comma-arrow-breakpoints=0

# No newlines before comments
-nbbc

--no-outdent-long-lines

--no-outdent-labels

--check-syntax

--indent-spaced-block-comments

# after a linebreak, move right one indentation level
--continuation-indentation=4