diff --git a/.travis.yml b/.travis.yml index 05bb9c6..8eb1d27 100644 --- a/.travis.yml +++ b/.travis.yml @@ -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 diff --git a/Changes b/Changes index 676ee14..590d2bd 100644 --- a/Changes +++ b/Changes @@ -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 diff --git a/MANIFEST b/MANIFEST deleted file mode 100644 index 315c8fb..0000000 --- a/MANIFEST +++ /dev/null @@ -1,12 +0,0 @@ -lib/Command/Interactive/Interaction.pm -lib/Command/Interactive.pm -Makefile.PL -MANIFEST -README.md -t/001.t -t/basic.t -t/interaction.t -t/password.t -t/pathological.t -t/regex.t -t/system_only.t diff --git a/cpanfile b/cpanfile new file mode 100644 index 0000000..9cca8f7 --- /dev/null +++ b/cpanfile @@ -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'; +}; diff --git a/dist.ini b/dist.ini new file mode 100644 index 0000000..beaff49 --- /dev/null +++ b/dist.ini @@ -0,0 +1,69 @@ +name = Command-Interactive +author = binary.com +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] diff --git a/lib/Command/Interactive.pm b/lib/Command/Interactive.pm index fa1b40e..36eef20 100644 --- a/lib/Command/Interactive.pm +++ b/lib/Command/Interactive.pm @@ -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. @@ -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 @@ -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!"; @@ -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) { @@ -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; @@ -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; diff --git a/lib/Command/Interactive/Interaction.pm b/lib/Command/Interactive/Interaction.pm index e60cc09..478b268 100755 --- a/lib/Command/Interactive/Interaction.pm +++ b/lib/Command/Interactive/Interaction.pm @@ -3,7 +3,7 @@ package Command::Interactive::Interaction; use strict; use warnings; -our $VERSION = 1.1; +## VERSION use Moose; @@ -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 @@ -55,7 +55,7 @@ has response => ( =head2 expected_string_is_regex (DEFAULT: FALSE) -Whether the C should be treated as a Perl regular expression. +Whether the C should be treated as a Perl regular expression. =cut @@ -126,13 +126,13 @@ has max_allowed_occurrences => ( Returns the actual string to send in response to discovering C, 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 diff --git a/t/rc/.perlcriticrc b/t/rc/.perlcriticrc new file mode 100644 index 0000000..2da8e03 --- /dev/null +++ b/t/rc/.perlcriticrc @@ -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 diff --git a/t/rc/.perltidyrc b/t/rc/.perltidyrc new file mode 100644 index 0000000..143e85b --- /dev/null +++ b/t/rc/.perltidyrc @@ -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 +