line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# Copyright (c) 2007 Jon Connell. |
2
|
|
|
|
|
|
|
# All Rights Reserved. |
3
|
|
|
|
|
|
|
# |
4
|
|
|
|
|
|
|
# This program is free software; you can redistribute it and/or |
5
|
|
|
|
|
|
|
# modify it under the same terms as Perl itself. |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
package Finance::Bank::Cahoot::CredentialsProvider::ReadLine; |
8
|
1
|
|
|
1
|
|
983
|
use base qw(Finance::Bank::Cahoot::CredentialsProvider); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
667
|
|
9
|
|
|
|
|
|
|
|
10
|
1
|
|
|
1
|
|
5
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
30
|
|
11
|
1
|
|
|
1
|
|
5
|
use warnings 'all'; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
30
|
|
12
|
1
|
|
|
1
|
|
4
|
use vars qw($VERSION); |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
40
|
|
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
$VERSION = '1.07'; |
15
|
|
|
|
|
|
|
|
16
|
1
|
|
|
1
|
|
4
|
use Carp qw(croak); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
34
|
|
17
|
1
|
|
|
1
|
|
4
|
use Term::ReadLine; |
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
324
|
|
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
sub _init |
20
|
|
|
|
|
|
|
{ |
21
|
3
|
|
|
3
|
|
5
|
my ($self, $options) = @_; |
22
|
3
|
|
|
|
|
16
|
while (my ($arg, $value) = each %{$options}) { |
|
7
|
|
|
|
|
20
|
|
23
|
6
|
100
|
|
|
|
21
|
if ($arg =~ m/(\w+)_prompt/) { |
24
|
4
|
100
|
|
|
|
41
|
croak 'Prompt for unknown credential '.$1 |
25
|
|
|
|
|
|
|
if not $self->can($1); |
26
|
3
|
|
|
|
|
10
|
$self->{_prompts}->{$1} = $value; |
27
|
|
|
|
|
|
|
} else { |
28
|
2
|
100
|
|
|
|
22
|
croak 'Invalid credential '.$arg.' supplied with callback' |
29
|
|
|
|
|
|
|
if not $self->can($arg); |
30
|
1
|
|
|
|
|
7
|
$self->{$arg} = $value; |
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
} |
33
|
1
|
|
|
|
|
7
|
$self->{_console} = new Term::ReadLine 'Cahoot Login Credentials'; |
34
|
1
|
|
|
|
|
5
|
return $self; |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
sub get |
38
|
|
|
|
|
|
|
{ |
39
|
9
|
|
|
9
|
1
|
12
|
my ($self, $credential, $offset) = @_; |
40
|
|
|
|
|
|
|
|
41
|
9
|
|
|
|
|
7
|
my $prompt; |
42
|
9
|
100
|
|
|
|
19
|
if (defined $self->{_prompts}->{$credential}) { |
43
|
6
|
|
|
|
|
16
|
$prompt = sprintf $self->{_prompts}->{$credential}, $offset; |
44
|
|
|
|
|
|
|
} else { |
45
|
3
|
100
|
|
|
|
6
|
if (defined $offset) { |
46
|
1
|
|
|
|
|
5
|
$prompt = sprintf 'Enter character %d of '.$credential.': ', $offset; |
47
|
|
|
|
|
|
|
} else { |
48
|
2
|
|
|
|
|
4
|
$prompt = 'Enter '.$credential.': '; |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
} |
51
|
9
|
|
|
|
|
8
|
my $str; |
52
|
9
|
100
|
|
|
|
15
|
if (defined $self->{$credential}) { |
53
|
1
|
|
|
|
|
2
|
$str = $self->{$credential}; |
54
|
|
|
|
|
|
|
} else { |
55
|
8
|
|
|
|
|
45
|
$str = $self->{_console}->readline($prompt); |
56
|
|
|
|
|
|
|
} |
57
|
9
|
50
|
|
|
|
387
|
return $str if length $str == 1; |
58
|
9
|
100
|
|
|
|
17
|
if (defined $offset) { |
59
|
4
|
|
|
|
|
18
|
return substr $str, $offset - 1, 1; |
60
|
|
|
|
|
|
|
} else { |
61
|
5
|
|
|
|
|
20
|
return $str; |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
1; |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
__END__ |