| line | stmt | bran | cond | sub | pod | time | code | 
| 1 |  |  |  |  |  |  | package App::GHPT::WorkSubmitter::Role::Question; | 
| 2 |  |  |  |  |  |  |  | 
| 3 | 1 |  |  | 1 |  | 7566 | use App::GHPT::Wrapper::OurMoose::Role; | 
|  | 1 |  |  |  |  | 4 |  | 
|  | 1 |  |  |  |  | 13 |  | 
| 4 |  |  |  |  |  |  |  | 
| 5 |  |  |  |  |  |  | our $VERSION = '1.000012'; | 
| 6 |  |  |  |  |  |  |  | 
| 7 | 1 |  |  | 1 |  | 154 | use Term::CallEditor qw( solicit ); | 
|  | 1 |  |  |  |  | 3 |  | 
|  | 1 |  |  |  |  | 82 |  | 
| 8 | 1 |  |  | 1 |  | 7 | use Term::Choose qw( choose ); | 
|  | 1 |  |  |  |  | 2 |  | 
|  | 1 |  |  |  |  | 663 |  | 
| 9 |  |  |  |  |  |  |  | 
| 10 |  |  |  |  |  |  | requires 'ask'; | 
| 11 |  |  |  |  |  |  |  | 
| 12 |  |  |  |  |  |  | has changed_files => ( | 
| 13 |  |  |  |  |  |  | is       => 'ro', | 
| 14 |  |  |  |  |  |  | isa      => 'App::GHPT::WorkSubmitter::ChangedFiles', | 
| 15 |  |  |  |  |  |  | required => 1, | 
| 16 |  |  |  |  |  |  | ); | 
| 17 |  |  |  |  |  |  |  | 
| 18 | 0 |  |  | 0 | 1 |  | sub ask_question ( $self, $question, @responses ) { | 
|  | 0 |  |  |  |  |  |  | 
|  | 0 |  |  |  |  |  |  | 
|  | 0 |  |  |  |  |  |  | 
|  | 0 |  |  |  |  |  |  | 
| 19 | 0 | 0 |  |  |  |  | my $choice = choose( | 
| 20 |  |  |  |  |  |  | [ | 
| 21 |  |  |  |  |  |  | @responses, | 
| 22 |  |  |  |  |  |  | 'Launch Editor' | 
| 23 |  |  |  |  |  |  | ], | 
| 24 |  |  |  |  |  |  | { prompt => $question } | 
| 25 |  |  |  |  |  |  | ) or exit;    # user hit 'q' or ctrl-d to stop | 
| 26 |  |  |  |  |  |  |  | 
| 27 | 0 | 0 |  |  |  |  | return $self->format_qa_markdown( $question, $choice ) | 
| 28 |  |  |  |  |  |  | unless $choice eq 'Launch Editor'; | 
| 29 |  |  |  |  |  |  |  | 
| 30 |  |  |  |  |  |  | # todo: It would be nice if the notes persisted to disk for a given PT so | 
| 31 |  |  |  |  |  |  | # that I could ctrl-c out of a later question and still not have to retype | 
| 32 |  |  |  |  |  |  | # previously asked questions.  That's a task for another day however. | 
| 33 |  |  |  |  |  |  |  | 
| 34 | 0 |  |  |  |  |  | my $prompt = <<"ENDOFTEXT"; | 
| 35 |  |  |  |  |  |  | $question | 
| 36 |  |  |  |  |  |  |  | 
| 37 |  |  |  |  |  |  | Complete your answer below the line in markdown. | 
| 38 |  |  |  |  |  |  | --- | 
| 39 |  |  |  |  |  |  | ENDOFTEXT | 
| 40 | 0 |  |  |  |  |  | my $fh = solicit($prompt); | 
| 41 |  |  |  |  |  |  |  | 
| 42 | 0 |  |  |  |  |  | my $answer = do { local $/ = undef; <$fh> }; | 
|  | 0 |  |  |  |  |  |  | 
|  | 0 |  |  |  |  |  |  | 
| 43 | 0 |  |  |  |  |  | $answer =~ s/\A\Q$prompt//; | 
| 44 |  |  |  |  |  |  |  | 
| 45 | 0 |  |  |  |  |  | return $self->format_qa_markdown( $question, $answer ); | 
| 46 |  |  |  |  |  |  | } | 
| 47 |  |  |  |  |  |  |  | 
| 48 |  |  |  |  |  |  | ## no critic (Subroutines::ProhibitUnusedPrivateSubroutines) | 
| 49 | 0 |  |  | 0 |  |  | sub _trim ($text) { | 
|  | 0 |  |  |  |  |  |  | 
|  | 0 |  |  |  |  |  |  | 
| 50 | 0 |  |  |  |  |  | return $text =~ s/\A\s+//r =~ s/\s+\z//r; | 
| 51 |  |  |  |  |  |  | } | 
| 52 |  |  |  |  |  |  | ## use critic | 
| 53 |  |  |  |  |  |  |  | 
| 54 | 0 |  |  | 0 | 0 |  | sub format_qa_markdown ( $self, $question, $answer ) { | 
|  | 0 |  |  |  |  |  |  | 
|  | 0 |  |  |  |  |  |  | 
|  | 0 |  |  |  |  |  |  | 
|  | 0 |  |  |  |  |  |  | 
| 55 | 0 |  |  |  |  |  | return <<"ENDOFMARKDOWN"; | 
| 56 |  |  |  |  |  |  | ### Question ### | 
| 57 | 0 |  |  |  |  |  | @{[ _trim( $question )]} | 
| 58 |  |  |  |  |  |  |  | 
| 59 |  |  |  |  |  |  | ### Answer ### | 
| 60 | 0 |  |  |  |  |  | @{[ _trim( $answer ) ]} | 
| 61 |  |  |  |  |  |  | ENDOFMARKDOWN | 
| 62 |  |  |  |  |  |  | } | 
| 63 |  |  |  |  |  |  |  | 
| 64 |  |  |  |  |  |  | 1; | 
| 65 |  |  |  |  |  |  |  | 
| 66 |  |  |  |  |  |  | # ABSTRACT: Role for writing interactive questions about the commits | 
| 67 |  |  |  |  |  |  |  | 
| 68 |  |  |  |  |  |  | __END__ | 
| 69 |  |  |  |  |  |  |  | 
| 70 |  |  |  |  |  |  | =pod | 
| 71 |  |  |  |  |  |  |  | 
| 72 |  |  |  |  |  |  | =encoding UTF-8 | 
| 73 |  |  |  |  |  |  |  | 
| 74 |  |  |  |  |  |  | =head1 NAME | 
| 75 |  |  |  |  |  |  |  | 
| 76 |  |  |  |  |  |  | App::GHPT::WorkSubmitter::Role::Question - Role for writing interactive questions about the commits | 
| 77 |  |  |  |  |  |  |  | 
| 78 |  |  |  |  |  |  | =head1 VERSION | 
| 79 |  |  |  |  |  |  |  | 
| 80 |  |  |  |  |  |  | version 1.000012 | 
| 81 |  |  |  |  |  |  |  | 
| 82 |  |  |  |  |  |  | =head1 SYNOPSIS | 
| 83 |  |  |  |  |  |  |  | 
| 84 |  |  |  |  |  |  | package App::GHPT::WorkSubitter::Question::WarnAboutPasswordFile; | 
| 85 |  |  |  |  |  |  | use App::GHPT::Wrapper::OurMoose; | 
| 86 |  |  |  |  |  |  | with 'App::GHPT::WorkSubmitter::Role::Question'; | 
| 87 |  |  |  |  |  |  |  | 
| 88 |  |  |  |  |  |  | sub ask($self) { | 
| 89 |  |  |  |  |  |  | # skip the question unless there's a password file | 
| 90 |  |  |  |  |  |  | return unless $self->changed_files->changed_files_match(qr/password/); | 
| 91 |  |  |  |  |  |  |  | 
| 92 |  |  |  |  |  |  | # ask the user if that's okay | 
| 93 |  |  |  |  |  |  | return $self->ask_question(<<'ENDOFTEXT',"I'm okay with the risk"); | 
| 94 |  |  |  |  |  |  | You've committed a file with a name matching 'password'.  Are you nuts? | 
| 95 |  |  |  |  |  |  | ENDOFTEXT | 
| 96 |  |  |  |  |  |  | } | 
| 97 |  |  |  |  |  |  |  | 
| 98 |  |  |  |  |  |  | __PACKAGE__->meta->make_immutable; | 
| 99 |  |  |  |  |  |  | 1; | 
| 100 |  |  |  |  |  |  |  | 
| 101 |  |  |  |  |  |  | =head1 DESCRIPTION | 
| 102 |  |  |  |  |  |  |  | 
| 103 |  |  |  |  |  |  | This role allows you to write questions to ask someone when creating pull | 
| 104 |  |  |  |  |  |  | request. | 
| 105 |  |  |  |  |  |  |  | 
| 106 |  |  |  |  |  |  | You want to create these questions classes in the | 
| 107 |  |  |  |  |  |  | C<App::GHPT::WorkSubmitter::Question::*> namespace where | 
| 108 |  |  |  |  |  |  | L<App::GHPT::WorkSubmitter::Questioner> will automatically detect them and ask | 
| 109 |  |  |  |  |  |  | them each time C<gh-pt.pl> is run. | 
| 110 |  |  |  |  |  |  |  | 
| 111 |  |  |  |  |  |  | Each class must supply an C<ask> method which should prompt the user as needed | 
| 112 |  |  |  |  |  |  | and return any markdown to be placed in the pull request body. | 
| 113 |  |  |  |  |  |  |  | 
| 114 |  |  |  |  |  |  | =head1 ATTRIBUTES | 
| 115 |  |  |  |  |  |  |  | 
| 116 |  |  |  |  |  |  | =head2 changed_files | 
| 117 |  |  |  |  |  |  |  | 
| 118 |  |  |  |  |  |  | The files that have changed in this branch.  This is the primary attribute | 
| 119 |  |  |  |  |  |  | you want to examine. | 
| 120 |  |  |  |  |  |  |  | 
| 121 |  |  |  |  |  |  | =head1 METHODS | 
| 122 |  |  |  |  |  |  |  | 
| 123 |  |  |  |  |  |  | =head2 $question->ask_question($question, @optional_responses) | 
| 124 |  |  |  |  |  |  |  | 
| 125 |  |  |  |  |  |  | Interactively ask a question and return markdown suitable for including in the | 
| 126 |  |  |  |  |  |  | pull request body. | 
| 127 |  |  |  |  |  |  |  | 
| 128 |  |  |  |  |  |  | The question that should be asked must be passed as the first argument, and | 
| 129 |  |  |  |  |  |  | all other arguments are treated as stock answers the user can select when | 
| 130 |  |  |  |  |  |  | asked the question.  The user will also have a final option C<Launch Editor> | 
| 131 |  |  |  |  |  |  | which will launch their editor and allow them free-form text input. | 
| 132 |  |  |  |  |  |  |  | 
| 133 |  |  |  |  |  |  | =head1 SUPPORT | 
| 134 |  |  |  |  |  |  |  | 
| 135 |  |  |  |  |  |  | Bugs may be submitted through L<https://github.com/maxmind/App-GHPT/issues>. | 
| 136 |  |  |  |  |  |  |  | 
| 137 |  |  |  |  |  |  | =head1 AUTHORS | 
| 138 |  |  |  |  |  |  |  | 
| 139 |  |  |  |  |  |  | =over 4 | 
| 140 |  |  |  |  |  |  |  | 
| 141 |  |  |  |  |  |  | =item * | 
| 142 |  |  |  |  |  |  |  | 
| 143 |  |  |  |  |  |  | Mark Fowler <mark@twoshortplanks.com> | 
| 144 |  |  |  |  |  |  |  | 
| 145 |  |  |  |  |  |  | =item * | 
| 146 |  |  |  |  |  |  |  | 
| 147 |  |  |  |  |  |  | Dave Rolsky <autarch@urth.org> | 
| 148 |  |  |  |  |  |  |  | 
| 149 |  |  |  |  |  |  | =back | 
| 150 |  |  |  |  |  |  |  | 
| 151 |  |  |  |  |  |  | =head1 COPYRIGHT AND LICENSE | 
| 152 |  |  |  |  |  |  |  | 
| 153 |  |  |  |  |  |  | This software is Copyright (c) 2019 by MaxMind, Inc. | 
| 154 |  |  |  |  |  |  |  | 
| 155 |  |  |  |  |  |  | This is free software, licensed under: | 
| 156 |  |  |  |  |  |  |  | 
| 157 |  |  |  |  |  |  | The Artistic License 2.0 (GPL Compatible) | 
| 158 |  |  |  |  |  |  |  | 
| 159 |  |  |  |  |  |  | =cut |