blib/lib/Finance/Bank/Fubon/TW.pm

filter: Statementstmt 27.2% 15 / 55 Branchbran 0.0% 0 / 12 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 57.1% 4 / 7 Podpod 0.0% 0 / 1 totaltotal 25.3% 19 / 75 CC 8 SCAR 28.2
CC
8
Cov
22%
statement
30.0
check_balance
20.0
AUTOLOAD
2.0
CRAP 16.9
↑ Summary
1 # $File: //member/autrijus/Finance-Bank-Fubon-TW/lib/Finance/Bank/Fubon/TW.pm $ $Author: autrijus $
2 # $Revision: #2 $ $Change: 5938 $ $DateTime: 2003/05/17 22:34:34 $
3  
4 package Finance::Bank::Fubon::TW;
5 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 our $VERSION = '0.01';
8 1 ▶use WWW::Mechanize;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 our $ua = WWW::Mechanize->new(
10 env_proxy => 1,
11 keep_alive => 1,
12 timeout => 60,
13 );
14  
15 0 ▶sub check_balance {
Subroutine check_balance: not called CC=4 SCAR=30.0
Pod undocumented
16 0 my ($class, %opts) = @_;
17 0 local $^W;
18  
19 0 ▶ croak "Must provide a password" unless exists $opts{password};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $opts{"password"} 0 0 0
20 0 ▶ croak "Must provide a username" unless exists $opts{username};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $opts{"username"} 0 0 0
21  
22 0 my $self = bless { %opts }, $class;
23  
24 0 $ua->get('https://net.fubonbank.com.tw/ebank/nbssl/nbauth/loginmain.asp');
25 0 $ua->field(USERID => $self->{username});
26 0 $ua->field(PWD => $self->{password});
27 0 $ua->submit;
28 0 $ua->get('https://net.fubonbank.com.tw/ebank/nbssl/nbauth/QryMain.asp');
29  
30 0 my $html = $ua->content;
31  
32 0 my @accounts;
33 0 ▶ while ($html =~ s!<TR.*?<br>(\d+)</td><td[^>]*>([^<]+)</td>!!) {
Branch: 1 branch
BranchTrueFalseTotal
if ($html =~ s[<TR.*?<br>(\d+)</td><td[^>]*>([^<]+)</td>][]) 0 0 0
34 0 my ($id, $balance) = ($1, $2);
35 0 $balance =~ s!,!!g;
36 0 $balance = 0 + $balance;
37 0 push @accounts, (bless {
38 balance => $balance,
39 name => $id,
40 account_no => $id,
41 parent => $self,
42 }, "Finance::Bank::Fubon::TW::Account");
43 }
44  
45 0 return @accounts;
46 }
47  
48 package Finance::Bank::Fubon::TW::Account;
49 # Basic OO smoke-and-mirrors Thingy
50 1 ▶no strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
51 0 ▶sub AUTOLOAD { my $self=shift; $AUTOLOAD =~ s/.*:://; $self->{$AUTOLOAD} }
Subroutine AUTOLOAD: not called CC=1 SCAR=6.9
52  
53 0 ▶sub statement {
Subroutine statement: not called CC=5 SCAR=34.0
54 0 my $ac = shift;
55 0 my $code;
56  
57 0 $ua->get('https://net.fubonbank.com.tw/ebank/Nbssl/asp/VR002Htm.asp?acc=' . $ac->account_no);
58 0 $ua->submit;
59  
60 0 my $html = $ua->content;
61 0 my @transactions;
62 0 ▶ while ($html =~ s!<tr >(.*?)</tr>!!s) {
Branch: 1 branch
BranchTrueFalseTotal
if ($html =~ s[<tr >(.*?)</tr>][]s) 0 0 0
63 0 my @lines;
64 0 foreach my $line (split(/\n/, $1)) {
65 0 ▶ next unless $line =~ /<td/;
Branch: 1 branch
BranchTrueFalseTotal
unless $line =~ /<td/ 0 0 0
66 0 $line =~ s/^\s+//;
67 0 $line =~ s/\s+$//;
68 0 $line =~ s/<[^>]+> ?//g;
69 0 $line =~ s/^&nbsp$//g;
70 0 ▶ if ( $line =~ s/,// ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($line =~ s/,//) 0 0 0
71 0 $line = 0 + $line;
72 }
73 0 push @lines, $line;
74 }
75 0 push @transactions, join(',', @lines) . "\n";
76 }
77  
78 0 return join("", @transactions);
79 }
80  
81 1 1;
82  
83 __END__
↑ Summary