lib/OAuthomatic/UserInteraction/ViaMicroWeb.pm

filter: Statementstmt 38.4% 15 / 39 Branchbran 0.0% 0 / 2 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 44.4% 4 / 9 Podpod 25.0% 1 / 4 totaltotal 37.0% 20 / 54 CC 2 SCAR 8.8
CC
2
Cov
37%
_open_in_browser
6.0
prepare_to_work
2.0
cleanup_after_work
2.0
CRAP 2.4
« blib/lib/OAuthomatic/UserInteraction/ViaMicroWeb.pm ↑ Summary blib/lib/OAuthomatic/Config.pm »
1 package OAuthomatic::UserInteraction::ViaMicroWeb;
2 # ABSTRACT: User is led using forms in the browser
3  
4  
5 3 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 3 ▶use namespace::sweep;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 3 ▶use Proc::Background;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 3 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10  
11 3 has 'micro_web' => (is=>'ro', isa=>'OAuthomatic::Internal::MicroWeb', required=>1,
12 handles => ['server', 'config']);
13  
14 sub prepare_to_work {
15 0 ▶ my $self = shift;
Subroutine prepare_to_work: not called CC=1 SCAR=6.9
Pod undocumented
16 0 $self->micro_web->start_using;
17 0 return;
18 }
19  
20 sub cleanup_after_work {
21 0 ▶ my $self = shift;
Subroutine cleanup_after_work: not called CC=1 SCAR=6.9
Pod undocumented
22 0 $self->micro_web->finish_using;
23 0 return;
24 }
25  
26  
27 sub prompt_client_credentials {
28 0 ▶ my ($self) = @_;
Subroutine prompt_client_credentials: not called CC=1 SCAR=6.9
Pod documented
29  
30 0 my $mweb = $self->micro_web;
31  
32 0 my $enter_url = $mweb->client_key_url;
33 0 $self->_open_in_browser($enter_url, <<"END");
34 Fill application tokens in the browser form.
35 This script will continue once they are submitted.
36 END
37 0 my $client_cred = $mweb->wait_for_client_cred();
38  
39 0 return $client_cred;
40 }
41  
42 sub visit_oauth_authorize_page {
43 0 ▶ my ($self, $url) = @_;
Subroutine visit_oauth_authorize_page: not called CC=1 SCAR=6.9
Pod undocumented
44  
45 0 my $site_name = $self->server->site_name;
46  
47 0 $self->_open_in_browser($url, <<"END");
48 Accept application authorization in the browser form (page from $site_name),
49 or just notification about succesfull authorization if you already authorized
50 in the past.
51 This script will continue once you authorize application.
52 END
53  
54 0 return;
55 }
56  
57 sub _open_in_browser {
58 0 ▶ my ($self, $url, $comment) = @_;
Subroutine _open_in_browser: not called CC=2 SCAR=17.9
59  
60 0 my $browser = $self->config->browser;
61 0 ▶ unless($browser) {
Branch: 1 branch
BranchTrueFalseTotal
if ($browser) { } 0 0 0
62 0 print <<"END";
63 Open your browser on
64 $url
65 $comment
66 END
67 } else {
68 0 print <<"END";
69 Spawning browser ($browser) on
70 $url
71 (open this page manually if for some reason it is not displayed automatically).
72  
73 $comment
74 END
75 0 my $bgr = Proc::Background->new($browser, $url);
76 # The process sometimes will end immediately (page in existing browser), sometimes will
77 # continue. Let's just ignore it (and, therefore, ignore returned object)
78 0 undef $bgr;
79 }
80 0 return;
81 }
82  
83 3 with 'OAuthomatic::UserInteraction';
84  
85 3 1;
86  
87 __END__
88  
89 =pod
90  
91 =encoding UTF-8
92  
93 =head1 NAME
94  
95 OAuthomatic::UserInteraction::ViaMicroWeb - User is led using forms in the browser
96  
97 =head1 VERSION
98  
99 version 0.0201
100  
101 =head1 DESCRIPTION
102  
103 Simple (local) web forms will be used to ask user for client
104 credentials and provide him with instructions.
105  
106 =head1 PARAMETERS
107  
108 =head2 micro_web
109  
110 Embedded web server object. Here it will be used to show forms.
111  
112 =head1 METHODS
113  
114 =head2 prompt_client_credentials() => ClientCred(...)
115  
116 Asks the user to visit appropriate remote page and provide application
117 (or developer) keys. Here use web form as an aid.
118  
119 =head1 AUTHOR
120  
121 Marcin Kasperski <Marcin.Kasperski@mekk.waw.pl>
122  
123 =head1 COPYRIGHT AND LICENSE
124  
125 This software is copyright (c) 2015 by Marcin Kasperski.
126  
127 This is free software; you can redistribute it and/or modify it under
128 the same terms as the Perl 5 programming language system itself.
129  
130 =cut
« blib/lib/OAuthomatic/UserInteraction/ViaMicroWeb.pm ↑ Summary blib/lib/OAuthomatic/Config.pm »