| 1 | package OAuthomatic::UserInteraction::ConsolePrompts; | ||||||||||||
| 2 | # ABSTRACT: Simple textual prompts on the console | ||||||||||||
| 3 | |||||||||||||
| 4 | # FIXME: use templates | ||||||||||||
| 5 | # FIXME: test it | ||||||||||||
| 6 | |||||||||||||
| 7 | |||||||||||||
| 8 | 3 | ▶ | use Moose; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 9 | 3 | ▶ | use namespace::sweep; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 10 | 3 | ▶ | use Proc::Background; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 11 | 3 | ▶ | use IO::Interactive qw/is_interactive/; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 12 | 3 | ▶ | use Carp; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 13 | |||||||||||||
| 14 | |||||||||||||
| 15 | 3 | has 'config' => ( | |||||||||||
| 16 | is => 'ro', isa => 'OAuthomatic::Config', required => 1, | ||||||||||||
| 17 | handles=>[ | ||||||||||||
| 18 | 'browser', | ||||||||||||
| 19 | ]); | ||||||||||||
| 20 | |||||||||||||
| 21 | |||||||||||||
| 22 | 3 | has 'server' => ( | |||||||||||
| 23 | is => 'ro', isa => 'OAuthomatic::Server', required => 1, | ||||||||||||
| 24 | handles => [ | ||||||||||||
| 25 | 'site_name', | ||||||||||||
| 26 | 'site_client_creation_page', | ||||||||||||
| 27 | 'site_client_creation_desc', | ||||||||||||
| 28 | 'site_client_creation_help', | ||||||||||||
| 29 | ]); | ||||||||||||
| 30 | |||||||||||||
| 31 | sub prompt_client_credentials { | ||||||||||||
| 32 | 0 | ▶ | my ($self) = @_; | ||||||||||
|
Subroutine
prompt_client_credentials: not called CC=6 SCAR=37.4
Pod
documented
| |||||||||||||
| 33 | |||||||||||||
| 34 | 0 | ▶ | unless(is_interactive()) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 35 | 0 | OAuthomatic::Error::Generic->throw( | |||||||||||
| 36 | ident => "Bad usage", | ||||||||||||
| 37 | extra => "Can not use ConsolePrompts without interactive terminal"); | ||||||||||||
| 38 | } | ||||||||||||
| 39 | |||||||||||||
| 40 | 0 | print << 'END'; | |||||||||||
| 41 | Client (application) credentials are necessary to continue. | ||||||||||||
| 42 | Those must be created manually using $site_name web interface. | ||||||||||||
| 43 | END | ||||||||||||
| 44 | 0 | my $page_url = $self->site_client_creation_page; | |||||||||||
| 45 | 0 | my $page_desc = $self->site_client_creation_desc; | |||||||||||
| 46 | 0 | ▶ | my $page_help = $self->site_client_creation_help || ''; | ||||||||||
|
Condition0%0/2
$self->site_client_creation_help || ''
MC/DC0%0/1
$self->site_client_creation_help || ''
$self->site_client_creation_help
Truth table0%0/2
A
A= $self->site_client_creation_help
| |||||||||||||
| 47 | 0 | ▶ | if($page_url) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 48 | 0 | print << "END"; | |||||||||||
| 49 | |||||||||||||
| 50 | Please, visit | ||||||||||||
| 51 | |||||||||||||
| 52 | $page_url | ||||||||||||
| 53 | |||||||||||||
| 54 | ($page_desc) | ||||||||||||
| 55 | click through new application setup and enter obtained values below. | ||||||||||||
| 56 | |||||||||||||
| 57 | $page_help | ||||||||||||
| 58 | END | ||||||||||||
| 59 | } else { | ||||||||||||
| 60 | 0 | print << "END"; | |||||||||||
| 61 | |||||||||||||
| 62 | Please, visit $page_desc, | ||||||||||||
| 63 | click through new application setup and enter developer keys below. | ||||||||||||
| 64 | |||||||||||||
| 65 | $page_help | ||||||||||||
| 66 | END | ||||||||||||
| 67 | } | ||||||||||||
| 68 | |||||||||||||
| 69 | 0 | my ($key, $secret); | |||||||||||
| 70 | 0 | while(1) { | |||||||||||
| 71 | 0 | print "Key: "; | |||||||||||
| 72 | 0 | $key = <>; chomp($key); $key =~ s/^\s+//x; $key =~ s/\s+$//x; | |||||||||||
| 73 | 0 | ▶ | last if $key; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 74 | } | ||||||||||||
| 75 | 0 | while(1) { | |||||||||||
| 76 | 0 | print "Secret: "; | |||||||||||
| 77 | 0 | $secret = <>; chomp($secret); $secret =~ s/^\s+//x; $secret =~ s/\s+$//x; | |||||||||||
| 78 | 0 | ▶ | last if $secret; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 79 | } | ||||||||||||
| 80 | 0 | return OAuthomatic::Types::ClientCred->new( | |||||||||||
| 81 | key => $key, | ||||||||||||
| 82 | secret => $secret, | ||||||||||||
| 83 | ); | ||||||||||||
| 84 | } | ||||||||||||
| 85 | |||||||||||||
| 86 | sub visit_oauth_authorize_page { | ||||||||||||
| 87 | 0 | ▶ | my ($self, $app_auth_url) = @_; | ||||||||||
|
Subroutine
visit_oauth_authorize_page: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||
| 88 | |||||||||||||
| 89 | 0 | print <<"END"; | |||||||||||
| 90 | Open your browser (local one!) on $app_auth_url | ||||||||||||
| 91 | and authorize application when prompted. This script will continue once you finish. | ||||||||||||
| 92 | END | ||||||||||||
| 93 | 0 | return; | |||||||||||
| 94 | } | ||||||||||||
| 95 | |||||||||||||
| 96 | ▶ | sub prepare_to_work { | |||||||||||
|
Subroutine
prepare_to_work: not called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||
| 97 | } | ||||||||||||
| 98 | |||||||||||||
| 99 | ▶ | sub cleanup_after_work { | |||||||||||
|
Subroutine
cleanup_after_work: not called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||
| 100 | } | ||||||||||||
| 101 | |||||||||||||
| 102 | 3 | with 'OAuthomatic::UserInteraction'; | |||||||||||
| 103 | |||||||||||||
| 104 | 3 | 1; | |||||||||||
| 105 | |||||||||||||
| 106 | __END__ | ||||||||||||
| 107 | |||||||||||||
| 108 | =pod | ||||||||||||
| 109 | |||||||||||||
| 110 | =encoding UTF-8 | ||||||||||||
| 111 | |||||||||||||
| 112 | =head1 NAME | ||||||||||||
| 113 | |||||||||||||
| 114 | OAuthomatic::UserInteraction::ConsolePrompts - Simple textual prompts on the console | ||||||||||||
| 115 | |||||||||||||
| 116 | =head1 VERSION | ||||||||||||
| 117 | |||||||||||||
| 118 | version 0.0201 | ||||||||||||
| 119 | |||||||||||||
| 120 | =head1 DESCRIPTION | ||||||||||||
| 121 | |||||||||||||
| 122 | Absolutely nothing fancy, bare console prints. | ||||||||||||
| 123 | |||||||||||||
| 124 | =head1 METHODS | ||||||||||||
| 125 | |||||||||||||
| 126 | =head2 prompt_client_credentials() => ClientCred(...) | ||||||||||||
| 127 | |||||||||||||
| 128 | Asks the user to visit appropriate remote page and provide application | ||||||||||||
| 129 | (or developer) keys. | ||||||||||||
| 130 | |||||||||||||
| 131 | Here just plain console prompt. | ||||||||||||
| 132 | |||||||||||||
| 133 | =head1 ATTRIBUTES | ||||||||||||
| 134 | |||||||||||||
| 135 | =head2 config | ||||||||||||
| 136 | |||||||||||||
| 137 | L<OAuthomatic::Config> object used to bundle various configuration params. | ||||||||||||
| 138 | |||||||||||||
| 139 | =head2 server | ||||||||||||
| 140 | |||||||||||||
| 141 | L<OAuthomatic::Server> object used to bundle server-related configuration params. | ||||||||||||
| 142 | |||||||||||||
| 143 | =head1 AUTHOR | ||||||||||||
| 144 | |||||||||||||
| 145 | Marcin Kasperski <Marcin.Kasperski@mekk.waw.pl> | ||||||||||||
| 146 | |||||||||||||
| 147 | =head1 COPYRIGHT AND LICENSE | ||||||||||||
| 148 | |||||||||||||
| 149 | This software is copyright (c) 2015 by Marcin Kasperski. | ||||||||||||
| 150 | |||||||||||||
| 151 | This is free software; you can redistribute it and/or modify it under | ||||||||||||
| 152 | the same terms as the Perl 5 programming language system itself. | ||||||||||||
| 153 | |||||||||||||
| 154 | =cut | ||||||||||||