blib/lib/Finance/Bank/ABSA.pm

filter: Statementstmt 21.5% 14 / 65 Branchbran 0.0% 0 / 22 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 80.0% 4 / 5 Podpod 0.0% 0 / 1 totaltotal 19.3% 18 / 93 CC 12 SCAR 47.6
CC
12
Cov
16%
check_ABSA_balance
156.0
BEGIN
1.0
BEGIN
1.0
CRAP 117.2
↑ Summary
1 package Finance::Bank::ABSA;
2 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 1 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 our $VERSION = '0.03';
5 1 ▶use WWW::Mechanize;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use HTML::TokeParser;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 0 ▶sub check_ABSA_balance {
Subroutine check_ABSA_balance: not called CC=12 SCAR=50.5
Pod undocumented
9 0 my ($class, %opts) = @_;
10 0 my @accounts;
11 0 ▶ croak "Must provide a security code" unless exists $opts{seccode};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $opts{"seccode"} 0 0 0
12 0 ▶ croak "Must provide a banking id" unless exists $opts{bankingid};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $opts{"bankingid"} 0 0 0
13 0 ▶ croak "Must provide a password" unless exists $opts{mypassword};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $opts{"mypassword"} 0 0 0
14  
15 0 my $self = bless { %opts }, $class;
16  
17 0 my $agent = WWW::Mechanize->new();
18 0 $agent->get("https://vs1.absa.co.za/ibs/UserAuthentication.do");
19  
20 # Filling in the login form.
21 0 $agent->form("theForm");
22 0 $agent->field("AccessAccount", $opts{bankingid});
23 0 $agent->field("PIN", $opts{seccode});
24 0 $agent->click("button_processAuthenticate");
25 0 ▶ die unless ($agent->success);
Branch: 1 branch
BranchTrueFalseTotal
unless $agent->success 0 0 0
26  
27 0 my @secletter = split(//, $opts{mypassword}); # put p/word into an array
28 0 $agent->form("AuthPasswordForm");
29  
30 # Now comes to trickery to only provide the requested chars of password
31 # Need to determine which of the input fields are class jc-pwdDgt
32 # as input fields with class jc-pwdDgtDis aren't required for login
33 # This is in order to not need to provide the whole password over the Net!
34 0 ▶ my $testpwdDgt = HTML::TokeParser->new(\$agent->content) or die "$!";
Branch: 1 branch
BranchTrueFalseTotal
my $testpwdDgt = "HTML::TokeParser"->new(\$agent->content) or die "$!" 0 0 0
35 0 $testpwdDgt->get_tag("form");
36  
37 # Go to first input field in form.
38 0 my $pwdToken = $testpwdDgt->get_tag("input");
39 0 ▶ while ( $pwdToken->[1]{name} =~ /pwdDgt(\d+)/ ) # Step through all pwdDgt fields only
Branch: 1 branch
BranchTrueFalseTotal
if ($pwdToken->[1]{"name"} =~ /pwdDgt(\d+)/) 0 0 0
40 # Setting $1 to the pwdDgt number
41 {
42 0 ▶ if ( $pwdToken->[1]{class} eq "jc-pwdDgt" ) { # AHA - they want this char!
Branch: 1 branch
BranchTrueFalseTotal
if ($pwdToken->[1]{"class"} eq "jc-pwdDgt") 0 0 0
43 0 $agent->field($pwdToken->[1]{name}, @secletter[$1]);
44 }
45 0 $pwdToken = $testpwdDgt->get_tag("input");
46 }
47  
48 0 $agent->click("button_processAuthPassword");
49 0 ▶ die unless ($agent->success);
Branch: 1 branch
BranchTrueFalseTotal
unless $agent->success 0 0 0
50  
51 # Now we have the data, we need to parse it. This is fragile.
52 0 my $content = $agent->{content};
53 0 my ($split1, $split2) = split /\<h4\>Balance Enquiries/, $content;
54 0 my ($content, $split2) = split /Click on the account number for a statement/, $split2;
55  
56 0 ▶ my $stream = HTML::TokeParser->new(\$content) or die "$!";
Branch: 1 branch
BranchTrueFalseTotal
my $stream = "HTML::TokeParser"->new(\$content) or die "$!" 0 0 0
57 0 $stream->get_tag("table");
58 0 $stream->get_tag("tr");
59 0 $stream->get_tag("tr");
60 0 $stream->get_tag("tr");
61  
62 0 ▶ while (my $token = $stream->get_tag("tr")) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $token = $stream->get_tag("tr")) 0 0 0
63 0 $token = $stream->get_tag("td");
64 0 ▶ if ($token->[1]{width} eq "5") {
Branch: 1 branch
BranchTrueFalseTotal
if ($token->[1]{"width"} eq 5) 0 0 0
65 0 $stream->get_tag("td");
66 0 my $accountname = $stream->get_trimmed_text("/td");
67 0 $stream->get_tag("td");
68 0 my $accountnumber = $stream->get_trimmed_text("/td");
69 0 $stream->get_tag("td");
70 0 my $accountbalance = $stream->get_trimmed_text("/td");
71 0 my @strarray = split(//, $accountbalance);
72 0 $stream->get_tag("td");
73 0 my $accountavailable = $stream->get_trimmed_text("/td");
74  
75 # Octal 240 is used from HTML3.2 spec to replace &nbsp;
76 # See Entities.pm under your perl vendor tree
77 # I choose to replace it here to easily/correctly cater for later formatting.
78 0 $accountbalance =~ s/[, ]/./g;
79 0 $accountbalance =~ s/\240//g;
80 0 $accountavailable =~ s/[, ]/./g;
81 0 $accountavailable =~ s/\240//g;
82 0 $accountname =~ s/\240//g;
83  
84 0 push @accounts, {
85 balance => $accountbalance,
86 name => $accountname,
87 available => $accountavailable,
88 account => $accountnumber
89 };
90 }
91 }
92 0 return @accounts;
93 }
94  
95 1 1;
96 __END__
↑ Summary